Class ActionDecoder
java.lang.Object
org.aesh.readline.action.ActionDecoder
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 ClassesModifier and TypeClassDescriptionstatic interfaceFunctional interface for peeking at terminal input without consuming it. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a decoder with default key mappings.ActionDecoder(EditMode editMode) Creates a decoder with key mappings from the specified edit mode. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(int input) Adds a single input code point to the decoder buffer.voidadd(int[] input) Adds input code points to the decoder buffer.booleanhasNext()Checks if there is another action available.org.aesh.terminal.KeyActionnext()Returns and removes the next action from the queue.org.aesh.terminal.KeyActionpeek()Returns the next action without removing it from the queue.voidsetEscapeTimeout(long timeoutMs) Sets the escape sequence disambiguation timeout.voidSets the input peeker for escape sequence timeout disambiguation.voidsetMappings(EditMode editMode) Updates the key mappings from the specified edit mode.
-
Constructor Details
-
ActionDecoder
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
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
Updates the key mappings from the specified edit mode.- Parameters:
editMode- the edit mode providing new key mappings
-