Class HttpTtyConnection

java.lang.Object
org.aesh.terminal.AbstractConnection
org.aesh.terminal.http.HttpTtyConnection
All Implemented Interfaces:
Appendable, AutoCloseable, org.aesh.terminal.Connection

public abstract class HttpTtyConnection extends org.aesh.terminal.AbstractConnection
A connection to an http client, independent of the protocol, it could be straight WebSockets or SockJS, etc...

The incoming protocol is based on JSON messages with an "action" field:

init - Client capability reporting (sent on connect)

{
  "action": "init",
  "type": "xterm-256color",
  "colorDepth": "TRUE_COLOR",
  "features": ["UNICODE", "CLIPBOARD"],
  "cols": 80,
  "rows": 24,
  "userAgent": "Mozilla/5.0 ..."
}

read - User terminal input

{
  "action": "read",
  "data": "what the user typed"
}

resize - Terminal size change

{
  "action": "resize",
  "cols": 120,
  "rows": 40
}
Author:
Julien Viet, Matej Lazar
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final org.aesh.terminal.tty.Size
    Default terminal size (80 columns x 24 rows).

    Fields inherited from class org.aesh.terminal.AbstractConnection

    attributes, closeHandler, eventDecoder, reading, sizeHandler, stdout
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new HTTP TTY connection with default charset (UTF-8) and size (80x24).
    HttpTtyConnection(Charset charset, org.aesh.terminal.tty.Size size)
    Creates a new HTTP TTY connection with the specified charset and size.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    org.aesh.terminal.Device
    Returns the handler for terminal type events.
    boolean
    Returns whether the client has sent an init message.
    long
    Returns the timestamp of the last access to this connection.
    void
    void
    boolean
    put(org.aesh.terminal.tty.Capability capability, Object... params)
    void
    setAttributes(org.aesh.terminal.Attributes attr)
    void
    Sets the handler for terminal type events.
    org.aesh.terminal.tty.Size
    boolean
    protected abstract void
    write(byte[] buffer)
    Writes raw bytes to the underlying transport.
    void
    Processes an incoming JSON message from the client and writes it to the decoder.

    Methods inherited from class org.aesh.terminal.AbstractConnection

    attributes, closeHandler, focusHandler, getStatusMessages, mouseHandler, printAboveHandler, reading, registerStatusLine, setCloseHandler, setFocusHandler, setMouseHandler, setPrintAboveHandler, setSignalHandler, setSizeHandler, setStdinHandler, setThemeChangeHandler, signalHandler, sizeHandler, stdinHandler, stdoutHandler, terminal, themeChangeHandler

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.aesh.terminal.Connection

    append, append, append, asPrintWriter, asWriter, close, currentRegion, enterRawMode, isInteractive, peek, printAbove, setCurrentRegion, splitScreen, splitScreen, supportsNonBlockingRead, write
  • Field Details

    • DEFAULT_SIZE

      public static final org.aesh.terminal.tty.Size DEFAULT_SIZE
      Default terminal size (80 columns x 24 rows).
  • Constructor Details

    • HttpTtyConnection

      public HttpTtyConnection()
      Creates a new HTTP TTY connection with default charset (UTF-8) and size (80x24).
    • HttpTtyConnection

      public HttpTtyConnection(Charset charset, org.aesh.terminal.tty.Size size)
      Creates a new HTTP TTY connection with the specified charset and size.
      Parameters:
      charset - the character encoding for the connection
      size - the initial terminal size
  • Method Details

    • isInitialized

      public boolean isInitialized()
      Returns whether the client has sent an init message.
      Returns:
      true if the client has initialized the connection
    • outputEncoding

      public Charset outputEncoding()
    • inputEncoding

      public Charset inputEncoding()
    • lastAccessedTime

      public long lastAccessedTime()
      Returns the timestamp of the last access to this connection.
      Returns:
      the last accessed time in milliseconds since epoch
    • device

      public org.aesh.terminal.Device device()
    • write

      protected abstract void write(byte[] buffer)
      Writes raw bytes to the underlying transport.
      Parameters:
      buffer - the bytes to write
    • writeToDecoder

      public void writeToDecoder(String msg)
      Processes an incoming JSON message from the client and writes it to the decoder.

      Handles the following actions:

      • init - Client capability reporting (type, colorDepth, features, cols, rows)
      • read - Terminal input from the user
      • resize - Terminal resize events
      Parameters:
      msg - the JSON message from the client
    • getTerminalTypeHandler

      public Consumer<String> getTerminalTypeHandler()
      Returns the handler for terminal type events.
      Returns:
      the terminal type handler, or null if not set
    • setTerminalTypeHandler

      public void setTerminalTypeHandler(Consumer<String> handler)
      Sets the handler for terminal type events.
      Parameters:
      handler - the handler to invoke when terminal type is received
    • size

      public org.aesh.terminal.tty.Size size()
    • close

      public void close()
    • openBlocking

      public void openBlocking()
    • openNonBlocking

      public void openNonBlocking()
    • put

      public boolean put(org.aesh.terminal.tty.Capability capability, Object... params)
    • setAttributes

      public void setAttributes(org.aesh.terminal.Attributes attr)
      Specified by:
      setAttributes in interface org.aesh.terminal.Connection
      Overrides:
      setAttributes in class org.aesh.terminal.AbstractConnection
    • supportsAnsi

      public boolean supportsAnsi()