Package jline

Class WindowsTerminal

  • All Implemented Interfaces:
    Terminal
    Direct Known Subclasses:
    AnsiWindowsTerminal

    public class WindowsTerminal
    extends TerminalSupport
    Terminal implementation for Microsoft Windows. Terminal initialization in init() 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 wrapInIfNeeded(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.

    Since:
    2.0
    • Field Detail

      • DIRECT_CONSOLE

        public static final java.lang.String DIRECT_CONSOLE
      • ANSI

        public static final java.lang.String ANSI
      • directConsole

        private boolean directConsole
      • originalMode

        private int originalMode
    • Constructor Detail

      • WindowsTerminal

        public WindowsTerminal()
                        throws java.lang.Exception
        Throws:
        java.lang.Exception
    • Method Detail

      • init

        public void init()
                  throws java.lang.Exception
        Specified by:
        init in interface Terminal
        Overrides:
        init in class TerminalSupport
        Throws:
        java.lang.Exception
      • restore

        public void restore()
                     throws java.lang.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.
        Specified by:
        restore in interface Terminal
        Overrides:
        restore in class TerminalSupport
        Throws:
        java.lang.Exception
      • setDirectConsole

        public void setDirectConsole​(boolean flag)
        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.
      • wrapInIfNeeded

        public java.io.InputStream wrapInIfNeeded​(java.io.InputStream in)
                                           throws java.io.IOException
        Description copied from interface: Terminal
        When using native support, return the InputStream to use for reading characters else return the input stream passed as a parameter.
        Specified by:
        wrapInIfNeeded in interface Terminal
        Overrides:
        wrapInIfNeeded in class TerminalSupport
        Throws:
        java.io.IOException
      • isSystemIn

        protected boolean isSystemIn​(java.io.InputStream in)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • getConsoleMode

        private static int getConsoleMode()
      • setConsoleMode

        private static void setConsoleMode​(int mode)
      • readConsoleInput

        private byte[] readConsoleInput()
      • getConsoleOutputCodepage

        private static int getConsoleOutputCodepage()
      • getWindowsTerminalWidth

        private static int getWindowsTerminalWidth()
      • getWindowsTerminalHeight

        private static int getWindowsTerminalHeight()