Class HttpTtyConnection

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

public abstract class HttpTtyConnection extends Object implements Connection
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: { "action": "read", "data": "what the user typed" } or { "action": "resize", "cols": 30, "rows: 50 }
Author:
Julien Viet, Matej Lazar
  • Field Details

    • DEFAULT_SIZE

      public static final 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, 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

    • outputEncoding

      public Charset outputEncoding()
      Specified by:
      outputEncoding in interface Connection
    • inputEncoding

      public Charset inputEncoding()
      Specified by:
      inputEncoding in interface Connection
    • 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 Device device()
      Specified by:
      device in interface Connection
    • 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 "read" actions (terminal input) and "resize" actions (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 Size size()
      Specified by:
      size in interface Connection
    • getSizeHandler

      public Consumer<Size> getSizeHandler()
      Returns the handler for terminal size change events.
      Specified by:
      getSizeHandler in interface Connection
      Returns:
      the size handler, or null if not set
    • setSizeHandler

      public void setSizeHandler(Consumer<Size> handler)
      Sets the handler for terminal size change events.
      Specified by:
      setSizeHandler in interface Connection
      Parameters:
      handler - the handler to invoke when terminal size changes
    • getSignalHandler

      public Consumer<Signal> getSignalHandler()
      Specified by:
      getSignalHandler in interface Connection
    • setSignalHandler

      public void setSignalHandler(Consumer<Signal> handler)
      Specified by:
      setSignalHandler in interface Connection
    • getStdinHandler

      public Consumer<int[]> getStdinHandler()
      Returns the handler for standard input data.
      Specified by:
      getStdinHandler in interface Connection
      Returns:
      the stdin handler, or null if not set
    • setStdinHandler

      public void setStdinHandler(Consumer<int[]> handler)
      Sets the handler for standard input data.
      Specified by:
      setStdinHandler in interface Connection
      Parameters:
      handler - the handler to invoke when input is received
    • stdoutHandler

      public Consumer<int[]> stdoutHandler()
      Returns the standard output handler for writing terminal output.
      Specified by:
      stdoutHandler in interface Connection
      Returns:
      the stdout handler
    • setCloseHandler

      public void setCloseHandler(Consumer<Void> closeHandler)
      Specified by:
      setCloseHandler in interface Connection
    • getCloseHandler

      public Consumer<Void> getCloseHandler()
      Specified by:
      getCloseHandler in interface Connection
    • openBlocking

      public void openBlocking()
      Specified by:
      openBlocking in interface Connection
    • openNonBlocking

      public void openNonBlocking()
      Specified by:
      openNonBlocking in interface Connection
    • put

      public boolean put(Capability capability, Object... params)
      Specified by:
      put in interface Connection
    • getAttributes

      public Attributes getAttributes()
      Specified by:
      getAttributes in interface Connection
    • setAttributes

      public void setAttributes(Attributes attr)
      Specified by:
      setAttributes in interface Connection
    • supportsAnsi

      public boolean supportsAnsi()
      Specified by:
      supportsAnsi in interface Connection