summaryrefslogtreecommitdiff
path: root/Pancake.hs
diff options
context:
space:
mode:
authordefanor <defanor@uberspace.net>2017-12-14 19:21:27 +0300
committerdefanor <defanor@uberspace.net>2017-12-14 19:21:27 +0300
commitb58e342bf414e869bf772fb3a38691fa4a604978 (patch)
treed6b057c6f6252a60a882f5f4703d5b20cfbd0fa0 /Pancake.hs
parente1151532a46a7ce2c59a8bc86088063cb03c4438 (diff)
Add the "set width" command
This is mostly needed for embedding, since there doesn't seem to be any practical (let alone portable) standard way to notify pancake of emacs window size changes. In pancake.el, width adjustment is now getting done automatically whenever any other command gets issued.
Diffstat (limited to 'Pancake.hs')
-rw-r--r--Pancake.hs6
1 files changed, 4 insertions, 2 deletions
diff --git a/Pancake.hs b/Pancake.hs
index 129585d..5d49b1a 100644
--- a/Pancake.hs
+++ b/Pancake.hs
@@ -74,6 +74,7 @@ data LoopState = LS { history :: Sliding (URI, P.Pandoc)
, embedded :: Bool
, interrupted :: Bool
, unclutterRegexps :: [(Regex, String)]
+ , columns :: Maybe Int
}
-- | Renders a parsed document.
@@ -81,7 +82,7 @@ printDoc :: MonadIO m => URI -> P.Pandoc -> StateT LoopState m ()
printDoc uri doc = do
term <- liftIO setupTermFromEnv
st <- get
- let cols = fromMaybe 80 $ getCapability term termColumns
+ let cols = fromMaybe 80 $ columns st <|> getCapability term termColumns
l = renderDoc cols (conf st) doc
textLines = rLines l
modify (\s -> s { rendered = l })
@@ -315,6 +316,7 @@ command Quit = liftIO $ do
when exists $ removeDirectoryRecursive dir
command Interrupt =
putErrLn "Received SIGINT. Interrupt twice in a row to quit."
+command (SetWidth w) = modify $ \s -> s { columns = w }
-- | Reads commands, runs them.
eventLoop :: MonadIO m => StateT LoopState m ()
@@ -353,7 +355,7 @@ main = do
tid <- myThreadId
_ <- installHandler sigINT (Catch (throwTo tid UserInterrupt)) Nothing
let run e = runStateT (updateConfig >> eventLoop)
- (LS ([],[]) 0 [] def e False [])
+ (LS ([],[]) 0 [] def e False [] Nothing)
>> pure ()
case getOpt Permute options args of
([], [], []) -> run False