CharacterPattern
ScreenInfoCharacterPattern
public class EscapeSequenceCharacterPattern extends Object implements CharacterPattern
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
CharacterPattern.Matching
Modifier and Type | Field | Description |
---|---|---|
static int |
ALT |
|
static int |
CTRL |
|
protected Map<Character,KeyType> |
finMap |
Map of recognized "finish pattern" sequences:
e.g.: 'A' -> ArrowUp : "Esc [ A" |
static int |
SHIFT |
|
protected Map<Integer,KeyType> |
stdMap |
Map of recognized "standard pattern" sequences:
e.g.: 24 -> F12 : "Esc [ 24 ~" |
protected boolean |
useEscEsc |
A flag to control, whether an Esc-prefix for an Esc-sequence is to be treated
as Alt-pressed.
|
Constructor | Description |
---|---|
EscapeSequenceCharacterPattern() |
Create an instance with a standard set of mappings.
|
Modifier and Type | Method | Description |
---|---|---|
protected 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.
|
CharacterPattern.Matching |
match(List<Character> cur) |
Given a list of characters, determine whether it exactly matches
any known KeyStroke, and whether a longer sequence can possibly match.
|
public static final int SHIFT
public static final int ALT
public static final int CTRL
protected final Map<Integer,KeyType> stdMap
protected final Map<Character,KeyType> finMap
protected boolean useEscEsc
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.)
public EscapeSequenceCharacterPattern()
protected KeyStroke getKeyStroke(KeyType key, int mods)
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.protected KeyStroke getKeyStrokeRaw(char first, int num1, int num2, char last, boolean bEsc)
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.public CharacterPattern.Matching match(List<Character> cur)
CharacterPattern
match
in interface CharacterPattern
cur
- of characters to checkMatching
Copyright © 2020. All rights reserved.