-- 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 <a>HaskelineT</a>. It simplifies several aspects of composing
--   Haskeline with State and Exception monads in modern versions of mtl.
--   
--   <pre>
--   type Repl a = HaskelineT IO a
--   </pre>
--   
--   The evaluator <a>evalRepl</a> evaluates a <a>HaskelineT</a> monad
--   transformer by constructing a shell with several custom functions and
--   evaluating it inside of IO:
--   
--   <ul>
--   <li>Commands: Handled on ordinary input.</li>
--   <li>Completions: Handled when tab key is pressed.</li>
--   <li>Options: Handled when a command prefixed by a prefix character is
--   entered.</li>
--   <li>Command prefix character: Optional command prefix ( passing
--   Nothing ignores the Options argument ).</li>
--   <li>Banner: Text Displayed at initialization.</li>
--   <li>Initializer: Run at initialization.</li>
--   </ul>
--   
--   A simple evaluation function might simply echo the output back to the
--   screen.
--   
--   <pre>
--   -- Evaluation : handle each line user inputs
--   cmd :: String -&gt; Repl ()
--   cmd input = liftIO $ print input
--   </pre>
--   
--   Several tab completion options are available, the most common is the
--   <a>WordCompleter</a> 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.
--   
--   <pre>
--   -- Tab Completion: return a completion for partial words entered
--   completer :: Monad m =&gt; WordCompleter m
--   completer n = do
--     let names = ["kirk", "spock", "mccoy"]
--     return $ filter (isPrefixOf n) names
--   </pre>
--   
--   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 <a>unwords</a>
--   function can be used to concatenate.
--   
--   <pre>
--   -- Commands
--   help :: [String] -&gt; Repl ()
--   help args = liftIO $ print $ "Help: " ++ show args
--   
--   say :: [String] -&gt; Repl ()
--   say args = do
--     _ &lt;- liftIO $ system $ "cowsay" ++ " " ++ (unwords args)
--     return ()
--   </pre>
--   
--   Now we need only map these functions to their commands.
--   
--   <pre>
--   options :: [(String, [String] -&gt; Repl ())]
--   options = [
--       ("help", help)  -- :help
--     , ("say", say)    -- :say
--     ]
--   </pre>
--   
--   The banner function is simply an IO action that is called at the start
--   of the shell.
--   
--   <pre>
--   ini :: Repl ()
--   ini = liftIO $ putStrLn "Welcome!"
--   </pre>
--   
--   Putting it all together we have a little shell.
--   
--   <pre>
--   main :: IO ()
--   main = evalRepl (pure "&gt;&gt;&gt; ") cmd options (Just ':') (Word completer) ini
--   </pre>
--   
--   Putting this in a file we can test out our cow-trek shell.
--   
--   <pre>
--   $ runhaskell Main.hs
--   Welcome!
--   &gt;&gt;&gt; &lt;TAB&gt;
--   kirk spock mccoy
--   
--   &gt;&gt;&gt; k&lt;TAB&gt;
--   kirk
--   
--   &gt;&gt;&gt; spam
--   "spam"
--   
--   &gt;&gt;&gt; :say Hello Haskell
--    _______________
--   &lt; Hello Haskell &gt;
--    ---------------
--           \   ^__^
--            \  (oo)\_______
--               (__)\       )\/\
--                   ||----w |
--                   ||     ||
--   </pre>
--   
--   See <a>https://github.com/sdiehl/repline</a> 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 ()
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)
