Class AbstractWindowsTerminal<Console>

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable, TerminalExt, Terminal
    Direct Known Subclasses:
    NativeWinSysTerminal

    public abstract class AbstractWindowsTerminal<Console>
    extends AbstractTerminal
    The AbstractWindowsTerminal is used as the base class for windows terminal. Due to windows limitations, mostly the missing support for ansi sequences, the only way to create a correct terminal is to use the windows api to set character attributes, move the cursor, erasing, etc... UTF-8 support is also lacking in windows and the code page supposed to emulate UTF-8 is a bit broken. In order to work around this broken code page, windows api WriteConsoleW is used directly. This means that the writer() becomes the primary output, while the output() is bridged to the writer() using a WriterOutputStream wrapper.
    • Field Detail

      • TYPE_WINDOWS_256_COLOR

        public static final java.lang.String TYPE_WINDOWS_256_COLOR
        See Also:
        Constant Field Values
      • TYPE_WINDOWS_CONEMU

        public static final java.lang.String TYPE_WINDOWS_CONEMU
        See Also:
        Constant Field Values
      • TYPE_WINDOWS_VTP

        public static final java.lang.String TYPE_WINDOWS_VTP
        See Also:
        Constant Field Values
      • ENABLE_VIRTUAL_TERMINAL_PROCESSING

        public static final int ENABLE_VIRTUAL_TERMINAL_PROCESSING
        See Also:
        Constant Field Values
      • ENABLE_PROCESSED_INPUT

        protected static final int ENABLE_PROCESSED_INPUT
        See Also:
        Constant Field Values
      • ENABLE_QUICK_EDIT_MODE

        protected static final int ENABLE_QUICK_EDIT_MODE
        See Also:
        Constant Field Values
      • ENABLE_EXTENDED_FLAGS

        protected static final int ENABLE_EXTENDED_FLAGS
        See Also:
        Constant Field Values
      • slaveInputPipe

        protected final java.io.Writer slaveInputPipe
      • output

        protected final java.io.OutputStream output
      • writer

        protected final java.io.PrintWriter writer
      • nativeHandlers

        protected final java.util.Map<Terminal.Signal,​java.lang.Object> nativeHandlers
      • attributes

        protected final Attributes attributes
      • inConsole

        protected final Console inConsole
      • outConsole

        protected final Console outConsole
      • originalInConsoleMode

        protected final int originalInConsoleMode
      • originalOutConsoleMode

        protected final int originalOutConsoleMode
      • lock

        protected final java.lang.Object lock
      • paused

        protected boolean paused
      • pump

        protected java.lang.Thread pump
      • focusTracking

        protected boolean focusTracking
      • skipNextLf

        protected boolean skipNextLf
    • Constructor Detail

      • AbstractWindowsTerminal

        public AbstractWindowsTerminal​(TerminalProvider provider,
                                       SystemStream systemStream,
                                       java.io.Writer writer,
                                       java.lang.String name,
                                       java.lang.String type,
                                       java.nio.charset.Charset encoding,
                                       boolean nativeSignals,
                                       Terminal.SignalHandler signalHandler,
                                       Console inConsole,
                                       int inConsoleMode,
                                       Console outConsole,
                                       int outConsoleMode)
                                throws java.io.IOException
        Throws:
        java.io.IOException
    • Method Detail

      • reader

        public NonBlockingReader reader()
        Description copied from interface: Terminal
        Retrieve the Reader for this terminal. This is the standard way to read input from this terminal. The reader is non blocking.
        Returns:
        The non blocking reader
      • writer

        public java.io.PrintWriter writer()
        Description copied from interface: Terminal
        Retrieve the Writer for this terminal. This is the standard way to write to this terminal.
        Returns:
        The writer
      • input

        public java.io.InputStream input()
        Description copied from interface: Terminal
        Retrieve the input stream for this terminal. In some rare cases, there may be a need to access the terminal input stream directly. In the usual cases, use the Terminal.reader() instead.
        Returns:
        The input stream
        See Also:
        Terminal.reader()
      • output

        public java.io.OutputStream output()
        Description copied from interface: Terminal
        Retrieve the output stream for this terminal. In some rare cases, there may be a need to access the terminal output stream directly. In the usual cases, use the Terminal.writer() instead.
        Returns:
        The output stream
        See Also:
        Terminal.writer()
      • getAttributes

        public Attributes getAttributes()
        Description copied from interface: Terminal
        Returns the terminal attributes. The returned object can be safely modified further used in a call to Terminal.setAttributes(Attributes).
        Returns:
        the terminal attributes.
      • setAttributes

        public void setAttributes​(Attributes attr)
        Description copied from interface: Terminal
        Set the terminal attributes. The terminal will perform a copy of the given attributes.
        Parameters:
        attr - the new attributes
      • updateConsoleMode

        protected void updateConsoleMode()
      • ctrl

        protected int ctrl​(char key)
      • setSize

        public void setSize​(Size size)
      • doClose

        protected void doClose()
                        throws java.io.IOException
        Overrides:
        doClose in class AbstractTerminal
        Throws:
        java.io.IOException
      • processKeyEvent

        protected void processKeyEvent​(boolean isKeyDown,
                                       short virtualKeyCode,
                                       char ch,
                                       int controlKeyState)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • getEscapeSequence

        protected java.lang.String getEscapeSequence​(short keyCode,
                                                     int keyState)
      • trackFocus

        public boolean trackFocus​(boolean tracking)
        Description copied from interface: Terminal
        Enable or disable focus tracking mode. When focus tracking has been activated, each time the terminal grabs the focus, the string "\33[I" will be sent to the input stream and each time the focus is lost, the string "\33[O" will be sent to the input stream.
        Specified by:
        trackFocus in interface Terminal
        Overrides:
        trackFocus in class AbstractTerminal
        Parameters:
        tracking - whether the focus tracking mode should be enabled or not
        Returns:
        true if focus tracking is supported
      • pause

        public void pause​(boolean wait)
                   throws java.lang.InterruptedException
        Description copied from interface: Terminal
        Stop reading the input stream and optionally wait for the underlying threads to finish.
        Specified by:
        pause in interface Terminal
        Overrides:
        pause in class AbstractTerminal
        Parameters:
        wait - true to wait until the terminal is actually paused
        Throws:
        java.lang.InterruptedException - if the call has been interrupted
      • paused

        public boolean paused()
        Description copied from interface: Terminal
        Check whether the terminal is currently reading the input stream or not. In order to process signal as quickly as possible, the terminal need to read the input stream and buffer it internally so that it can detect specific characters in the input stream (Ctrl+C, Ctrl+D, etc...) and raise the appropriate signals. However, there are some cases where this processing should be disabled, for example when handing the terminal control to a subprocess.
        Specified by:
        paused in interface Terminal
        Overrides:
        paused in class AbstractTerminal
        Returns:
        whether the terminal is currently reading the input stream or not
        See Also:
        Terminal.pause(), Terminal.resume()
      • pump

        protected void pump()
      • processInputChar

        public void processInputChar​(char c)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • trackMouse

        public boolean trackMouse​(Terminal.MouseTracking tracking)
        Description copied from interface: Terminal
        Change the mouse tracking mouse. To start mouse tracking, this method must be called with a valid mouse tracking mode. Mouse events will be reported by writing the InfoCmp.Capability.key_mouse to the input stream. When this character sequence is detected, the Terminal.readMouseEvent() method can be called to actually read the corresponding mouse event.
        Specified by:
        trackMouse in interface Terminal
        Overrides:
        trackMouse in class AbstractTerminal
        Parameters:
        tracking - the mouse tracking mode
        Returns:
        true if mouse tracking is supported
      • getConsoleMode

        protected abstract int getConsoleMode​(Console console)
      • setConsoleMode

        protected abstract void setConsoleMode​(Console console,
                                               int mode)
      • processConsoleInput

        protected abstract boolean processConsoleInput()
                                                throws java.io.IOException
        Read a single input event from the input buffer and process it.
        Returns:
        true if new input was generated from the event
        Throws:
        java.io.IOException - if anything wrong happens
      • getProvider

        public TerminalProvider getProvider()
        Description copied from interface: TerminalExt
        Returns the TerminalProvider that created this terminal or null if the terminal was created with no provider.