Class AbstractConnection

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

public abstract class AbstractConnection extends Object implements Connection
Abstract base class for Connection implementations that use an EventDecoder for signal and input handling.

Provides the common handler plumbing (signal, stdin, stdout, size, close, attributes, reading state) so that subclasses only need to implement device/transport-specific methods.

Author:
Ståle W. Pedersen
  • Field Details

    • eventDecoder

      protected EventDecoder eventDecoder
    • stdout

      protected Consumer<int[]> stdout
    • sizeHandler

      protected Consumer<Size> sizeHandler
    • closeHandler

      protected Consumer<Void> closeHandler
    • attributes

      protected Attributes attributes
    • reading

      protected volatile boolean reading
  • Constructor Details

    • AbstractConnection

      public AbstractConnection()
  • Method Details

    • getSignalHandler

      public Consumer<Signal> getSignalHandler()
      Description copied from interface: Connection
      Get SignalHandler. A handler that's called when a Signal is sent to the terminal
      Specified by:
      getSignalHandler in interface Connection
      Returns:
      Signal handler
    • setSignalHandler

      public void setSignalHandler(Consumer<Signal> handler)
      Description copied from interface: Connection
      Specify the signal handler. A handler that's called when a Signal is sent to the terminal
      Specified by:
      setSignalHandler in interface Connection
      Parameters:
      handler - signal handler
    • getStdinHandler

      public Consumer<int[]> getStdinHandler()
      Description copied from interface: Connection
      Get the standard input handler.
      Specified by:
      getStdinHandler in interface Connection
      Returns:
      the stdin handler that processes input as code point arrays
    • setStdinHandler

      public void setStdinHandler(Consumer<int[]> handler)
      Description copied from interface: Connection
      Set the standard input handler.
      Specified by:
      setStdinHandler in interface Connection
      Parameters:
      handler - the handler to process input as code point arrays
    • stdoutHandler

      public Consumer<int[]> stdoutHandler()
      Description copied from interface: Connection
      Handler that's called for all output
      Specified by:
      stdoutHandler in interface Connection
      Returns:
      output handler
    • getSizeHandler

      public Consumer<Size> getSizeHandler()
      Description copied from interface: Connection
      Get the size handler.
      Specified by:
      getSizeHandler in interface Connection
      Returns:
      Handler that's called when the terminal changes size
    • setSizeHandler

      public void setSizeHandler(Consumer<Size> handler)
      Description copied from interface: Connection
      Specify size handler that's called when the terminal changes size.
      Specified by:
      setSizeHandler in interface Connection
      Parameters:
      handler - the size change handler
    • setCloseHandler

      public void setCloseHandler(Consumer<Void> closeHandler)
      Description copied from interface: Connection
      Specify handler that's called when the input stream is closed.
      Specified by:
      setCloseHandler in interface Connection
      Parameters:
      closeHandler - handler
    • getCloseHandler

      public Consumer<Void> getCloseHandler()
      Description copied from interface: Connection
      Get the close handler.
      Specified by:
      getCloseHandler in interface Connection
      Returns:
      handler thats called when the input stream is closed.
    • setThemeChangeHandler

      public void setThemeChangeHandler(Consumer<TerminalTheme> handler)
      Description copied from interface: Connection
      Set a handler to be called when the terminal's theme changes.

      When a handler is registered, the input pipeline will intercept unsolicited CSI ? 997 ; Ps n responses and route them to this handler instead of passing them through as input. This prevents theme change notifications from corrupting the readline buffer.

      Typically used together with Connection.enableThemeChangeNotification() which tells the terminal to send these notifications.

      Note: The default implementation is a no-op. Implementations that extend AbstractConnection get automatic support via EventDecoder.

      Specified by:
      setThemeChangeHandler in interface Connection
      Parameters:
      handler - the handler to invoke with the new theme, or null to remove
      See Also:
    • getThemeChangeHandler

      public Consumer<TerminalTheme> getThemeChangeHandler()
      Description copied from interface: Connection
      Get the current theme change handler.
      Specified by:
      getThemeChangeHandler in interface Connection
      Returns:
      the theme change handler, or null if not set
      See Also:
    • reading

      public boolean reading()
      Description copied from interface: Connection
      Check if the connection is actively reading from the input stream.

      This returns true after Connection.openBlocking() or Connection.openNonBlocking() has been called and before Connection.close() is called.

      When reading is active, query methods can use Connection.setStdinHandler(Consumer) to receive responses. When reading is not active, synchronous I/O must be used.

      Specified by:
      reading in interface Connection
      Returns:
      true if the connection is actively reading input
    • getAttributes

      public Attributes getAttributes()
      Description copied from interface: Connection
      Get the current terminal attributes.
      Specified by:
      getAttributes in interface Connection
      Returns:
      the terminal attributes
    • setAttributes

      public void setAttributes(Attributes attr)
      Description copied from interface: Connection
      Set the terminal attributes.
      Specified by:
      setAttributes in interface Connection
      Parameters:
      attr - the attributes to set