Class Terminal

java.lang.Object
org.elasticsearch.cli.Terminal

public abstract class Terminal extends Object
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.
  • Field Details

    • DEFAULT

      public static final Terminal DEFAULT
      The default terminal implementation, which will be a console if available, or stdout/stderr if not.
  • Constructor Details

    • Terminal

      protected Terminal(String lineSeparator)
  • Method Details

    • setVerbosity

      public void setVerbosity(Terminal.Verbosity verbosity)
      Sets the verbosity of the terminal.
    • readText

      public abstract String readText(String prompt)
      Reads clear text from the terminal input. See Console.readLine().
    • readSecret

      public abstract char[] readSecret(String prompt)
      Reads password text from the terminal input. See Console.readPassword()}.
    • readSecret

      public char[] readSecret(String prompt, int maxLength)
      Read password text form terminal input up to a maximum length.
    • getWriter

      public abstract PrintWriter getWriter()
      Returns a Writer which can be used to write to the terminal directly using standard output.
    • getOutputStream

      @Nullable public abstract OutputStream getOutputStream()
      Returns an OutputStream which can be used to write to the terminal directly using standard output. May return null if this Terminal is not capable of binary output
    • getErrorWriter

      public PrintWriter getErrorWriter()
      Returns a Writer which can be used to write to the terminal directly using standard error.
    • println

      public final void println(CharSequence msg)
      Prints a line to the terminal at Terminal.Verbosity.NORMAL verbosity level.
    • println

      public final void println(Terminal.Verbosity verbosity, CharSequence msg)
      Prints a line to the terminal at verbosity level.
    • print

      public final void print(Terminal.Verbosity verbosity, String msg)
      Prints message to the terminal's standard output at verbosity level, without a newline.
    • print

      protected void print(Terminal.Verbosity verbosity, String msg, boolean isError)
      Prints message to the terminal at verbosity level, without a newline.
    • errorPrint

      public final void errorPrint(Terminal.Verbosity verbosity, String msg)
      Prints a line to the terminal's standard error at Terminal.Verbosity.NORMAL verbosity level, without a newline.
    • errorPrintln

      public final void errorPrintln(String msg)
      Prints a line to the terminal's standard error at Terminal.Verbosity.NORMAL verbosity level.
    • errorPrintln

      public final void errorPrintln(Terminal.Verbosity verbosity, String msg)
      Prints a line to the terminal's standard error at verbosity level.
    • isPrintable

      public final boolean isPrintable(Terminal.Verbosity verbosity)
      Checks if is enough verbosity level to be printed
    • promptYesNo

      public final boolean promptYesNo(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.
    • readLineToCharArray

      public static char[] readLineToCharArray(Reader reader, int maxLength)
      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 answers false, interactive operations can be attempted, but it is not guaranteed that they will succeed.
      Returns:
      if this terminal is headless.