Commit 97fddd1a authored by Judah Jacobson's avatar Judah Jacobson
Browse files

Fix `STX` appearing in any lines of the prompt, not just the last one.

Fixes #72.
parent be7c5e28
......@@ -171,7 +171,7 @@ getInputLineWithInitial prompt (left,right) = promptedInput (getInputCmdLine ini
where
initialIM = insertString left $ moveToStart $ insertString right $ emptyIM
getInputCmdLine :: (MonadIO m, MonadMask m) => InsertMode -> TermOps -> String -> InputT m (Maybe String)
getInputCmdLine :: (MonadIO m, MonadMask m) => InsertMode -> TermOps -> Prefix -> InputT m (Maybe String)
getInputCmdLine initialIM tops prefix = do
emode <- InputT $ asks editMode
result <- runInputCmdT tops $ case emode of
......@@ -218,7 +218,7 @@ getPrintableChar fops = do
Just False -> getPrintableChar fops
_ -> return c
getInputCmdChar :: (MonadIO m, MonadMask m) => TermOps -> String -> InputT m (Maybe Char)
getInputCmdChar :: (MonadIO m, MonadMask m) => TermOps -> Prefix -> InputT m (Maybe Char)
getInputCmdChar tops prefix = runInputCmdT tops
$ runCommandLoop tops prefix acceptOneChar emptyIM
......@@ -275,7 +275,7 @@ and 'historyFile' flags.
-- | Wrapper for input functions.
-- This is the function that calls "wrapFileInput" around file backend input
-- functions (see Term.hs).
promptedInput :: MonadIO m => (TermOps -> String -> InputT m a)
promptedInput :: MonadIO m => (TermOps -> Prefix -> InputT m a)
-> (FileOps -> IO a)
-> String -> InputT m a
promptedInput doTerm doFile prompt = do
......@@ -288,9 +288,13 @@ promptedInput doTerm doFile prompt = do
putStrOut rterm prompt
wrapFileInput fops $ doFile fops
Left tops -> do
-- Convert the full prompt to graphemes (not just the last line)
-- to account for the `\ESC...STX` appearing anywhere in it.
let prompt' = stringToGraphemes prompt
-- If the prompt contains newlines, print all but the last line.
let (lastLine,rest) = break (`elem` "\r\n") $ reverse prompt
outputStr $ reverse rest
let (lastLine,rest) = break (`elem` stringToGraphemes "\r\n")
$ reverse prompt'
outputStr $ graphemesToString $ reverse rest
doTerm tops $ reverse lastLine
{- | If Ctrl-C is pressed during the given action, throw an exception
......
......@@ -12,13 +12,13 @@ import Control.Monad
import Control.Monad.Catch (handle, throwM)
runCommandLoop :: (CommandMonad m, MonadState Layout m, LineState s)
=> TermOps -> String -> KeyCommand m s a -> s -> m a
=> TermOps -> Prefix -> KeyCommand m s a -> s -> m a
runCommandLoop tops@TermOps{evalTerm = e} prefix cmds initState
= case e of -- NB: Need to separate this case out from the above pattern
-- in order to build on ghc-6.12.3
EvalTerm eval liftE
-> eval $ withGetEvent tops
$ runCommandLoop' liftE tops (stringToGraphemes prefix) initState
$ runCommandLoop' liftE tops prefix initState
cmds
runCommandLoop' :: forall m n s a . (Term n, CommandMonad n,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment