diff --git a/System/Console/Haskeline.hs b/System/Console/Haskeline.hs index f42277b..9c4590c 100644 --- a/System/Console/Haskeline.hs +++ b/System/Console/Haskeline.hs @@ -46,6 +46,7 @@ module System.Console.Haskeline( getInputLine, getInputLineWithInitial, getInputChar, + getInputChar', getPassword, waitForAnyKey, -- ** Outputting text @@ -232,6 +233,20 @@ acceptOneChar = choiceCmd [useChar $ \c s -> change (insertChar c) s keyCommand acceptOneChar , ctrlChar 'd' +> failCmd] +{- | Reads one character of input, including non-printable. +-} +getInputChar' :: (MonadIO m, MonadMask m) => String -- ^ The input prompt + -> InputT m (Maybe Char) +getInputChar' = promptedInput getInputCmdChar' $ + runMaybeT . getLocaleChar + +getInputCmdChar' :: (MonadIO m, MonadMask m) => TermOps -> Prefix -> InputT m (Maybe Char) +getInputCmdChar' tops prefix = runInputCmdT tops + $ runCommandLoop tops prefix acceptOneChar' emptyIM + +acceptOneChar' :: Monad m => KeyCommand m InsertMode (Maybe Char) +acceptOneChar' = useChar' $ \c _s -> return (Just c) + ---------- {- | Waits for one key to be pressed, then returns. Ignores the value of the specific key. diff --git a/System/Console/Haskeline/Command.hs b/System/Console/Haskeline/Command.hs index 1a0d915..f4bb7c6 100644 --- a/System/Console/Haskeline/Command.hs +++ b/System/Console/Haskeline/Command.hs @@ -22,6 +22,7 @@ module System.Console.Haskeline.Command( changeFromChar, (+>), useChar, + useChar', choiceCmd, keyChoiceCmd, keyChoiceCmdM, @@ -97,6 +98,12 @@ useChar act = KeyMap $ \k -> case k of -> Just $ Consumed (act c) _ -> Nothing +useChar' :: (Char -> Command m s t) -> KeyCommand m s t +useChar' act = KeyMap $ \k -> case k of + Key _m (KeyChar c) + -> Just $ Consumed (act c) + _ -> Nothing + withoutConsuming :: Command m s t -> KeyCommand m s t withoutConsuming = KeyMap . const . Just . NotConsumed