Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
d929235
move WellKnownStrings to a separate file
adamsitnik Jun 28, 2022
c8887ec
move Database to separate file
adamsitnik Jun 28, 2022
cf77107
move factory logic to DatabaseFactory so the test project does not ne…
adamsitnik Jun 28, 2022
c6f3a60
move WellKnownNumbers to separate file
adamsitnik Jun 28, 2022
acd4f24
include Database in the test project
adamsitnik Jun 28, 2022
f5e3641
move TerminalFormatStrings to a separate file
adamsitnik Jun 28, 2022
d3cdb93
include TerminalFormatStrings in test project
adamsitnik Jun 28, 2022
7ea9f50
fix existing tests
adamsitnik Jun 28, 2022
dc0af6b
move the key mapping logic to a separate class, do NOT change it
adamsitnik Jun 29, 2022
c927091
simple tests for ASCII characters
adamsitnik Jun 29, 2022
f30f02e
test cases for xterm and xterm-256color
adamsitnik Jul 5, 2022
5ffdd67
add PuTTY and UXTern
adamsitnik Jul 5, 2022
9230c81
add Windows Terminal data
adamsitnik Jul 6, 2022
41a92bf
add more PuTTY test cases
adamsitnik Jul 6, 2022
af92ab3
handle empty encodings
adamsitnik Jul 6, 2022
9a2ed71
make it possible to run the tests on Windows so I can use my favourit…
adamsitnik Jul 7, 2022
69f12c9
add mappings for single characters
adamsitnik Jul 7, 2022
5bbac1d
add mappings for 3 characters
adamsitnik Jul 8, 2022
a9db7db
fix test cases where pressing Ctrl/Alt/Shift + other key produces two…
adamsitnik Jul 8, 2022
c2e02d8
handle more complex sequences (with modifiers)
adamsitnik Jul 8, 2022
620d1a0
handle edge cases properly
adamsitnik Jul 9, 2022
20593ef
add tmux test data
adamsitnik Jul 11, 2022
c612f4f
add rxvt-unicode test data and implementation for rxvt modifiers
adamsitnik Jul 11, 2022
3e62636
polishing
adamsitnik Jul 12, 2022
aa07430
switch to the new implementation and allow the users to differentiate…
adamsitnik Jul 12, 2022
254c762
add way more test cases and fix identified issues
adamsitnik Jul 12, 2022
4023725
polishing: reorder the tests
adamsitnik Jul 13, 2022
d65c6e7
fix compiler error (it's strange as I was not getting it when I was b…
adamsitnik Jul 14, 2022
8cd9e3d
add more SCO mappings
adamsitnik Jul 14, 2022
7fea037
Numeric Keypad
adamsitnik Jul 14, 2022
16e983f
Merge remote-tracking branch 'upstream/main' into consoleReadKey
adamsitnik Jul 14, 2022
dd07418
add Tmux 256 color test cases (TERM=screen-256color)
adamsitnik Jul 21, 2022
632267c
add two Numeric Keypad test cases: period & Enter
adamsitnik Jul 21, 2022
69f6434
fix issue discovered by adding more tmux test cases: ^[OM should be m…
adamsitnik Jul 21, 2022
9c352b4
address code review feedback: move TerminalFormatStrings classs out i…
adamsitnik Jul 21, 2022
f974992
address code review feedback: handle all variants of tmux when gettin…
adamsitnik Jul 21, 2022
b3366a8
address code review feedback: reduce number of out parameters
adamsitnik Jul 21, 2022
dc82fb5
fix TermInfo tests
adamsitnik Jul 21, 2022
214da94
add .NET 6 compat switch
adamsitnik Jul 21, 2022
7766ed3
Apply suggestions from code review
adamsitnik Aug 1, 2022
c8010c5
address code review feedback
adamsitnik Aug 1, 2022
c28d600
Merge branch 'main' into consoleReadKey
adamsitnik Aug 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Numeric Keypad
  • Loading branch information
adamsitnik committed Jul 14, 2022
commit 7fea037f25414053a578ea41fc064376ea93da0d
38 changes: 29 additions & 9 deletions src/libraries/System.Console/src/System/IO/KeyParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private static bool TryParseTerminalInputSequence(char[] buffer, ConsolePal.Term
// Example: "^[[a" is Shift+UpArrow for rxvt and Shift+F3 for SCO.
if (input[1] == 'O'|| terminalFormatStrings.IsRxvtTerm)
{
key = MapKeyIdOXterm(input[2]); // fallback to well known mappings
key = MapKeyIdOXterm(input[2], terminalFormatStrings.IsRxvtTerm); // fallback to well known mappings

if (key != default)
{
Expand All @@ -107,7 +107,15 @@ private static bool TryParseTerminalInputSequence(char[] buffer, ConsolePal.Term
return false; // it was not a known sequence
}
}
character = key == ConsoleKey.Enter ? '\r' : default; // "^[OM" should produce new line character (was not previously mapped this way)
character = key switch
{
ConsoleKey.Enter => '\r', // "^[OM" should produce new line character (was not previously mapped this way)
ConsoleKey.Add => '+',
ConsoleKey.Subtract => '-',
ConsoleKey.Divide => '/',
ConsoleKey.Multiply => '*',
_ => default
};
startIndex += MinimalSequenceLength;
return true;
}
Expand Down Expand Up @@ -170,7 +178,7 @@ private static bool TryParseTerminalInputSequence(char[] buffer, ConsolePal.Term

key = input[SequencePrefixLength + digitCount + 2] is VtSequenceEndTag
? MapEscapeSequenceNumber(byte.Parse(input.Slice(SequencePrefixLength, digitCount)))
: MapKeyIdOXterm(input[SequencePrefixLength + digitCount + 2]);
: MapKeyIdOXterm(input[SequencePrefixLength + digitCount + 2], terminalFormatStrings.IsRxvtTerm);

if (key != default)
{
Expand All @@ -195,25 +203,37 @@ static bool TryMapUsingTerminfoDb(ReadOnlyMemory<char> inputSequence, ConsolePal
}

// maps "^[O{character}" for all Terminals and "^[[{character}" for rxvt Terminals
static ConsoleKey MapKeyIdOXterm(char character)
static ConsoleKey MapKeyIdOXterm(char character, bool isRxvt)
=> character switch
{
'A' or 'a' => ConsoleKey.UpArrow,
'B' or 'b' => ConsoleKey.DownArrow,
'C' or 'c' => ConsoleKey.RightArrow,
'D' or 'd' => ConsoleKey.LeftArrow,
'F' or 'w' => ConsoleKey.End,
'A' or 'a' or 'x' => ConsoleKey.UpArrow, // lowercase used by rxvt
'B' or 'b' or 'r' => ConsoleKey.DownArrow, // lowercase used by rxv
'C' or 'c' or 'v' => ConsoleKey.RightArrow, // lowercase used by rxv
'D' or 'd' or 't' => ConsoleKey.LeftArrow, // lowercase used by rxv
'E' => ConsoleKey.NoName, // ^[OE maps to Begin, but we don't have such Key. To reproduce press Num5.
'F' or 'q' => ConsoleKey.End,
'H' => ConsoleKey.Home,
'j' => ConsoleKey.Multiply, // used by both xterm and rxvt
'k' => ConsoleKey.Add, // used by both xterm and rxvt
'm' => ConsoleKey.Subtract, // used by both xterm and rxvt
'n' => ConsoleKey.Delete, // rxvt
'o' => ConsoleKey.Divide, // used by both xterm and rxvt
'P' => ConsoleKey.F1,
'p' => ConsoleKey.Insert, // rxvt
'Q' => ConsoleKey.F2,
'R' => ConsoleKey.F3,
'S' => ConsoleKey.F4,
's' => ConsoleKey.PageDown, // rxvt
'T' => ConsoleKey.F5, // VT 100+
'U' => ConsoleKey.F6, // VT 100+
'u' => ConsoleKey.NoName, // it should be Begin, but we don't have such (press Num5 in rxvt to reproduce)
'V' => ConsoleKey.F7, // VT 100+
'W' => ConsoleKey.F8, // VT 100+
'w' when isRxvt => ConsoleKey.Home,
'w' when !isRxvt => ConsoleKey.End,
'X' => ConsoleKey.F9, // VT 100+
'Y' => ConsoleKey.F10, // VT 100+
'y' => ConsoleKey.PageUp, // rxvt
'Z' => ConsoleKey.F11, // VT 100+
'[' => ConsoleKey.F12, // VT 100+
_ => default
Expand Down
Loading