-- 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.4.3.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>Multi-line command: Optional command name that switches to a
--   multi-line input. (Press <a>Ctrl-D</a> to exit and commit the
--   multi-line input). Passing Nothing disables multi-line input
--   support.</li>
--   <li>Banner: Text Displayed at initialisation. It takes an argument so
--   it can take into account if the current line is part of a multi-line
--   input.</li>
--   <li>Initialiser: Run at initialisation.</li>
--   <li>Finaliser: Run on <a>Ctrl-D</a>, it can be used to output a custom
--   exit message or to choose whether to exit or not depending on the
--   application state</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 arg = do
--     _ &lt;- liftIO $ callCommand $ "cowsay" ++ " " ++ arg
--     return ()
--   </pre>
--   
--   (You may need the following import in pull <tt>callCommand</tt> into
--   scope)
--   
--   <pre>
--   import System.Process (callCommand)
--   </pre>
--   
--   Now we need only map these functions to their commands.
--   
--   <pre>
--   options :: Options (HaskelineT IO)
--   options = [
--       ("help", help . words)  -- :help
--     , ("say", say)            -- :say
--     ]
--   </pre>
--   
--   The initialiser function is simply an IO action that is called at the
--   start of the shell.
--   
--   <pre>
--   ini :: Repl ()
--   ini = liftIO $ putStrLn "Welcome!"
--   </pre>
--   
--   The finaliser function is an IO action that is called at the end of
--   the shell.
--   
--   <pre>
--   final :: Repl ExitDecision
--   final = do
--     liftIO $ putStrLn "Goodbye!"
--     return Exit
--   </pre>
--   
--   Putting it all together we have a little shell.
--   
--   <pre>
--   main :: IO ()
--   main = evalRepl (const . pure $ "&gt;&gt;&gt; ") cmd options (Just ':') (Just "paste") (Word completer) ini final
--   </pre>
module System.Console.Repline

-- | Monad transformer for readline input
data HaskelineT (m :: Type -> Type) a

-- | Run HaskelineT monad
runHaskelineT :: (MonadMask m, MonadIO m) => Settings m -> HaskelineT m a -> m a
class MonadCatch m => MonadHaskeline (m :: Type -> Type)

-- | Evaluate the REPL logic into a MonadCatch context.
evalRepl :: (MonadMask m, MonadIO m) => (MultiLine -> HaskelineT m String) -> Command (HaskelineT m) -> Options (HaskelineT m) -> Maybe Char -> Maybe String -> CompleterStyle m -> HaskelineT m a -> HaskelineT m ExitDecision -> m ()

-- | REPL Options datatype
data ReplOpts (m :: Type -> Type)
ReplOpts :: (MultiLine -> HaskelineT m String) -> Command (HaskelineT m) -> Options (HaskelineT m) -> Maybe Char -> Maybe String -> CompleterStyle m -> HaskelineT m () -> HaskelineT m ExitDecision -> ReplOpts (m :: Type -> Type)

-- | Banner
[banner] :: ReplOpts (m :: Type -> Type) -> MultiLine -> HaskelineT m String

-- | Command function
[command] :: ReplOpts (m :: Type -> Type) -> Command (HaskelineT m)

-- | Options list and commands
[options] :: ReplOpts (m :: Type -> Type) -> Options (HaskelineT m)

-- | Optional command prefix ( passing Nothing ignores the Options argument
--   )
[prefix] :: ReplOpts (m :: Type -> Type) -> Maybe Char

-- | Optional multi-line command ( passing Nothing disables multi-line
--   support )
[multilineCommand] :: ReplOpts (m :: Type -> Type) -> Maybe String

-- | Tab completion function
[tabComplete] :: ReplOpts (m :: Type -> Type) -> CompleterStyle m

-- | Initialiser
[initialiser] :: ReplOpts (m :: Type -> Type) -> HaskelineT m ()

-- | Finaliser ( runs on <a>Ctrl-D</a> )
[finaliser] :: ReplOpts (m :: Type -> Type) -> HaskelineT m ExitDecision

-- | Evaluate the REPL logic into a MonadCatch context from the ReplOpts
--   configuration.
evalReplOpts :: (MonadMask m, MonadIO m) => ReplOpts m -> m ()

-- | Command function synonym
--   
--   The argument corresponds to the arguments of the command, it may
--   contain spaces or newlines (when input is multi-line).
--   
--   For example, with prefix <tt><tt>:</tt></tt> and command
--   <tt>"command"</tt> the argument <a>String</a> for:
--   
--   <pre>
--   :command some arguments
--   </pre>
--   
--   is <tt>"some arguments"</tt>
type Cmd (m :: Type -> Type) = String -> m ()

-- | Options function synonym
type Options (m :: Type -> Type) = [(String, Cmd m)]

-- | Word completer
type WordCompleter (m :: Type -> Type) = String -> m [String]

