Class AbstractConnection

java.lang.Object
org.aesh.terminal.AbstractConnection
All Implemented Interfaces:
Appendable, 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
      Field.
    • stdout

      protected Consumer<int[]> stdout
      Field.
    • sizeHandler

      protected Consumer<Size> sizeHandler
      Field.
    • closeHandler

      protected Consumer<Void> closeHandler
      Field.
    • attributes

      protected Attributes attributes
      Field.
    • reading

      protected volatile boolean reading
      Field.
  • Constructor Details

    • AbstractConnection

      protected AbstractConnection()
      Constructor.
  • Method Details

    • terminal

      public TerminalFeatures terminal()
      Description copied from interface: Connection
      Access advanced terminal features: queries, capability detection, semantic output, and mode management.
      Specified by:
      terminal in interface Connection
      Returns:
      the terminal features for this connection
    • signalHandler

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

      public void setSignalHandler(Consumer<Signal> handler)
      Description copied from interface: Connection
      Specify the signal handler.
      Specified by:
      setSignalHandler in interface Connection
      Parameters:
      handler - signal handler
    • stdinHandler

      public Consumer<int[]> stdinHandler()
      Description copied from interface: Connection
      Get the standard input handler.
      Specified by:
      stdinHandler 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
    • sizeHandler

      public Consumer<Size> sizeHandler()
      Description copied from interface: Connection
      Get the size handler.
      Specified by:
      sizeHandler 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
    • closeHandler

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

      public void setThemeChangeHandler(Consumer<org.aesh.terminal.detect.TerminalTheme> handler)
      Description copied from interface: Connection
      Set a handler to be called when the terminal's theme changes.
      Specified by:
      setThemeChangeHandler in interface Connection
      Parameters:
      handler - the handler to invoke with the new theme, or null to remove
    • themeChangeHandler

      public Consumer<org.aesh.terminal.detect.TerminalTheme> themeChangeHandler()
      Description copied from interface: Connection
      Get the current theme change handler.
      Specified by:
      themeChangeHandler in interface Connection
      Returns:
      the theme change handler, or null if not set
    • setMouseHandler

      public void setMouseHandler(Consumer<MouseEvent> handler)
      Description copied from interface: Connection
      Set a handler to be called when mouse events are received.

      Mouse tracking must be explicitly enabled via MouseTracking for the terminal to send mouse events.

      Specified by:
      setMouseHandler in interface Connection
      Parameters:
      handler - the handler to invoke with mouse events, or null to remove
      See Also:
    • mouseHandler

      public Consumer<MouseEvent> mouseHandler()
      Description copied from interface: Connection
      Get the current mouse event handler.
      Specified by:
      mouseHandler in interface Connection
      Returns:
      the mouse handler, or null if not set
    • setFocusHandler

      public void setFocusHandler(Consumer<Boolean> handler)
      Description copied from interface: Connection
      Set the handler for terminal focus events.

      When set, the terminal will report focus gained (true) and focus lost (false) events. Focus tracking must be enabled by sending ESC [ ? 1004 h to the terminal.

      Specified by:
      setFocusHandler in interface Connection
      Parameters:
      handler - the focus handler, or null to disable
    • focusHandler

      public Consumer<Boolean> focusHandler()
      Description copied from interface: Connection
      Get the current focus event handler.
      Specified by:
      focusHandler in interface Connection
      Returns:
      the focus handler, or null if not set
    • registerStatusLine

      public StatusLine registerStatusLine(int priority)
      Description copied from interface: Connection
      Register a persistent status line displayed between scrolling output and the prompt.

      Status lines are rendered in priority order: lowest priority at top, highest priority at bottom (closest to the prompt). They persist across Connection.printAbove(String) calls and are redrawn automatically.

      If multiple status lines share the same priority, they are ordered by registration time.

      Specified by:
      registerStatusLine in interface Connection
      Parameters:
      priority - the display priority (higher = closer to prompt)
      Returns:
      a new StatusLine that can be updated or closed
    • getStatusMessages

      public List<String> getStatusMessages()
      Returns the current status line messages in display order (lowest priority first).
      Returns:
      unmodifiable list of active status line messages
    • setPrintAboveHandler

      public void setPrintAboveHandler(Consumer<String> handler)
      Description copied from interface: Connection
      Set the handler for Connection.printAbove(String) calls.

      This is typically set by the readline implementation during an active readline session, and cleared when the session ends.

      Specified by:
      setPrintAboveHandler in interface Connection
      Parameters:
      handler - the handler, or null to disable
    • printAboveHandler

      public Consumer<String> printAboveHandler()
      Description copied from interface: Connection
      Get the current printAbove handler.
      Specified by:
      printAboveHandler in interface Connection
      Returns:
      the handler, or null if not set
    • reading

      public boolean reading()
      Description copied from interface: Connection
      Check if the connection is actively reading from the input stream.
      Specified by:
      reading in interface Connection
      Returns:
      true if the connection is actively reading input
    • attributes

      public Attributes attributes()
      Description copied from interface: Connection
      Get the current terminal attributes.
      Specified by:
      attributes 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