Alternate constructor that tries all known readline implementations, in this order:
Alternate constructor that tries all known readline implementations, in this order:
- GNU Readline - Editline - Getline - JLine - Simple (pure Java)
application name
Alternate constructor taking a single readline implementation.
Alternate constructor taking a single readline implementation. Fails if that readline implementation cannot be found.
application name
readline implementation
the application name, used by some readline libraries for key-binding
list of readline libraries to try to load, in
order. The ReadlineType values are
defined by the grizzled.readline
package.
delimiters to use when tokenizing a line for tab-completion.
List of handlers.
List of handlers. The subclass must define this value to contain a
list of its handlers. The allHandlers property will combine
this list with the help handler to get the list of all handlers.
If you define your own help handler, you'll have to override the
helpHandler property to return your help handler, instead of
the default one.
Default list of readline libraries to try, in order.
Assumed output width of the screen.
StartCommandIdentifier is the list of characters that are
permitted as the first character of a white space-delimited,
multicharacter command name.
StartCommandIdentifier is the list of characters that are
permitted as the first character of a white space-delimited,
multicharacter command name. All other characters are assumed to
introduce single-character commands. Subclasses may override this value
to permit additional, or different, starting characters for
multicharacter command names. See the splitCommandAndArgs()
method for more details.
Get all handlers.
Get all handlers. By default, this property combines the
handlers value with the default help handler,
HelpHandler. If you define your own help handler, you'll
have to override the helpHandler property to return your
help handler, instead of the default one.
the application name, used by some readline libraries for key-binding
Emit an error message in a consistent way.
Emit an error message in a consistent way. May be overridden by subclasses. The default implementation prints errors in red.
the message to emit
Handles a command line, just as if it had been typed directly at the prompt.
Handles a command line, just as if it had been typed directly at the prompt.
the command line
KeepGoing to tell the main loop to continue,
or Stop to tell the main loop to be done.
Called when an end-of-file condition is encountered while reading a command (On Unix-like systems, with some readline libraries, this happens when the user pressed Ctrl-D).
Called when an end-of-file condition is encountered while reading a
command (On Unix-like systems, with some readline libraries, this
happens when the user pressed Ctrl-D). prompt. The default version
of this method simply returns Stop, causing the command
loop to exit.
KeepGoing to tell the main loop to continue,
or Stop to tell the main loop to be done.
Called when an empty command line is entered in response to the prompt.
Called when an empty command line is entered in response to the
prompt. The default version of this method simply returns
KeepGoing.
KeepGoing to tell the main loop to continue,
or Stop to tell the main loop to be done.
Called when an exception occurs during the main loop.
Called when an exception occurs during the main loop. This method
can handle the exception however it wants; it must return either
KeepGoing or Stop. The default version
of this method dumps the exception stack trace and returns
Stop.
the exception
KeepGoing to tell the main loop to continue,
or Stop to tell the main loop to be done.
Called when a command is entered that isn't recognized.
Called when a command is entered that isn't recognized. The default
version of this method prints an error message and returns
KeepGoing.
the command name
the command arguments
KeepGoing to tell the main loop to continue,
or Stop to tell the main loop to be done.
Get the help handler.
Get the help handler. Override this property if you want to supply your own help handler.
Get the history object being used to record command history.
Get the history object being used to record command history.
the grizzled.readline.History object
Repeatedly issue a prompt, accept input, parse an initial prefix from the received input, and dispatch to execution handlers.
Called after a command line is interpreted.
Called after a command line is interpreted. The default implementation
simply returns KeepGoing.
the command that invoked this handler
the remainder of the unparsed command line
KeepGoing to tell the main loop to continue,
or Stop to tell the main loop to be done.
Called immediately after the main loop (mainLoop()) ends
its command loop, this hook method can be used for cleanup.
Called immediately after the main loop (mainLoop()) ends
its command loop, this hook method can be used for cleanup. The
default implementation does nothing.
Called just before a command line is interpreted, this hook method can edit the command.
Called just before a command line is interpreted, this hook method can edit the command.
the command line
The possibly edited command, Some("") to signal an empty command, or None to signal EOF.
Called just before the main loop (mainLoop()) begins its
command loop, this hook method can be used for initialization.
Called just before the main loop (mainLoop()) begins its
command loop, this hook method can be used for initialization. The
default implementation does nothing.
The primary prompt string.
Push a reader on the reader stack.
Push a reader on the reader stack. The reader on top of the stack
is used until it returns None (indicating EOF). Then, it is
removed from the stack, and the next reader is used. When the only
reader remaining on the stack returns None, the command
interpreter signals an EOF condition to the subclass (by calling
handleEOF()).
The reader is a simple function that takes a prompt string (which
it can choose to ignore) and returns a line of input
(Some(input)) or None for EOF. The line of input,
if returned, should not have a trailing newline.
the reader function
The second prompt string, used when additional input is being retrieved.
Split a command from its argument list, returning the command as one string and the remaining unparsed argument string as the other string.
Split a command from its argument list, returning the command as one string and the remaining unparsed argument string as the other string. The commmand name is parsed from the remaining arguments using the following rules:
- If the first non-white character if the input line is in the
StartCommandIdentifier string, then the command is assumed to be
a identifier that is separated from the arguments by white space.
- If the first character if the input line is not in the
StartCommandIdentifier string, then the command is assumed to be
a single-character command, with the arguments immediately
following the single character.
The StartCommandIdentifier string is an overridable field
defined by this class, consisting of the characters permitted to start
a multicharacter command. By default, it consists of alphanumerics.
Subclasses may override it to permit additional, or different, starting
characters for multicharacter commands.
For example, using the default identifier characters, this function will break the following commands into command + arguments as shown:
Input: foo bar baz
Result: Command foo, argument string "bar baz"
Input: !bar
Result: Command ! argument string "bar"
Input: ? one two
Result: Command ? argument string "one two"
Subclasses may override this method to parse commands differently.
the input type
A (commandName, argumentString) 2-tuple
delimiters to use when tokenizing a line for tab-completion.
Emit a warning message in a consistent way.
Emit a warning message in a consistent way. May be overridden by subclasses. The default implementation prints the message with the prefix "Warning: ".
the message to emit
Base class for command interpreters.
CommandInterpreteris the base class of any command interpreter. This class and theCommandHandlertrait provide a simple framework for writing line-oriented command-interpreters. This framework is conceptually similar to the Pythoncmdmodule and itsCmdclass, though the implementation differs substantially in places.For reading input from the console,
CommandInterpreterwill use of any of the readline libraries supported by thegrizzled.readlinepackage. All of those libraries support a persistent command history, and most support command completion and command editing.A command line consists of an initial command name, followed by a list of arguments to that command. The
CommandInterpreterclass's command reader automatically separates the command and the remaining arguments, via thesplitCommandAndArgs()method. Parsing the arguments is left to the actual command implementation. The rules for how the command is split from the remainder of the input line are outlined in the documentation for thesplitCommandAndArgs()method.