Package org.elasticsearch.cli
Class Terminal
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 Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumDefines the available verbosity levels of messages to be printed. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier 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.voidflush()Returns a Writer which can be used to write to the terminal directly using standard error.abstract OutputStreamReturns an OutputStream which can be used to write to the terminal directly using standard output.abstract 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 printedfinal voidprint(Terminal.Verbosity verbosity, String msg) Prints message to the terminal's standard output atverbositylevel, without a newline.protected voidprint(Terminal.Verbosity verbosity, String msg, boolean isError) Prints message to the terminal 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, int maxLength) Read from the reader until we find a newline.abstract char[]readSecret(String prompt) Reads password text from the terminal input.char[]readSecret(String prompt, int maxLength) Read password text form terminal input up to a maximum length.abstract StringReads clear text from the terminal input.voidsetVerbosity(Terminal.Verbosity verbosity) Sets the verbosity of the terminal.
-
Field Details
-
DEFAULT
The default terminal implementation, which will be a console if available, or stdout/stderr if not.
-
-
Constructor Details
-
Terminal
-
-
Method Details
-
setVerbosity
Sets the verbosity of the terminal. -
readText
Reads clear text from the terminal input. SeeConsole.readLine(). -
readSecret
Reads password text from the terminal input. SeeConsole.readPassword()}. -
readSecret
Read password text form terminal input up to a maximum length. -
getWriter
Returns a Writer which can be used to write to the terminal directly using standard output. -
getOutputStream
Returns an OutputStream which can be used to write to the terminal directly using standard output. May returnnullif this Terminal is not capable of binary output -
getErrorWriter
Returns a Writer which can be used to write to the terminal directly using standard error. -
println
Prints a line to the terminal atTerminal.Verbosity.NORMALverbosity level. -
println
Prints a line to the terminal atverbositylevel. -
print
Prints message to the terminal's standard output atverbositylevel, without a newline. -
print
Prints message to the terminal atverbositylevel, without a newline. -
errorPrint
Prints a line to the terminal's standard error atTerminal.Verbosity.NORMALverbosity level, without a newline. -
errorPrintln
Prints a line to the terminal's standard error atTerminal.Verbosity.NORMALverbosity level. -
errorPrintln
Prints a line to the terminal's standard error atverbositylevel. -
isPrintable
Checks if is enoughverbositylevel to be printed -
promptYesNo
Prompt for a yes or no answer from the user. This method will loop until 'y' or 'n' (or the default empty value) is entered. -
readLineToCharArray
Read 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. -
flush
public void flush() -
isHeadless
public 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.
-