Class EscapeSequenceCharacterPattern
- All Implemented Interfaces:
CharacterPattern
- Direct Known Subclasses:
ScreenInfoCharacterPattern
These sequences all start with Escape, followed by either an open bracket or a capital letter O (these two are treated as equivalent).
Then follows a list of zero or up to two decimals separated by a semicolon, and a non-digit last character.
If the last character is a tilde (~) then the first number defines the key (through stdMap), otherwise the last character itself defines the key (through finMap).
The second number, if provided by the terminal, specifies the modifier state (shift,alt,ctrl). The value is 1 + sum(modifiers), where shift is 1, alt is 2 and ctrl is 4.
The two maps stdMap and finMap can be customized in subclasses to add, remove or replace keys - to support non-standard Terminals.
Examples: (on a gnome terminal)
ArrowUp is "Esc [ A"; Alt-ArrowUp is "Esc [ 1 ; 3 A"
both are handled by finMap mapping 'A' to ArrowUp
F6 is "Esc [ 1 7 ~"; Ctrl-Shift-F6 is "Esc [ 1 7 ; 6 R"
both are handled by stdMap mapping 17 to F6
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface com.googlecode.lanterna.input.CharacterPattern
CharacterPattern.Matching
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
Map of recognized "finish pattern" sequences:
e.g.: 'A' -> ArrowUp : "Esc [ A"static final int
Map of recognized "standard pattern" sequences:
e.g.: 24 -> F12 : "Esc [ 24 ~"protected boolean
A flag to control, whether an Esc-prefix for an Esc-sequence is to be treated as Alt-pressed. -
Constructor Summary
ConstructorsConstructorDescriptionCreate an instance with a standard set of mappings. -
Method Summary
Modifier and TypeMethodDescriptionprotected KeyStroke
getKeyStroke
(KeyType key, int mods) combines a KeyType and modifiers into a KeyStroke.protected KeyStroke
getKeyStrokeRaw
(char first, int num1, int num2, char last, boolean bEsc) combines the raw parts of the sequence into a KeyStroke.Given a list of characters, determine whether it exactly matches any known KeyStroke, and whether a longer sequence can possibly match.
-
Field Details
-
SHIFT
public static final int SHIFT- See Also:
-
ALT
public static final int ALT- See Also:
-
CTRL
public static final int CTRL- See Also:
-
stdMap
Map of recognized "standard pattern" sequences:
e.g.: 24 -> F12 : "Esc [ 24 ~" -
finMap
Map of recognized "finish pattern" sequences:
e.g.: 'A' -> ArrowUp : "Esc [ A" -
useEscEsc
protected boolean useEscEscA flag to control, whether an Esc-prefix for an Esc-sequence is to be treated as Alt-pressed. Some Terminals (e.g. putty) report the Alt-modifier like that.If the application is e.g. more interested in seeing separate Escape and plain Arrow keys, then it should replace this class by a subclass that sets this flag to false. (It might then also want to remove the CtrlAltAndCharacterPattern.)
-
-
Constructor Details
-
EscapeSequenceCharacterPattern
public EscapeSequenceCharacterPattern()Create an instance with a standard set of mappings.
-
-
Method Details
-
getKeyStroke
combines a KeyType and modifiers into a KeyStroke. Subclasses can override this for customization purposes.- Parameters:
key
- the KeyType as determined by parsing the sequence. It will be null, if the pattern looked like a key sequence but wasn't identified.mods
- the bitmask of the modifer keys pressed along with the key.- Returns:
- either null (to report mis-match), or a valid KeyStroke.
-
getKeyStrokeRaw
combines the raw parts of the sequence into a KeyStroke. This method does not check the first char, but overrides may do so.- Parameters:
first
- the char following after Esc in the sequence (either [ or O)num1
- the first decimal, or 0 if not in the sequencenum2
- the second decimal, or 0 if not in the sequencelast
- the terminating char.bEsc
- whether an extra Escape-prefix was found.- Returns:
- either null (to report mis-match), or a valid KeyStroke.
-
match
Description copied from interface:CharacterPattern
Given a list of characters, determine whether it exactly matches any known KeyStroke, and whether a longer sequence can possibly match.- Specified by:
match
in interfaceCharacterPattern
- Parameters:
cur
- of characters to check- Returns:
- see
Matching
-