Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Building blocks for a GHCI-like REPL with colon-commands.
Synopsis
- type Command m = Text -> m ReplDirective
- data CommandErr
- type Completion m = Text -> m [Text]
- type OptionCommands m = Map Text (Text, Command m)
- data ReplDef m = ReplDef {
- rdOnInterrupt :: !ReplDirective
- rdGreeting :: !Text
- rdPrompt :: !Text
- rdOptionCommands :: !(OptionCommands m)
- rdExecCommand :: !(Command m)
- rdCompletion :: !(Completion m)
- data ReplDirective
- bareCommand :: MonadThrow m => m ReplDirective -> Command m
- noOptionCommands :: OptionCommands m
- noCompletion :: Applicative m => Completion m
- runReplDef :: (MonadCatch m, MonadUnliftIO m) => ReplDef m -> m ()
- stepReplDef :: MonadThrow m => ReplDef m -> Text -> m ReplDirective
Documentation
type Command m = Text -> m ReplDirective Source #
A Command
takes some input, performs some effect, and returns a directive (continue or quit).
data CommandErr Source #
Sometimes things go wrong...
CommandErrExpectedNoInput | An option |
CommandErrUnknownCommand !Text | An option |
Instances
Exception CommandErr Source # | |
Defined in Climb toException :: CommandErr -> SomeException # fromException :: SomeException -> Maybe CommandErr # displayException :: CommandErr -> String # | |
Show CommandErr Source # | |
Defined in Climb showsPrec :: Int -> CommandErr -> ShowS # show :: CommandErr -> String # showList :: [CommandErr] -> ShowS # | |
Eq CommandErr Source # | |
Defined in Climb (==) :: CommandErr -> CommandErr -> Bool # (/=) :: CommandErr -> CommandErr -> Bool # |
type Completion m = Text -> m [Text] Source #
A Completion
takes some input and returns potential matches.
Defines a REPL with commands, options, and completion.
ReplDef | |
|
data ReplDirective #
Directive to control voluntary REPL termination.
Instances
Show ReplDirective | |
Defined in Linenoise.Repl showsPrec :: Int -> ReplDirective -> ShowS # show :: ReplDirective -> String # showList :: [ReplDirective] -> ShowS # | |
Eq ReplDirective | |
Defined in Linenoise.Repl (==) :: ReplDirective -> ReplDirective -> Bool # (/=) :: ReplDirective -> ReplDirective -> Bool # |
bareCommand :: MonadThrow m => m ReplDirective -> Command m Source #
Helps you define commands that expect no input.
noCompletion :: Applicative m => Completion m Source #
runReplDef :: (MonadCatch m, MonadUnliftIO m) => ReplDef m -> m () Source #
Runs a REPL as defined.
stepReplDef :: MonadThrow m => ReplDef m -> Text -> m ReplDirective Source #
Processes a single line of input. Useful for testing. (Note that this does not handle default option commands.)