-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Haskeline wrapper for GHCi-like REPL interfaces. -- -- Haskeline wrapper for GHCi-like REPL interfaces. Composable with -- normal mtl transformers. @package repline @version 0.2.2.0 -- | Repline exposes an additional monad transformer on top of Haskeline -- called HaskelineT. It simplifies several aspects of composing -- Haskeline with State and Exception monads in modern versions of mtl. -- --
-- type Repl a = HaskelineT IO a ---- -- The evaluator evalRepl evaluates a HaskelineT monad -- transformer by constructing a shell with several custom functions and -- evaluating it inside of IO: -- --
-- -- Evaluation : handle each line user inputs -- cmd :: String -> Repl () -- cmd input = liftIO $ print input ---- -- Several tab completion options are available, the most common is the -- WordCompleter which completes on single words separated by -- spaces from a list of matches. The internal logic can be whatever is -- required and can also access a StateT instance to query application -- state. -- --
-- -- Tab Completion: return a completion for partial words entered -- completer :: Monad m => WordCompleter m -- completer n = do -- let names = ["kirk", "spock", "mccoy"] -- return $ filter (isPrefixOf n) names ---- -- Input which is prefixed by a colon (commands like ":type" and ":help") -- queries an association list of functions which map to custom logic. -- The function takes a space-separated list of augments in it's first -- argument. If the entire line is desired then the unwords -- function can be used to concatenate. -- --
-- -- Commands -- help :: [String] -> Repl () -- help args = liftIO $ print $ "Help: " ++ show args -- -- say :: [String] -> Repl () -- say args = do -- _ <- liftIO $ system $ "cowsay" ++ " " ++ (unwords args) -- return () ---- -- Now we need only map these functions to their commands. -- --
-- options :: [(String, [String] -> Repl ())]
-- options = [
-- ("help", help) -- :help
-- , ("say", say) -- :say
-- ]
--
--
-- The banner function is simply an IO action that is called at the start
-- of the shell.
--
-- -- ini :: Repl () -- ini = liftIO $ putStrLn "Welcome!" ---- -- Putting it all together we have a little shell. -- --
-- main :: IO () -- main = evalRepl (pure ">>> ") cmd options (Just ':') (Word completer) ini ---- -- Putting this in a file we can test out our cow-trek shell. -- --
-- $ runhaskell Main.hs -- Welcome! -- >>> <TAB> -- kirk spock mccoy -- -- >>> k<TAB> -- kirk -- -- >>> spam -- "spam" -- -- >>> :say Hello Haskell -- _______________ -- < Hello Haskell > -- --------------- -- \ ^__^ -- \ (oo)\_______ -- (__)\ )\/\ -- ||----w | -- || || ---- -- See https://github.com/sdiehl/repline for more examples. module System.Console.Repline data HaskelineT (m :: * -> *) a -- | Run HaskelineT monad runHaskelineT :: MonadException m => Settings m -> HaskelineT m a -> m a -- | Evaluate the REPL logic into a MonadException context. evalRepl :: (Functor m, MonadException m) => HaskelineT m String -> Command (HaskelineT m) -> Options (HaskelineT m) -> Maybe Char -> CompleterStyle m -> HaskelineT m a -> m () -- | REPL Options datatype data ReplOpts m ReplOpts :: HaskelineT m String -> Command (HaskelineT m) -> Options (HaskelineT m) -> Maybe Char -> CompleterStyle m -> HaskelineT m () -> ReplOpts m -- | Banner [banner] :: ReplOpts m -> HaskelineT m String -- | Command function [command] :: ReplOpts m -> Command (HaskelineT m) -- | Options list and commands [options] :: ReplOpts m -> Options (HaskelineT m) -- | Optional command prefix ( passing Nothing ignores the Options argument -- ) [prefix] :: ReplOpts m -> Maybe Char -- | Tab completion function [tabComplete] :: ReplOpts m -> CompleterStyle m -- | Initialiser [initialiser] :: ReplOpts m -> HaskelineT m () -- | Evaluate the REPL logic into a MonadException context from the -- ReplOpts configuration. evalReplOpts :: (Functor m, MonadException m) => ReplOpts m -> m () -- | Command function synonym type Cmd m = [String] -> m () -- | Options function synonym type Options m = [(String, Cmd m)] -- | Word completer type WordCompleter m = (String -> m [String]) -- | Line completer type LineCompleter m = (String -> String -> m [Completion]) data CompleterStyle m -- | Completion function takes single word. Word :: WordCompleter m -> CompleterStyle m -- | Completion function takes single word ( no space ). Word0 :: WordCompleter m -> CompleterStyle m -- | Completion function takes tuple of full line. Cursor :: LineCompleter m -> CompleterStyle m -- | Completion function completes files in CWD. File :: CompleterStyle m -- | Conditional tab completion based on prefix. Prefix :: CompletionFunc m -> [(String, CompletionFunc m)] -> CompleterStyle m -- | Command function synonym type Command m = String -> m () -- | Performs completions from the given line state. -- -- The first String argument is the contents of the line to the -- left of the cursor, reversed. The second String argument is the -- contents of the line to the right of the cursor. -- -- The output String is the unused portion of the left half of the -- line, reversed. type CompletionFunc (m :: Type -> Type) = (String, String) -> m (String, [Completion]) -- | Word completer function wordCompleter :: Monad m => WordCompleter m -> CompletionFunc m -- | List completer function listCompleter :: Monad m => [String] -> CompletionFunc m -- | File completer function fileCompleter :: MonadIO m => CompletionFunc m listWordCompleter :: Monad m => [String] -> WordCompleter m -- | Return a completion function a line fragment runMatcher :: Monad m => [(String, CompletionFunc m)] -> CompletionFunc m -> CompletionFunc m trimComplete :: String -> Completion -> Completion -- | Abort the current REPL loop, and continue. abort :: MonadIO m => HaskelineT m a -- | Wrap a HasklineT action so that if an interrupt is thrown the shell -- continues as normal. tryAction :: MonadException m => HaskelineT m a -> HaskelineT m a -- | Catch all toplevel failures. dontCrash :: (MonadIO m, MonadException m) => m () -> m () instance System.Console.Haskeline.MonadException.MonadException m => System.Console.Repline.MonadHaskeline (System.Console.Repline.HaskelineT m) instance Control.Monad.Trans.Class.MonadTrans System.Console.Repline.HaskelineT instance System.Console.Haskeline.MonadException.MonadException m => System.Console.Haskeline.MonadException.MonadException (System.Console.Repline.HaskelineT m) instance Control.Monad.IO.Class.MonadIO m => Control.Monad.IO.Class.MonadIO (System.Console.Repline.HaskelineT m) instance GHC.Base.Applicative m => GHC.Base.Applicative (System.Console.Repline.HaskelineT m) instance GHC.Base.Functor m => GHC.Base.Functor (System.Console.Repline.HaskelineT m) instance GHC.Base.Monad m => GHC.Base.Monad (System.Console.Repline.HaskelineT m) instance Control.Monad.Fail.MonadFail m => Control.Monad.Fail.MonadFail (System.Console.Repline.HaskelineT m) instance Control.Monad.State.Class.MonadState s m => Control.Monad.State.Class.MonadState s (System.Console.Repline.HaskelineT m) instance Control.Monad.Reader.Class.MonadReader r m => Control.Monad.Reader.Class.MonadReader r (System.Console.Repline.HaskelineT m) instance System.Console.Haskeline.MonadException.MonadException m => System.Console.Repline.MonadHaskeline (System.Console.Haskeline.InputT.InputT m) instance System.Console.Repline.MonadHaskeline m => System.Console.Repline.MonadHaskeline (Control.Monad.Trans.State.Strict.StateT s m)