Safe Haskell | None |
---|---|
Language | Haskell98 |
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.
- data Sh st a
- runSh :: st -> OutputCommand -> Sh st () -> IO (CommandResult st)
- shellPut :: BackendOutput -> Sh st ()
- shellPutStr :: String -> Sh st ()
- shellPutStrLn :: String -> Sh st ()
- shellPutInfo :: String -> Sh st ()
- shellPutInfoLn :: String -> Sh st ()
- shellPutErr :: String -> Sh st ()
- shellPutErrLn :: String -> Sh st ()
- getShellSt :: Sh st st
- putShellSt :: st -> Sh st ()
- modifyShellSt :: (st -> st) -> Sh st ()
- shellSpecial :: ShellSpecial st -> Sh st ()
- type ShellContext st = (CommandResult st, OutputCommand)
- extractContext :: Sh st (ShellContext st)
- runWithContext :: ShellContext st -> Sh st a -> IO (a, CommandResult st)
- updateCommandResult :: CommandResult st -> Sh st ()
The Shell monad
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.
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
being mutable and CommandResult
stOutputCommand
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