Class ECMA48

  • All Implemented Interfaces:
    java.lang.Runnable

    public class ECMA48
    extends java.lang.Object
    implements java.lang.Runnable
    This implements a complex ECMA-48/ISO 6429/ANSI X3.64 type console, including a scrollback buffer.

    It currently implements VT100, VT102, VT220, and XTERM with the following caveats:

    - The vttest scenario for VT220 8-bit controls (11.1.2.3) reports a failure with XTERM. This is due to vttest failing to decode the UTF-8 stream.

    - Smooth scrolling, printing, keyboard locking, keyboard leds, and tests from VT100 are not supported.

    - User-defined keys (DECUDK), downloadable fonts (DECDLD), and VT100/ANSI compatibility mode (DECSCL) from VT220 are not supported. (Also, because DECSCL is not supported, it will fail the last part of the vttest "Test of VT52 mode" if DeviceType is set to VT220.)

    - Numeric/application keys from the number pad are not supported because they are not exposed from the TKeypress API.

    - VT52 HOLD SCREEN mode is not supported.

    - In VT52 graphics mode, the 3/, 5/, and 7/ characters (fraction numerators) are not rendered correctly.

    - All data meant for the 'printer' (CSI Pc ? i) is discarded.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  ECMA48.DeviceType
      The emulator can emulate several kinds of terminals.
      static class  ECMA48.MouseProtocol
      XTERM mouse reporting protocols.
    • Constructor Summary

      Constructors 
      Constructor Description
      ECMA48​(ECMA48.DeviceType type, java.io.InputStream inputStream, java.io.OutputStream outputStream, TerminalListener terminalListener, Backend backend)
      Public constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addUserEvent​(TInputEvent event)
      Add a keyboard and mouse event from the user to the queue.
      TerminalState captureState()
      Obtain a snapshot of the terminal state.
      void close()
      Close the input and output streams and stop the reader thread.
      static java.lang.String deviceTypeLang​(ECMA48.DeviceType deviceType, java.lang.String baseLang)
      Return the proper LANG for this device type.
      static java.lang.String deviceTypeTerm​(ECMA48.DeviceType deviceType)
      Return the most commonly-used TERM environment variable for this device type.
      boolean isReading()
      See if the reader thread is still running.
      void onFocus()
      Let the application know this terminal gained focus, if it has enabled FOCUS_MOUSE_MODE.
      void onUnfocus()
      Let the application know this terminal lost focus, if it has enabled FOCUS_MOUSE_MODE.
      void run()
      Read function runs on a separate thread.
      void setHeight​(int height)
      Set the display height.
      void setScrollbackMax​(int scrollbackMax)
      Set the maximum number of lines for the scrollback buffer.
      void setTextHeight​(int textHeight)
      Set the height of a character cell in pixels.
      void setTextWidth​(int textWidth)
      Set the width of a character cell in pixels.
      void setWidth​(int width)
      Set the display width.
      boolean waitForOutput​(int millis)
      Wait for a period of time to get output from the launched process.
      void writeRemote​(java.lang.String str)
      Write a string directly to the remote side.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ECMA48

        public ECMA48​(ECMA48.DeviceType type,
                      java.io.InputStream inputStream,
                      java.io.OutputStream outputStream,
                      TerminalListener terminalListener,
                      Backend backend)
               throws java.io.UnsupportedEncodingException
        Public constructor.
        Parameters:
        type - one of the DeviceType constants to select VT100, VT102, VT220, or XTERM
        inputStream - an InputStream connected to the remote side. For type == XTERM, inputStream is converted to a Reader with UTF-8 encoding.
        outputStream - an OutputStream connected to the remote user. For type == XTERM, outputStream is converted to a Writer with UTF-8 encoding.
        terminalListener - a callback to the outer display, or null for default VT100 behavior
        backend - the backend that can obtain the correct background color
        Throws:
        java.io.UnsupportedEncodingException - if an exception is thrown when creating the InputStreamReader
    • Method Detail

      • run

        public final void run()
        Read function runs on a separate thread.
        Specified by:
        run in interface java.lang.Runnable
      • waitForOutput

        public boolean waitForOutput​(int millis)
        Wait for a period of time to get output from the launched process.
        Parameters:
        millis - millis to wait for, or 0 to wait forever
        Returns:
        true if the launched process has emitted something
      • addUserEvent

        public void addUserEvent​(TInputEvent event)
        Add a keyboard and mouse event from the user to the queue.
        Parameters:
        event - the input event to consume
      • captureState

        public TerminalState captureState()
        Obtain a snapshot of the terminal state.
        Returns:
        the terminal state that can be used by an external user interface
      • deviceTypeTerm

        public static java.lang.String deviceTypeTerm​(ECMA48.DeviceType deviceType)
        Return the most commonly-used TERM environment variable for this device type. Note that jexer.TTerminal pulls TERM from the System property jexer.TTerminal.TERM, rather than using on the value here.
        Parameters:
        deviceType - DeviceType.VT100, DeviceType, XTERM, etc.
        Returns:
        "vt100", "xterm", etc.
      • deviceTypeLang

        public static java.lang.String deviceTypeLang​(ECMA48.DeviceType deviceType,
                                                      java.lang.String baseLang)
        Return the proper LANG for this device type. Only XTERM devices know about UTF-8, the others are defined by their standard to be either 7-bit or 8-bit characters only.
        Parameters:
        deviceType - DeviceType.VT100, DeviceType, XTERM, etc.
        baseLang - a base language without UTF-8 flag such as "C" or "en_US"
        Returns:
        "en_US", "en_US.UTF-8", etc.
      • writeRemote

        public void writeRemote​(java.lang.String str)
        Write a string directly to the remote side.
        Parameters:
        str - string to send
      • close

        public final void close()
        Close the input and output streams and stop the reader thread. Note that it is safe to call this multiple times.
      • isReading

        public final boolean isReading()
        See if the reader thread is still running.
        Returns:
        if true, we are still connected to / reading from the remote side
      • setWidth

        public final void setWidth​(int width)
        Set the display width.
        Parameters:
        width - the new width
      • setHeight

        public final void setHeight​(int height)
        Set the display height.
        Parameters:
        height - the new height
      • setScrollbackMax

        public final void setScrollbackMax​(int scrollbackMax)
        Set the maximum number of lines for the scrollback buffer.
        Parameters:
        scrollbackMax - the maximum number of lines for the scrollback buffer
      • setTextWidth

        public void setTextWidth​(int textWidth)
        Set the width of a character cell in pixels.
        Parameters:
        textWidth - the width in pixels of a character cell
      • setTextHeight

        public void setTextHeight​(int textHeight)
        Set the height of a character cell in pixels.
        Parameters:
        textHeight - the height in pixels of a character cell
      • onFocus

        public void onFocus()
        Let the application know this terminal gained focus, if it has enabled FOCUS_MOUSE_MODE.
      • onUnfocus

        public void onUnfocus()
        Let the application know this terminal lost focus, if it has enabled FOCUS_MOUSE_MODE.