java.lang.Object
org.elasticsearch.cli.Terminal
A Terminal wraps access to reading input and writing output for a cli.
 The available methods are similar to those of 
Console, with the ability
 to read either normal text or a password, and the ability to print a line
 of text. Printing is also gated by the Terminal.Verbosity of the terminal,
 which allows println(Verbosity,CharSequence) calls which act like a logger,
 only actually printing if the verbosity level of the terminal is above
 the verbosity of the message.- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic enumDefines the available verbosity levels of messages to be printed.
- 
Field SummaryFields
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedTerminal(Reader reader, PrintWriter outWriter, PrintWriter errWriter) Constructs a terminal instance.
- 
Method SummaryModifier and TypeMethodDescriptionfinal voiderrorPrint(Terminal.Verbosity verbosity, String msg) Prints a line to the terminal's standard error atTerminal.Verbosity.NORMALverbosity level, without a newline.final voiderrorPrintln(String msg) Prints a line to the terminal's standard error atTerminal.Verbosity.NORMALverbosity level.final voiderrorPrintln(Terminal.Verbosity verbosity, String msg) Prints a line to the terminal's standard error atverbositylevel.final voidflush()Flush the outputs of this terminal.final PrintWriterReturns a Writer which can be used to write to the terminal directly using standard error.Returns an InputStream which can be used to read from the terminal directly using standard input.Returns an OutputStream which can be used to write to the terminal directly using standard output.final ReaderReturns a Reader which can be used to read directly from the terminal using standard input.Return the current verbosity level of this terminal.final PrintWriterReturns a Writer which can be used to write to the terminal directly using standard output.booleanIndicates whether this terminal is for a headless system i.e.final booleanisPrintable(Terminal.Verbosity verbosity) Checks if is enoughverbositylevel to be printedprotected voidprint(Terminal.Verbosity verbosity, PrintWriter writer, CharSequence msg, boolean newline) Prints message to the terminal atverbositylevel.final voidprint(Terminal.Verbosity verbosity, String msg) Prints message to the terminal's standard output atverbositylevel, without a newline.final voidprintln(CharSequence msg) Prints a line to the terminal atTerminal.Verbosity.NORMALverbosity level.final voidprintln(Terminal.Verbosity verbosity, CharSequence msg) Prints a line to the terminal atverbositylevel.final booleanpromptYesNo(String prompt, boolean defaultYes) Prompt for a yes or no answer from the user.static char[]readLineToCharArray(Reader reader) Read from the reader until we find a newline.char[]readSecret(String prompt) Reads password text from the terminal input.Reads clear text from the terminal input.voidsetVerbosity(Terminal.Verbosity verbosity) Sets the verbosity of the terminal.
- 
Field Details- 
DEFAULTThe default terminal implementation, which will be a console if available, or stdout/stderr if not.
 
- 
- 
Constructor Details- 
TerminalConstructs a terminal instance.- Parameters:
- reader- A character-based reader over the input of this terminal
- outWriter- A character-based writer for the output of this terminal
- errWriter- A character-based writer for the error stream of this terminal
 
 
- 
- 
Method Details- 
setVerbositySets the verbosity of the terminal.Defaults to Terminal.Verbosity.NORMAL.
- 
getVerbosityReturn the current verbosity level of this terminal.
- 
readTextReads clear text from the terminal input. SeeConsole.readLine().
- 
readSecretReads password text from the terminal input. SeeConsole.readPassword()}.
- 
getReaderReturns a Reader which can be used to read directly from the terminal using standard input.
- 
getWriterReturns a Writer which can be used to write to the terminal directly using standard output.
- 
getErrorWriterReturns a Writer which can be used to write to the terminal directly using standard error.
- 
getInputStreamReturns an InputStream which can be used to read from the terminal directly using standard input.May return nullif this Terminal is not capable of binary input. This corresponds with the underlying stream of bytes read byreader.
- 
getOutputStreamReturns an OutputStream which can be used to write to the terminal directly using standard output.May return nullif this Terminal is not capable of binary output. This corresponds with the underlying stream of bytes written to bygetWriter().
- 
printlnPrints a line to the terminal atTerminal.Verbosity.NORMALverbosity level.
- 
printlnPrints a line to the terminal atverbositylevel.
- 
printPrints message to the terminal's standard output atverbositylevel, without a newline.
- 
printprotected void print(Terminal.Verbosity verbosity, PrintWriter writer, CharSequence msg, boolean newline) Prints message to the terminal atverbositylevel. Subclasses may override if the writers are not implemented.
- 
errorPrintPrints a line to the terminal's standard error atTerminal.Verbosity.NORMALverbosity level, without a newline.
- 
errorPrintlnPrints a line to the terminal's standard error atTerminal.Verbosity.NORMALverbosity level.
- 
errorPrintlnPrints a line to the terminal's standard error atverbositylevel.
- 
isPrintableChecks if is enoughverbositylevel to be printed
- 
promptYesNoPrompt for a yes or no answer from the user. This method will loop until 'y' or 'n' (or the default empty value) is entered.
- 
readLineToCharArrayRead from the reader until we find a newline. If that newline character is immediately preceded by a carriage return, we have a Windows-style newline, so we discard the carriage return as well as the newline.
- 
flushpublic final void flush()Flush the outputs of this terminal.
- 
isHeadlesspublic boolean isHeadless()Indicates whether this terminal is for a headless system i.e. is not interactive. If an instances answersfalse, interactive operations can be attempted, but it is not guaranteed that they will succeed.- Returns:
- if this terminal is headless.
 
 
-