Shellac-0.9.9: A framework for creating shell envinronments

Safe HaskellNone
LanguageHaskell2010

System.Console.Shell.ShellMonad

Contents

Description

This module implements a monad for use in shell commands and in evaluation functions. It is a state moand layered over IO. liftIO may be used to execute arbitrary I/O actions. However, the shellPut* commands are the preferred way to output text.

Synopsis

The Shell monad

data Sh st a Source #

The type of shell commands. This monad is a state monad layered over IO. The type parameter st allows the monad to carry around a package of user-defined state.

Instances

Monad (Sh st) Source # 

Methods

(>>=) :: Sh st a -> (a -> Sh st b) -> Sh st b #

(>>) :: Sh st a -> Sh st b -> Sh st b #

return :: a -> Sh st a #

fail :: String -> Sh st a #

Functor (Sh st) Source # 

Methods

fmap :: (a -> b) -> Sh st a -> Sh st b #

(<$) :: a -> Sh st b -> Sh st a #

MonadFix (Sh st) Source # 

Methods

mfix :: (a -> Sh st a) -> Sh st a #

Applicative (Sh st) Source # 

Methods

pure :: a -> Sh st a #

(<*>) :: Sh st (a -> b) -> Sh st a -> Sh st b #

(*>) :: Sh st a -> Sh st b -> Sh st b #

(<*) :: Sh st a -> Sh st b -> Sh st a #

MonadIO (Sh st) Source # 

Methods

liftIO :: IO a -> Sh st a #

CommandFunction (Sh st ()) st Source # 

Methods

parseCommand :: String -> Sh st () -> CommandParser st

commandSyntax :: Sh st () -> [Doc]

runSh :: st -> OutputCommand -> Sh st () -> IO (CommandResult st) Source #

Execute a shell action

Output functions

shellPut :: BackendOutput -> Sh st () Source #

Output a tagged string to the console

shellPutStr :: String -> Sh st () Source #

Prints a regular output string

shellPutStrLn :: String -> Sh st () Source #

Prints regular output with a line terminator

shellPutInfo :: String -> Sh st () Source #

Prints an informational output string

shellPutInfoLn :: String -> Sh st () Source #

Prints an informational output string with a line terminator

shellPutErr :: String -> Sh st () Source #

Prints an error output string

shellPutErrLn :: String -> Sh st () Source #

Prints and error output string with a line terminator

Shell state accessors

getShellSt :: Sh st st Source #

Get the current shell state

putShellSt :: st -> Sh st () Source #

Set the shell state

modifyShellSt :: (st -> st) -> Sh st () Source #

Apply the given funtion to the shell state

Special actions

shellSpecial :: ShellSpecial st -> Sh st () Source #

Schedule a shell "special" action. Only the last call to this function will affect the shell's behavior! It modifies a bit of state that is overwritten on each call.

Extracting and using the shell context

type ShellContext st = (CommandResult st, OutputCommand) Source #

The total context held by the shell, with CommandResult st being mutable and OutputCommand immutable

extractContext :: Sh st (ShellContext st) Source #

Extract the current shell context for future use, see runWithContext

runWithContext :: ShellContext st -> Sh st a -> IO (a, CommandResult st) Source #

Run a shell with the supplied context, useful if you need to invoke a shell within a new IO context, for example when using timeout

updateCommandResult :: CommandResult st -> Sh st () Source #

Update the mutable context of this shell

Orphan instances

MonadState st (Sh st) Source # 

Methods

get :: Sh st st #

put :: st -> Sh st () #

state :: (st -> (a, st)) -> Sh st a #