-- | Line completer
type LineCompleter (m :: Type -> Type) = String -> String -> m [Completion]

-- | Tab completer types
data CompleterStyle (m :: Type -> Type)

-- | Completion function takes single word.
Word :: WordCompleter m -> CompleterStyle (m :: Type -> Type)

-- | Completion function takes single word ( no space ).
Word0 :: WordCompleter m -> CompleterStyle (m :: Type -> Type)

-- | Completion function takes tuple of full line.
Cursor :: LineCompleter m -> CompleterStyle (m :: Type -> Type)

-- | Completion function completes files in CWD.
File :: CompleterStyle (m :: Type -> Type)

-- | Conditional tab completion based on prefix.
Prefix :: CompletionFunc m -> [(String, CompletionFunc m)] -> CompleterStyle (m :: Type -> Type)

-- | Combine two completions
Combine :: CompleterStyle m -> CompleterStyle m -> CompleterStyle (m :: Type -> Type)

-- | Custom completion
Custom :: CompletionFunc m -> CompleterStyle (m :: Type -> Type)

-- | Command function synonym
type Command (m :: Type -> Type) = String -> m ()

-- | Decide whether to exit the REPL or not
data ExitDecision

-- | Keep the REPL open
Continue :: ExitDecision

-- | Close the REPL and exit
Exit :: ExitDecision

-- | Context for the current line if it is part of a multi-line input or
--   not
data MultiLine
MultiLine :: MultiLine
SingleLine :: MultiLine

-- | Performs completions from the given line state.
--   
--   The first <a>String</a> argument is the contents of the line to the
--   left of the cursor, reversed. The second <a>String</a> argument is the
--   contents of the line to the right of the cursor.
--   
--   The output <a>String</a> is the unused portion of the left half of the
--   line, reversed.
type CompletionFunc (m :: Type -> Type) = (String, String) -> m (String, [Completion])

-- | If the first completer produces no suggestions, fallback to the second
--   completer's output.
fallbackCompletion :: Monad m => CompletionFunc m -> CompletionFunc m -> CompletionFunc m

-- | 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

-- | List word completer
listWordCompleter :: Monad m => [String] -> WordCompleter m

-- | Return a completion function a line fragment
runMatcher :: Monad m => [(String, CompletionFunc m)] -> CompletionFunc m -> CompletionFunc m

-- | Trim completion
trimComplete :: String -> Completion -> Completion

-- | Abort the current REPL loop, and continue.
abort :: forall (m :: Type -> Type) a. MonadThrow m => HaskelineT m a

-- | Wrap a HasklineT action so that if an interrupt is thrown the shell
--   continues as normal.
tryAction :: forall (m :: Type -> Type) a. (MonadMask m, MonadIO m) => HaskelineT m a -> HaskelineT m a

-- | Catch all toplevel failures.
dontCrash :: (MonadIO m, MonadCatch m) => m () -> m ()
instance GHC.Internal.Base.Applicative m => GHC.Internal.Base.Applicative (System.Console.Repline.HaskelineT m)
instance GHC.Classes.Eq System.Console.Repline.MultiLine
instance GHC.Internal.Base.Functor m => GHC.Internal.Base.Functor (System.Console.Repline.HaskelineT m)
instance Control.Monad.Catch.MonadCatch m => Control.Monad.Catch.MonadCatch (System.Console.Repline.HaskelineT m)
instance GHC.Internal.Control.Monad.Fail.MonadFail m => GHC.Internal.Control.Monad.Fail.MonadFail (System.Console.Repline.HaskelineT m)
instance GHC.Internal.Control.Monad.Fix.MonadFix m => GHC.Internal.Control.Monad.Fix.MonadFix (System.Console.Repline.HaskelineT m)
instance (Control.Monad.Catch.MonadMask m, Control.Monad.IO.Class.MonadIO m) => System.Console.Repline.MonadHaskeline (System.Console.Repline.HaskelineT m)
instance (Control.Monad.Catch.MonadMask m, Control.Monad.IO.Class.MonadIO 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)
instance GHC.Internal.Base.Monad m => GHC.Internal.Base.Monad (System.Console.Repline.HaskelineT m)
instance Control.Monad.IO.Class.MonadIO m => Control.Monad.IO.Class.MonadIO (System.Console.Repline.HaskelineT m)
instance Control.Monad.Catch.MonadMask m => Control.Monad.Catch.MonadMask (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 Control.Monad.State.Class.MonadState s m => Control.Monad.State.Class.MonadState s (System.Console.Repline.HaskelineT m)
instance Control.Monad.Catch.MonadThrow m => Control.Monad.Catch.MonadThrow (System.Console.Repline.HaskelineT m)
instance Control.Monad.Trans.Class.MonadTrans System.Console.Repline.HaskelineT
instance GHC.Internal.Show.Show System.Console.Repline.MultiLine
