Shellac- A framework for creating shell envinronments




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.


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.


MonadState st (Sh st) 
Monad (Sh st) 
Functor (Sh st) 
MonadFix (Sh st) 
MonadIO (Sh st) 
CommandFunction (Sh st ()) st 

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 stSource

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 System.Timeout.timeout

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

Update the mutable context of this shell