Class LineReaderBuilder
LineReader
instances.
This builder provides a fluent API for constructing LineReader objects with various configuration options. It simplifies the process of creating a properly configured LineReader by providing methods for setting all the necessary components and options.
Example usage:
LineReader reader = LineReaderBuilder.builder() .terminal(terminal) .completer(completer) .parser(parser) .highlighter(highlighter) .variable(LineReader.HISTORY_FILE, historyFile) .option(LineReader.Option.AUTO_LIST, true) .build();
If no terminal is provided, the builder will attempt to create a default terminal
using TerminalBuilder.terminal()
.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Builds and returns a LineReader instance with the configured options.static LineReaderBuilder
builder()
Creates a new LineReaderBuilder instance.Sets the completer to be used for tab completion.completionMatcher
(CompletionMatcher completionMatcher) highlighter
(Highlighter highlighter) Sets the highlighter to be used for syntax highlighting.option
(LineReader.Option option, boolean value) Sets the parser to be used for parsing command lines.Sets the terminal to be used by the LineReader.
-
Method Details
-
builder
Creates a new LineReaderBuilder instance.- Returns:
- a new LineReaderBuilder
-
terminal
Sets the terminal to be used by the LineReader.If not specified, a default terminal will be created when building the LineReader.
- Parameters:
terminal
- the terminal to use- Returns:
- this builder
-
appName
-
variables
-
variable
-
option
-
history
-
completer
Sets the completer to be used for tab completion.The completer provides completion candidates when the user presses the tab key.
- Parameters:
completer
- the completer to use- Returns:
- this builder
- See Also:
-
highlighter
Sets the highlighter to be used for syntax highlighting.The highlighter applies styling to the input text as the user types.
- Parameters:
highlighter
- the highlighter to use- Returns:
- this builder
- See Also:
-
parser
Sets the parser to be used for parsing command lines.The parser breaks the input line into tokens according to specific syntax rules. It is used during tab completion and when accepting a line of input.
This method will log a warning if the provided parser does not support the
CompletingParsedLine
interface, as this may cause issues with completion of escaped or quoted words.- Parameters:
parser
- the parser to use- Returns:
- this builder
- See Also:
-
expander
-
completionMatcher
-
build
Builds and returns a LineReader instance with the configured options.This method creates a new LineReader with all the components and options that have been set on this builder. If no terminal has been provided, a default terminal will be created.
The resulting LineReader will have the following components set:
- Terminal - either the provided terminal or a default one
- Application name - either the provided name or the terminal name
- History - either the provided history or a new DefaultHistory
- Completer, Highlighter, Parser, Expander - if provided
- Options - any options that were set using option()
- Returns:
- a new LineReader instance
- Throws:
IOError
- if there is an error creating the default terminal
-