public abstract class SimpleTerminalConsole
extends java.lang.Object
TerminalConsoleAppender. Once started, it displays
a command prompt ("> ") and reads input commands from the console.
Usage: Extend this class and implement the abstract
methods for your application. Consider overriding
buildReader(LineReaderBuilder) to add further features to the
console (e.g. call LineReaderBuilder.completer(Completer) with
a custom completer to provide command completion).
| Constructor and Description |
|---|
SimpleTerminalConsole() |
| Modifier and Type | Method and Description |
|---|---|
protected org.jline.reader.LineReader |
buildReader(org.jline.reader.LineReaderBuilder builder)
Configures the
LineReaderBuilder and LineReader with
additional options. |
protected abstract boolean |
isRunning()
Determines if the application is still running and accepting input.
|
protected void |
processInput(java.lang.String input)
Process an input line entered through the console.
|
protected abstract void |
runCommand(java.lang.String command)
Run a command entered in the console.
|
protected abstract void |
shutdown()
Shutdown the application and perform a clean exit.
|
void |
start()
Start reading commands from the console.
|
protected abstract boolean isRunning()
true to continue reading inputprotected abstract void runCommand(java.lang.String command)
command - The command line to runprotected abstract void shutdown()
This is called if the application receives SIGINT while reading input, e.g. when pressing CTRL+C on most terminal implementations.
protected void processInput(java.lang.String input)
The default implementation trims leading and trailing whitespace from the input and skips execution if the command is empty.
input - The input lineprotected org.jline.reader.LineReader buildReader(org.jline.reader.LineReaderBuilder builder)
LineReaderBuilder and LineReader with
additional options.
Override this method to make further changes, (e.g. call
LineReaderBuilder.appName(String) or
LineReaderBuilder.completer(Completer)).
The default implementation sets some opinionated default options, which are considered to be appropriate for most applications:
LineReader.Option#DISABLE_EVENT_EXPANSION: JLine implements
Bash's Event Designators by default. These usually do not
behave as expected in a simple command environment, so it's
recommended to disable it.LineReader.Option#INSERT_TAB: By default, JLine inserts
a tab character when attempting to tab-complete on empty input.
It is more intuitive to show a list of commands instead.builder - The builder to configurepublic void start()
Note that this method won't return until one of the following conditions are met:
isRunning() returns false, indicating that the
application is shutting down.shutdown() is triggered by the user (e.g. due to
pressing CTRL+C)