Repository : ssh://darcs.haskell.org//srv/darcs/packages/haskeline On branch : master
http://hackage.haskell.org/trac/ghc/changeset/71bbf20f717083f8e1acf878b97925f309b92f74 >--------------------------------------------------------------- commit 71bbf20f717083f8e1acf878b97925f309b92f74 Author: Judah Jacobson <[email protected]> Date: Fri Feb 24 23:46:53 2012 +0000 Don't use MonadState to expose the History API. Instead, provide explicit get/put/modifyHistory actions. This makes it easier to use InputT in a stack of monad transformers. >--------------------------------------------------------------- System/Console/Haskeline.hs | 15 ++++++++++++++- System/Console/Haskeline/InputT.hs | 20 ++++++++++++++------ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/System/Console/Haskeline.hs b/System/Console/Haskeline.hs index 419d91a..715b382 100644 --- a/System/Console/Haskeline.hs +++ b/System/Console/Haskeline.hs @@ -61,6 +61,12 @@ module System.Console.Haskeline( defaultPrefs, runInputTWithPrefs, runInputTBehaviorWithPrefs, + -- ** History + -- $history + getHistory, + putHistory, + modifyHistory, + -- * Additional submodules module System.Console.Haskeline.Completion, module System.Console.Haskeline.MonadException) where @@ -177,7 +183,7 @@ maybeAddHistory result = do AlwaysAdd -> addHistory IgnoreConsecutive -> addHistoryUnlessConsecutiveDupe IgnoreAll -> addHistoryRemovingAllDupes - in modify (adder line) + in modifyHistory (adder line) _ -> return () ---------- @@ -246,6 +252,13 @@ getPassword x = promptedInput ] loop' = keyCommand loop +{- $history +The 'InputT' monad transformer provides direct, low-level access to the user's line history state. + +However, for most applications, it should suffice to just use the 'autoAddHistory' +and 'historyFile' flags. + +-} ------- diff --git a/System/Console/Haskeline/InputT.hs b/System/Console/Haskeline/InputT.hs index 8dd031c..9129a91 100644 --- a/System/Console/Haskeline/InputT.hs +++ b/System/Console/Haskeline/InputT.hs @@ -14,7 +14,7 @@ import System.Console.Haskeline.Term import System.Directory(getHomeDirectory) import System.FilePath import Control.Applicative -import qualified Control.Monad.State as State +import Control.Monad (liftM, ap) import System.IO -- | Application-specific customizations to the user interface. @@ -47,18 +47,26 @@ newtype InputT m a = InputT {unInputT :: ReaderT RunTerm MonadReader (Settings m), MonadReader RunTerm) instance Monad m => Functor (InputT m) where - fmap = State.liftM + fmap = liftM instance Monad m => Applicative (InputT m) where pure = return - (<*>) = State.ap + (<*>) = ap instance MonadTrans InputT where lift = InputT . lift . lift . lift . lift . lift -instance Monad m => State.MonadState History (InputT m) where - get = get - put = put +-- | Get the current line input history. +getHistory :: Monad m => InputT m History +getHistory = get + +-- | Set the line input history. +putHistory :: Monad m => History -> InputT m () +putHistory = put + +-- | Change the current line input history. +modifyHistory :: Monad m => (History -> History) -> InputT m () +modifyHistory = modify -- for internal use only type InputCmdT m = StateT Layout (UndoT (StateT HistLog (StateT KillRing _______________________________________________ Cvs-libraries mailing list [email protected] http://www.haskell.org/mailman/listinfo/cvs-libraries
