Package org.aesh.readline
Class Readline
java.lang.Object
org.aesh.readline.Readline
Readline is a simple way to read a single input line from the terminal/shell/console.
Readline reads/writes from/to a
Connection.
Readline is thread safe and will not accept new readline(org.aesh.terminal.Connection, java.lang.String, java.util.function.Consumer<java.lang.String>) calls
while currently reading input.
-
Constructor Summary
ConstructorsConstructorDescriptionReadline()Creates a new Readline instance with default edit mode, in-memory history, and simple completion handler.Creates a new Readline instance with the specified edit mode and in-memory history.Readline(EditMode editMode, History history, CompletionHandler<?> completionHandler) Creates a new Readline instance with the specified edit mode, history, and completion handler. -
Method Summary
Modifier and TypeMethodDescriptionprotected InputProcessorReturns the current input processor.voidreadline(ReadlineRequest request) Reads a line of input using aReadlineRequestthat encapsulates all parameters.voidReads a line of input from the connection with a string prompt.voidreadline(org.aesh.terminal.Connection conn, String prompt, Consumer<String> requestHandler, List<org.aesh.readline.completion.Completion> completions) Reads a line of input from the connection with a string prompt and completions.voidreadline(org.aesh.terminal.Connection conn, org.aesh.readline.prompt.Prompt prompt, Consumer<String> requestHandler) Reads a line of input from the connection with a Prompt object.voidreadline(org.aesh.terminal.Connection conn, org.aesh.readline.prompt.Prompt prompt, Consumer<String> requestHandler, List<org.aesh.readline.completion.Completion> completions) Reads a line of input from the connection with a Prompt object and completions.voidsetSuggestionProvider(org.aesh.readline.suggestion.SuggestionProvider provider) Sets the suggestion provider for inline ghost text.
-
Constructor Details
-
Readline
public Readline()Creates a new Readline instance with default edit mode, in-memory history, and simple completion handler. -
Readline
Creates a new Readline instance with the specified edit mode and in-memory history.- Parameters:
editMode- the edit mode to use (e.g., Emacs or Vi mode)
-
Readline
Creates a new Readline instance with the specified edit mode, history, and completion handler.- Parameters:
editMode- the edit mode to use (e.g., Emacs or Vi mode)history- the history implementation to use for command historycompletionHandler- the completion handler for tab completion, or null for default
-
-
Method Details
-
setSuggestionProvider
public void setSuggestionProvider(org.aesh.readline.suggestion.SuggestionProvider provider) Sets the suggestion provider for inline ghost text.- Parameters:
provider- the suggestion provider
-
getInputProcessor
Returns the current input processor.- Returns:
- the input processor, or null if not currently reading input
-
readline
public void readline(org.aesh.terminal.Connection conn, String prompt, Consumer<String> requestHandler) Reads a line of input from the connection with a string prompt.- Parameters:
conn- the terminal connection to read fromprompt- the prompt string to displayrequestHandler- the callback to receive the completed input line
-
readline
public void readline(org.aesh.terminal.Connection conn, String prompt, Consumer<String> requestHandler, List<org.aesh.readline.completion.Completion> completions) Reads a line of input from the connection with a string prompt and completions.- Parameters:
conn- the terminal connection to read fromprompt- the prompt string to displayrequestHandler- the callback to receive the completed input linecompletions- the list of completions for tab completion
-
readline
public void readline(org.aesh.terminal.Connection conn, org.aesh.readline.prompt.Prompt prompt, Consumer<String> requestHandler) Reads a line of input from the connection with a Prompt object.- Parameters:
conn- the terminal connection to read fromprompt- the prompt to displayrequestHandler- the callback to receive the completed input line
-
readline
public void readline(org.aesh.terminal.Connection conn, org.aesh.readline.prompt.Prompt prompt, Consumer<String> requestHandler, List<org.aesh.readline.completion.Completion> completions) Reads a line of input from the connection with a Prompt object and completions.- Parameters:
conn- the terminal connection to read fromprompt- the prompt to displayrequestHandler- the callback to receive the completed input linecompletions- the list of completions for tab completion
-
readline
Reads a line of input using aReadlineRequestthat encapsulates all parameters. This is the preferred way to invoke readline when optional parameters are needed.Example usage:
ReadlineRequest request = ReadlineRequest.builder() .connection(conn) .prompt(new Prompt("$ ")) .requestHandler(line -> System.out.println("Got: " + line)) .completions(myCompletions) .history(myHistory) .build(); readline.readline(request);- Parameters:
request- the readline request containing all parameters- Throws:
IllegalStateException- if already reading a line
-