Enum Class Terminal

java.lang.Object
java.lang.Enum<Terminal>
org.refcodes.runtime.Terminal
All Implemented Interfaces:
Serializable, Comparable<Terminal>, Constable, org.refcodes.mixin.AliasAccessor

public enum Terminal extends Enum<Terminal> implements org.refcodes.mixin.AliasAccessor
Enumeration with the (relevant) terminals as well as interpolated terminal metrics.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    The Terminal.CharSetCapability defines three categories of character capabilities as observed on various platform.

    Nested classes/interfaces inherited from class java.lang.Enum

    Enum.EnumDesc<E extends Enum<E>>

    Nested classes/interfaces inherited from interface org.refcodes.mixin.AliasAccessor

    org.refcodes.mixin.AliasAccessor.AliasBuilder<B extends org.refcodes.mixin.AliasAccessor.AliasBuilder<B>>, org.refcodes.mixin.AliasAccessor.AliasMutator, org.refcodes.mixin.AliasAccessor.AliasProperty
  • Enum Constant Summary

    Enum Constants
    Enum Constant
    Description
    ansi: a terminal using the ANSI escape codes for color and formatting.
    cygwin: The cygwin terminal on Windows.
    gnome-terminal: the default terminal emulator for the GNOME desktop environment.
    konsole: the default terminal emulator for the KDE desktop environment.
    linux: the console terminal in a Linux system.
    rxvt:a terminal emulator for the X Window System.
    screen: a full-screen window manager that multiplexes a physical terminal between several processes.
    tmux: a terminal multiplexer that allows multiple terminals to be created and managed from a single console or SSH session.
    Unknown, not one of the others.
    vt100: a classic DEC terminal
    vt220: a popular terminal from Digital Equipment Corporation (DEC).
    xterm: a generic terminal emulator for the X Window System.
    xterm-256color: an extended version of xterm with support for 256 colors.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the alias by which this Terminal type is known.
    static String
    Determines the encoding of the system (system's console) in use as of System.out.
    static int
    Determines the height in characters of the system's terminal in use.
    static String
    Determines the operating system as of OperatingSystem.toOperatingSystem() and in case a OperatingSystem.WINDOWS is being detected, then \r\n" (CRLF) is returned, else "\n" (LF) is returned.
    static String
    Determines the current session's terminal in use.
    static int
    Determines the width in characters of the system's terminal in use.
    static boolean
    Determines whether ANSI escape sequences are supported by the terminal.
    static boolean
    Determines whether ANSI escape sequences are forced to be supported or not by REFCODES.ORG artifacts.
    static boolean
    isLineBreakRequired(int aRowWidth)
    Determines whether we need an explicit line-break for the given width on the current operating system and used terminal.
    Determines the Terminal.CharSetCapability of the current terminal session.
    static String
    toLineBreak(int aRowWidth)
    Uses isLineBreakRequired(int) to retrieve the character sequence required to suffix to a line in order to get a line break without risking any empty lines as of automatic line wrapping.
    static int
    Does some calculation to always return a sound console height (never returns -1).
    static int
    Does some calculation to always return a sound console width (never returns -1).
    static Terminal
    Determines the terminal your application is currently in:
    static Terminal
    Returns the enum constant of this class with the specified name.
    static Terminal[]
    Returns an array containing the constants of this enum class, in the order they are declared.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Enum Constant Details

    • XTERM

      public static final Terminal XTERM
      xterm: a generic terminal emulator for the X Window System.
    • CYGWIN

      public static final Terminal CYGWIN
      cygwin: The cygwin terminal on Windows.
    • VT100

      public static final Terminal VT100
      vt100: a classic DEC terminal
    • LINUX

      public static final Terminal LINUX
      linux: the console terminal in a Linux system.
    • RXVT

      public static final Terminal RXVT
      rxvt:a terminal emulator for the X Window System.
    • ANSI

      public static final Terminal ANSI
      ansi: a terminal using the ANSI escape codes for color and formatting.
    • XTERM_256COLOR

      public static final Terminal XTERM_256COLOR
      xterm-256color: an extended version of xterm with support for 256 colors.
    • VT220

      public static final Terminal VT220
      vt220: a popular terminal from Digital Equipment Corporation (DEC).
    • GNOME_TERMINAL

      public static final Terminal GNOME_TERMINAL
      gnome-terminal: the default terminal emulator for the GNOME desktop environment.
    • KONSOLE

      public static final Terminal KONSOLE
      konsole: the default terminal emulator for the KDE desktop environment.
    • SCREEN

      public static final Terminal SCREEN
      screen: a full-screen window manager that multiplexes a physical terminal between several processes.
    • TMUX

      public static final Terminal TMUX
      tmux: a terminal multiplexer that allows multiple terminals to be created and managed from a single console or SSH session.
    • UNKNOWN

      public static final Terminal UNKNOWN
      Unknown, not one of the others.
  • Method Details

    • values

      public static Terminal[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static Terminal valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • getAlias

      public String getAlias()
      Returns the alias by which this Terminal type is known.
      Specified by:
      getAlias in interface org.refcodes.mixin.AliasAccessor
      Returns:
      The according Terminal types alias.
    • getLineBreak

      public static String getLineBreak()
      Determines the operating system as of OperatingSystem.toOperatingSystem() and in case a OperatingSystem.WINDOWS is being detected, then \r\n" (CRLF) is returned, else "\n" (LF) is returned. Can be overridden with the SystemProperty.CONSOLE_LINE_BREAK (java -Dconsole.lineBreak=...) and the EnvironmentVariable.CONSOLE_LINE_BREAK ("export CONSOLE_LINE_BREAK=...).
      Returns:
      The operating system's specific line break; on Windows it is "\r\n" (CRLF) and on all other operating systems it is "\n" (LF).
    • getEncoding

      public static String getEncoding()
      Determines the encoding of the system (system's console) in use as of System.out.
      Returns:
      The encoding (of the console).
    • getHeight

      public static int getHeight()
      Determines the height in characters of the system's terminal in use.
      Returns:
      The height of the terminal in characters or -1 if the height cannot be determined.
    • getWidth

      public static int getWidth()
      Determines the width in characters of the system's terminal in use.
      Returns:
      The width of the terminal in characters or -1 if the width cannot be determined.
    • getTerminalSession

      public static String getTerminalSession()
      Determines the current session's terminal in use. Known terminal types can be retrieved via toTerminal().
      Returns:
      The current session's terminal in use.
    • isAnsiTerminal

      public static boolean isAnsiTerminal()
      Determines whether ANSI escape sequences are supported by the terminal.
      Returns:
      True in case ANSI escape sequences are supported, else false.
    • isAnsiTerminalPreferred

      public static boolean isAnsiTerminalPreferred()
      Determines whether ANSI escape sequences are forced to be supported or not by REFCODES.ORG artifacts. This overrules isAnsiTerminal() for the REFCODES.ORG artifacts. Various settings such as SystemProperty.CONSOLE_ANSI and (in this order) EnvironmentVariable.CONSOLE_ANSI overrule isAnsiTerminal().
      Returns:
      True in case ANSI escape sequences are forced to be used by REFCODES.ORG artifacts or not.
    • isLineBreakRequired

      public static boolean isLineBreakRequired(int aRowWidth)
      Determines whether we need an explicit line-break for the given width on the current operating system and used terminal. E.g. on "win.cmd" we must not use a line-break in case our line is a s long as the console's width. There are some more such cases which this method tries to take into consideration.
      Parameters:
      aRowWidth - The row width you want to use when printing out to a console.
      Returns:
      True in case you should use a line-break.
    • toLineBreak

      public static String toLineBreak(int aRowWidth)
      Uses isLineBreakRequired(int) to retrieve the character sequence required to suffix to a line in order to get a line break without risking any empty lines as of automatic line wrapping. Automatic line wrapping can happen on Windows environment when the console width is reached. A line break would cause a superfluous empty line (ugly).
      Parameters:
      aRowWidth - The row width you want to use when printing out to a console.
      Returns:
      The system's line break characters when a line break is emphasized or an empty string if no line break sequence is recommended.
    • toPreferredHeight

      public static int toPreferredHeight()
      Does some calculation to always return a sound console height (never returns -1). Anything in the REFCODES.ORG artifacts which is intended to print to the console uses this method to determine some heuristic best console height.
      Returns:
      A sound heuristic console height.
    • toPreferredWidth

      public static int toPreferredWidth()
      Does some calculation to always return a sound console width (never returns -1). Anything in the REFCODES.ORG artifacts which is intended to print to the console uses this method to determine some heuristic best console width.
      Returns:
      A sound heuristic console width.
    • toCharSetCapability

      public static Terminal.CharSetCapability toCharSetCapability()
      Determines the Terminal.CharSetCapability of the current terminal session. The Terminal.CharSetCapability is used to determine which characters to use when printing tables and boxes to the terminal (see the TableStyle class's toExecutionTableStyle method as well as the TextBoxGrid class's toExecutionTextBoxGrid() method.
      Returns:
      The Terminal.CharSetCapability determined at best knowledge.
    • toTerminal

      public static Terminal toTerminal()
      Determines the terminal your application is currently in:
      Returns:
      The Terminal being detected or UNKNOWN if detection was not possible.