Class EventDecoder

java.lang.Object
org.aesh.terminal.EventDecoder
All Implemented Interfaces:
Consumer<int[]>

public class EventDecoder extends Object implements Consumer<int[]>
Decodes terminal input events, separating signals (INT, SUSP, EOF) and unsolicited terminal responses from regular input.

When a themeChangeHandler is registered, this decoder also intercepts CSI ? 997 ; Ps n theme change DSR notifications and routes them to the handler instead of passing them through as input. This prevents theme change notifications from corrupting the readline buffer.

Author:
Ståle W. Pedersen
  • Constructor Details

    • EventDecoder

      public EventDecoder()
      Create a new EventDecoder with default control character values. Default values: INTR=3 (Ctrl+C), EOF=4 (Ctrl+D), SUSP=26 (Ctrl+Z).
    • EventDecoder

      public EventDecoder(int intr, int eof, int susp)
      Create a new EventDecoder with custom control character values.
      Parameters:
      intr - the interrupt character code (typically Ctrl+C = 3)
      eof - the end-of-file character code (typically Ctrl+D = 4)
      susp - the suspend character code (typically Ctrl+Z = 26)
    • EventDecoder

      public EventDecoder(Attributes attributes)
      Create a new EventDecoder using control characters from terminal attributes. Falls back to default values if the attributes do not specify valid control characters.
      Parameters:
      attributes - the terminal attributes to extract control characters from
  • Method Details

    • getSignalHandler

      public Consumer<Signal> getSignalHandler()
      Get the current signal handler.
      Returns:
      the signal handler, or null if not set
    • setSignalHandler

      public void setSignalHandler(Consumer<Signal> signalHandler)
      Set the signal handler that will be called when signals are detected in input.
      Parameters:
      signalHandler - the handler to process signals
    • getInputHandler

      public Consumer<int[]> getInputHandler()
      Get the current input handler.
      Returns:
      the input handler, or null if not set
    • setInputHandler

      public void setInputHandler(Consumer<int[]> inputHandler)
      Set the input handler that will receive non-signal input. Any queued input will be delivered to the handler immediately.
      Parameters:
      inputHandler - the handler to process input as code point arrays
    • getThemeChangeHandler

      public Consumer<TerminalTheme> getThemeChangeHandler()
      Get the current theme change handler.
      Returns:
      the theme change handler, or null if not set
    • setThemeChangeHandler

      public void setThemeChangeHandler(Consumer<TerminalTheme> themeChangeHandler)
      Set the handler for theme change DSR notifications.

      When set, the decoder will intercept CSI ? 997 ; Ps n sequences from the input stream and invoke this handler instead of passing them through as regular input.

      Parameters:
      themeChangeHandler - the handler, or null to disable interception
    • accept

      public void accept(int[] input)
      Process input, separating signals and theme DSR notifications from regular input.

      Signal characters are extracted and sent to the signal handler. When a theme change handler is registered, CSI ? 997 ; Ps n sequences are intercepted and routed to the theme change handler. Remaining input is sent to the input handler.

      Specified by:
      accept in interface Consumer<int[]>
      Parameters:
      input - the input code points to process