Package jline

Class UnixTerminal

java.lang.Object
jline.Terminal
jline.UnixTerminal
All Implemented Interfaces:
ConsoleOperations

public class UnixTerminal extends Terminal

Terminal that is used for unix platforms. Terminal initialization is handled by issuing the stty command against the /dev/tty file to disable character echoing and enable character input. All known unix systems (including Linux and Macintosh OS X) support the stty), so this implementation should work for an reasonable POSIX system.

Author:
Marc Prud'hommeaux, Updates Dale Kemp 2005-12-03
  • Field Details

  • Constructor Details

    • UnixTerminal

      public UnixTerminal()
  • Method Details

    • checkBackspace

      protected void checkBackspace()
    • initializeTerminal

      public void initializeTerminal() throws IOException, InterruptedException
      Remove line-buffered input by invoking "stty -icanon min 1" against the current terminal.
      Specified by:
      initializeTerminal in class Terminal
      Throws:
      IOException
      InterruptedException
    • restoreTerminal

      public void restoreTerminal() throws Exception
      Restore the original terminal configuration, which can be used when shutting down the console reader. The ConsoleReader cannot be used after calling this method.
      Throws:
      Exception
    • readVirtualKey

      public int readVirtualKey(InputStream in) throws IOException
      Description copied from class: Terminal
      Reads a virtual key from the console. Typically, this will just be the raw character that was entered, but in some cases, multiple input keys will need to be translated into a single virtual key.
      Overrides:
      readVirtualKey in class Terminal
      Parameters:
      in - the InputStream to read from
      Returns:
      the virtual key (e.g., ConsoleOperations#VK_UP)
      Throws:
      IOException
    • isSupported

      public boolean isSupported()
      Description copied from class: Terminal
      Returns true if this terminal is capable of initializing the terminal to use jline.
      Specified by:
      isSupported in class Terminal
    • getEcho

      public boolean getEcho()
      Description copied from class: Terminal
      Returns true if the terminal will echo all characters type.
      Specified by:
      getEcho in class Terminal
    • getTerminalWidth

      public int getTerminalWidth()
      Returns the value of "stty size" width param. Note: this method caches the value from the first time it is called in order to increase speed, which means that changing to size of the terminal will not be reflected in the console.
      Specified by:
      getTerminalWidth in class Terminal
    • getTerminalHeight

      public int getTerminalHeight()
      Returns the value of "stty size" height param. Note: this method caches the value from the first time it is called in order to increase speed, which means that changing to size of the terminal will not be reflected in the console.
      Specified by:
      getTerminalHeight in class Terminal
    • stty

      protected static String stty(String args) throws IOException, InterruptedException
      Execute the stty command with the specified arguments against the current active terminal.
      Throws:
      IOException
      InterruptedException
    • setSttyCommand

      public static void setSttyCommand(String cmd)
      The command to use to set the terminal options. Defaults to "stty", or the value of the system property "jline.sttyCommand".
    • getSttyCommand

      public static String getSttyCommand()
      The command to use to set the terminal options. Defaults to "stty", or the value of the system property "jline.sttyCommand".
    • isEchoEnabled

      public boolean isEchoEnabled()
      Description copied from class: Terminal
      Returns false if character echoing is disabled.
      Specified by:
      isEchoEnabled in class Terminal
    • enableEcho

      public void enableEcho()
      Description copied from class: Terminal
      Enable character echoing. This can be used to re-enable character if the ConsoleReader is no longer being used.
      Specified by:
      enableEcho in class Terminal
    • disableEcho

      public void disableEcho()
      Description copied from class: Terminal
      Disable character echoing. This can be used to manually re-enable character if the ConsoleReader has been disabled.
      Specified by:
      disableEcho in class Terminal