Package jline

Class WindowsTerminal

  • All Implemented Interfaces:
    ConsoleOperations

    public class WindowsTerminal
    extends Terminal

    Terminal implementation for Microsoft Windows. Terminal initialization in initializeTerminal() is accomplished by extracting the jline_version.dll, saving it to the system temporary directoy (determined by the setting of the java.io.tmpdir System property), loading the library, and then calling the Win32 APIs SetConsoleMode and GetConsoleMode to disable character echoing.

    By default, the readCharacter(java.io.InputStream) method will attempt to test to see if the specified InputStream is System.in or a wrapper around FileDescriptor.in, and if so, will bypass the character reading to directly invoke the readc() method in the JNI library. This is so the class can read special keys (like arrow keys) which are otherwise inaccessible via the System.in stream. Using JNI reading can be bypassed by setting the jline.WindowsTerminal.directConsole system property to false.

    Author:
    Marc Prud'hommeaux
    • Field Detail

      • SPECIAL_KEY_INDICATOR

        public static final int SPECIAL_KEY_INDICATOR
        On windows terminals, this character indicates that a 'special' key has been pressed. This means that a key such as an arrow key, or delete, or home, etc. will be indicated by the next character.
        See Also:
        Constant Field Values
      • LEFT_ARROW_KEY

        public static final int LEFT_ARROW_KEY
        When following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR, this character indicates an left arrow key press.
        See Also:
        Constant Field Values
      • RIGHT_ARROW_KEY

        public static final int RIGHT_ARROW_KEY
        When following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR this character indicates an right arrow key press.
        See Also:
        Constant Field Values
      • UP_ARROW_KEY

        public static final int UP_ARROW_KEY
        When following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR this character indicates an up arrow key press.
        See Also:
        Constant Field Values
      • DOWN_ARROW_KEY

        public static final int DOWN_ARROW_KEY
        When following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR this character indicates an down arrow key press.
        See Also:
        Constant Field Values
      • DELETE_KEY

        public static final int DELETE_KEY
        When following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR this character indicates that the delete key was pressed.
        See Also:
        Constant Field Values
      • HOME_KEY

        public static final int HOME_KEY
        When following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR this character indicates that the home key was pressed.
        See Also:
        Constant Field Values
      • END_KEY

        public static final char END_KEY
        When following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR this character indicates that the end key was pressed.
        See Also:
        Constant Field Values
      • PAGE_UP_KEY

        public static final char PAGE_UP_KEY
        When following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR this character indicates that the page up key was pressed.
        See Also:
        Constant Field Values
      • PAGE_DOWN_KEY

        public static final char PAGE_DOWN_KEY
        When following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR this character indicates that the page down key was pressed.
        See Also:
        Constant Field Values
      • INSERT_KEY

        public static final char INSERT_KEY
        When following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR this character indicates that the insert key was pressed.
        See Also:
        Constant Field Values
      • ESCAPE_KEY

        public static final char ESCAPE_KEY
        When following the SPECIAL_KEY_INDICATOR or NUMPAD_KEY_INDICATOR, this character indicates that the escape key was pressed.
        See Also:
        Constant Field Values
    • Method Detail

      • readCharacter

        public int readCharacter​(java.io.InputStream in)
                          throws java.io.IOException
        Description copied from class: Terminal
        Read a single character from the input stream. This might enable a terminal implementation to better handle nuances of the console.
        Overrides:
        readCharacter in class Terminal
        Throws:
        java.io.IOException
      • initializeTerminal

        public void initializeTerminal()
                                throws java.lang.Exception
        Description copied from class: Terminal
        Initialize any system settings that are required for the console to be able to handle input correctly, such as setting tabtop, buffered input, and character echo.
        Specified by:
        initializeTerminal in class Terminal
        Throws:
        java.lang.Exception
      • readVirtualKey

        public int readVirtualKey​(java.io.InputStream in)
                           throws java.io.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:
        java.io.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
      • setDirectConsole

        public void setDirectConsole​(java.lang.Boolean directConsole)
        Whether or not to allow the use of the JNI console interaction.
      • getDirectConsole

        public java.lang.Boolean getDirectConsole()
        Whether or not to allow the use of the JNI console interaction.
      • 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