Class AbstractWindowsTerminal<Console>

java.lang.Object
org.jline.terminal.impl.AbstractTerminal
org.jline.terminal.impl.AbstractWindowsTerminal<Console>
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable, TerminalExt, Terminal
Direct Known Subclasses:
JansiWinSysTerminal, JnaWinSysTerminal, NativeWinSysTerminalPREVIEW, 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 Details

  • Constructor Details

  • Method Details

    • handle

      Description copied from interface: Terminal
      Registers a handler for the given Terminal.Signal.

      Note that the JVM does not easily allow catching the Terminal.Signal.QUIT signal, which causes a thread dump to be displayed. This signal is mainly used when connecting through an SSH socket to a virtual terminal.

      Specified by:
      handle in interface Terminal
      Overrides:
      handle in class AbstractTerminal
      Parameters:
      signal - the signal to register a handler for
      handler - the handler
      Returns:
      the previous signal handler
    • 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 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 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:
    • output

      public 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:
    • 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 IOException
      Overrides:
      doClose in class AbstractTerminal
      Throws:
      IOException
    • processKeyEvent

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

      protected String getEscapeSequence(short keyCode, int keyState)
    • getRawSequence

      protected String getRawSequence(InfoCmp.Capability cap)
    • hasFocusSupport

      public boolean hasFocusSupport()
      Description copied from interface: Terminal
      Returns true if the terminal has support for focus tracking.
      Specified by:
      hasFocusSupport in interface Terminal
      Overrides:
      hasFocusSupport in class AbstractTerminal
      Returns:
      whether focus tracking is supported by the terminal
      See Also:
    • 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
    • canPauseResume

      public boolean canPauseResume()
      Description copied from interface: Terminal
      Whether this terminal supports Terminal.pause() and Terminal.resume() calls.
      Specified by:
      canPauseResume in interface Terminal
      Overrides:
      canPauseResume in class AbstractTerminal
      Returns:
      whether this terminal supports Terminal.pause() and Terminal.resume() calls.
      See Also:
    • pause

      public void pause()
      Description copied from interface: Terminal
      Stop reading the input stream.
      Specified by:
      pause in interface Terminal
      Overrides:
      pause in class AbstractTerminal
      See Also:
    • pause

      public void pause(boolean wait) throws 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:
      InterruptedException - if the call has been interrupted
    • resume

      public void resume()
      Description copied from interface: Terminal
      Resume reading the input stream.
      Specified by:
      resume in interface Terminal
      Overrides:
      resume in class AbstractTerminal
      See Also:
    • 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:
    • pump

      protected void pump()
    • processInputChar

      public void processInputChar(char c) throws IOException
      Throws:
      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 IOException
      Read a single input event from the input buffer and process it.
      Returns:
      true if new input was generated from the event
      Throws:
      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.
    • getSystemStream

      public SystemStream getSystemStream()
      Description copied from interface: TerminalExt
      The underlying system stream, may be SystemStream.Output, SystemStream.Error, or null if this terminal is not bound to a system stream.