Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module defines the Shellac interface for shell backends. A shell backend
is required to provide sensible implementations for outputString
, flushOutput
,
getSingleChar
, getInput
, and getWordBreakChars
. All other operations may
be noops (however, they must not denote bottom!).
This module is intended for use by backend implementers. It is not intended to be used by regular clients of the library. The Shellac package provides a basic backend (System.Console.Shell.Backend.Basic). More advanced backends are available in separate packages.
- type CompletionFunction = (String, String, String) -> IO (Maybe (String, [String]))
- data BackendOutput
- data ShellBackend bst = ShBackend {
- initBackend :: IO bst
- shutdownBackend :: bst -> IO ()
- outputString :: bst -> BackendOutput -> IO ()
- flushOutput :: bst -> IO ()
- getSingleChar :: bst -> String -> IO (Maybe Char)
- getInput :: bst -> String -> IO (Maybe String)
- addHistory :: bst -> String -> IO ()
- setWordBreakChars :: bst -> String -> IO ()
- getWordBreakChars :: bst -> IO String
- onCancel :: bst -> IO ()
- setAttemptedCompletionFunction :: bst -> CompletionFunction -> IO ()
- setDefaultCompletionFunction :: bst -> Maybe (String -> IO [String]) -> IO ()
- completeFilename :: bst -> String -> IO [String]
- completeUsername :: bst -> String -> IO [String]
- clearHistoryState :: bst -> IO ()
- setMaxHistoryEntries :: bst -> Int -> IO ()
- getMaxHistoryEntries :: bst -> IO Int
- readHistory :: bst -> FilePath -> IO ()
- writeHistory :: bst -> FilePath -> IO ()
- defaultWordBreakChars :: [Char]
- templateBackend :: a -> ShellBackend a
Documentation
type CompletionFunction = (String, String, String) -> IO (Maybe (String, [String])) Source #
The type of completion functions. The argument is a triple consisting of (before,word,after), where 'word' is a string of non-word-break characters which contains the cursor position. 'before' is all characters on the line before 'word' and 'after' is all characters on the line after word. The return value should be 'Nothing' if no completions can be generated, or 'Just (newWord,completions)' if completions can be generated. 'newWord' is a new string to replace 'word' on the command line and 'completions' is a list of all possible completions of 'word'. To achieve the standard "complete-as-far-as-possible" behavior, 'newWord' should be the longest common prefix of all words in 'completions'.
data BackendOutput Source #
A datatype representing ouput to be printed. The different categories of output are distinguished to that shell backends can, for example, apply different colors or send output to different places (stderr versus stdout).
RegularOutput String | The most regular way to produce output |
InfoOutput String | An informative output string, such as command help |
ErrorOutput String | An string generated by an error |
data ShellBackend bst Source #
This record type contains all the functions that Shellac allows the pluggable
backend to provide. Most of these operations are optional and relate to
advanced features like command completion and history. However, a shell backend
is required to provide sensible implementations for outputString
, flushOutput
,
getSingleChar
, getInput
, and getWordBreakChars
.
ShBackend | |
|
defaultWordBreakChars :: [Char] Source #
Provides a sane default set of characters to use when breaking
lines into 'words'. If a backend does not have configurable
word break characters, then getWordBreakCharacters
can just
return this default set.
templateBackend :: a -> ShellBackend a Source #
This backend template is useful for defining custom backends.
The idea is that you will use templateBackend
to generate a
bare-bones backend implemenation and only fill in the methods
that you wish to define using the record update syntax.
The parameter to templateBackend
becomes the backend state associated with the backend and is
passed into to each of the operation methods.