Package org.elasticsearch.cli
Class Terminal
- java.lang.Object
-
- org.elasticsearch.cli.Terminal
-
public abstract class Terminal extends java.lang.Object
A Terminal wraps access to reading input and writing output for a cli. The available methods are similar to those ofConsole
, 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 theTerminal.Verbosity
of the terminal, which allowsprintln(Verbosity,String)
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 Classes Modifier and Type Class Description static class
Terminal.Verbosity
Defines the available verbosity levels of messages to be printed.
-
Constructor Summary
Constructors Modifier Constructor Description protected
Terminal(java.lang.String lineSeparator)
-
Method Summary
Modifier and Type Method Description void
errorPrint(Terminal.Verbosity verbosity, java.lang.String msg)
Prints a line to the terminal's standard error atTerminal.Verbosity.NORMAL
verbosity level, without a newline.void
errorPrintln(java.lang.String msg)
Prints a line to the terminal's standard error atTerminal.Verbosity.NORMAL
verbosity level.void
errorPrintln(Terminal.Verbosity verbosity, java.lang.String msg)
Prints a line to the terminal's standard error atverbosity
level.java.io.PrintWriter
getErrorWriter()
Returns a Writer which can be used to write to the terminal directly using standard error.abstract java.io.PrintWriter
getWriter()
Returns a Writer which can be used to write to the terminal directly using standard output.boolean
isPrintable(Terminal.Verbosity verbosity)
Checks if is enoughverbosity
level to be printedvoid
print(Terminal.Verbosity verbosity, java.lang.String msg)
Prints message to the terminal's standard output atverbosity
level, without a newline.void
println(java.lang.String msg)
Prints a line to the terminal atTerminal.Verbosity.NORMAL
verbosity level.void
println(Terminal.Verbosity verbosity, java.lang.String msg)
Prints a line to the terminal atverbosity
level.boolean
promptYesNo(java.lang.String prompt, boolean defaultYes)
Prompt for a yes or no answer from the user.abstract char[]
readSecret(java.lang.String prompt)
Reads password text from the terminal input.abstract java.lang.String
readText(java.lang.String prompt)
Reads clear text from the terminal input.void
setVerbosity(Terminal.Verbosity verbosity)
Sets the verbosity of the terminal.
-
-
-
Field Detail
-
DEFAULT
public static final Terminal DEFAULT
The default terminal implementation, which will be a console if available, or stdout/stderr if not.
-
-
Method Detail
-
setVerbosity
public void setVerbosity(Terminal.Verbosity verbosity)
Sets the verbosity of the terminal.
-
readText
public abstract java.lang.String readText(java.lang.String prompt)
Reads clear text from the terminal input. SeeConsole.readLine()
.
-
readSecret
public abstract char[] readSecret(java.lang.String prompt)
Reads password text from the terminal input. SeeConsole.readPassword()
}.
-
getWriter
public abstract java.io.PrintWriter getWriter()
Returns a Writer which can be used to write to the terminal directly using standard output.
-
getErrorWriter
public java.io.PrintWriter getErrorWriter()
Returns a Writer which can be used to write to the terminal directly using standard error.
-
println
public final void println(java.lang.String msg)
Prints a line to the terminal atTerminal.Verbosity.NORMAL
verbosity level.
-
println
public final void println(Terminal.Verbosity verbosity, java.lang.String msg)
Prints a line to the terminal atverbosity
level.
-
print
public final void print(Terminal.Verbosity verbosity, java.lang.String msg)
Prints message to the terminal's standard output atverbosity
level, without a newline.
-
errorPrint
public final void errorPrint(Terminal.Verbosity verbosity, java.lang.String msg)
Prints a line to the terminal's standard error atTerminal.Verbosity.NORMAL
verbosity level, without a newline.
-
errorPrintln
public final void errorPrintln(java.lang.String msg)
Prints a line to the terminal's standard error atTerminal.Verbosity.NORMAL
verbosity level.
-
errorPrintln
public final void errorPrintln(Terminal.Verbosity verbosity, java.lang.String msg)
Prints a line to the terminal's standard error atverbosity
level.
-
isPrintable
public final boolean isPrintable(Terminal.Verbosity verbosity)
Checks if is enoughverbosity
level to be printed
-
promptYesNo
public final boolean promptYesNo(java.lang.String prompt, boolean defaultYes)
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.
-
-