Class ActionDecoder

java.lang.Object
org.aesh.readline.action.ActionDecoder

public class ActionDecoder extends Object
Decodes input key sequences and maps them to corresponding actions.

Uses a pre-allocated buffer with offset tracking to avoid per-keystroke array allocations. The buffer grows when needed but is compacted only when the read offset exceeds half the capacity.

Author:
Ståle W. Pedersen
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    Functional interface for peeking at terminal input without consuming it.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a decoder with default key mappings.
    Creates a decoder with key mappings from the specified edit mode.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(int input)
    Adds a single input code point to the decoder buffer.
    void
    add(int[] input)
    Adds input code points to the decoder buffer.
    boolean
    Checks if there is another action available.
    org.aesh.terminal.KeyAction
    Returns and removes the next action from the queue.
    org.aesh.terminal.KeyAction
    Returns the next action without removing it from the queue.
    void
    setEscapeTimeout(long timeoutMs)
    Sets the escape sequence disambiguation timeout.
    void
    Sets the input peeker for escape sequence timeout disambiguation.
    void
    Updates the key mappings from the specified edit mode.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ActionDecoder

      public ActionDecoder(EditMode editMode)
      Creates a decoder with key mappings from the specified edit mode.
      Parameters:
      editMode - the edit mode providing key mappings
    • ActionDecoder

      public ActionDecoder()
      Creates a decoder with default key mappings.
  • Method Details

    • setInputPeeker

      public void setInputPeeker(ActionDecoder.InputPeeker peeker)
      Sets the input peeker for escape sequence timeout disambiguation.

      When set, the decoder will use peek(escapeTimeout) to check if more input is coming after an ambiguous prefix (e.g., bare ESC). If the peek times out, the prefix is treated as a complete action.

      Parameters:
      peeker - the input peeker, or null to disable timeout disambiguation
    • setEscapeTimeout

      public void setEscapeTimeout(long timeoutMs)
      Sets the escape sequence disambiguation timeout.
      Parameters:
      timeoutMs - timeout in milliseconds (default: 50ms)
    • add

      public void add(int[] input)
      Adds input code points to the decoder buffer.
      Parameters:
      input - the array of code points to add
    • add

      public void add(int input)
      Adds a single input code point to the decoder buffer.
      Parameters:
      input - the code point to add
    • peek

      public org.aesh.terminal.KeyAction peek()
      Returns the next action without removing it from the queue.
      Returns:
      the next key action, or null if none available
    • hasNext

      public boolean hasNext()
      Checks if there is another action available.
      Returns:
      true if another action is available
    • next

      public org.aesh.terminal.KeyAction next()
      Returns and removes the next action from the queue.
      Returns:
      the next key action
    • setMappings

      public void setMappings(EditMode editMode)
      Updates the key mappings from the specified edit mode.
      Parameters:
      editMode - the edit mode providing new key mappings