Fixes #4221 Extra modifiers f1 to f4 in v2net (#4220)

* Assume we are running in a terminal that supports true color by default unless user explicitly forces 16

* Add support for extra modifiers for F1 to F4 keys

* Revert "Assume we are running in a terminal that supports true color by default unless user explicitly forces 16"

This reverts commit 4cc2530de0.

* Cleanup

* Update comments

* Code cleanup

---------

Co-authored-by: Tig <tig@users.noreply.github.com>
This commit is contained in:
Thomas Nind
2025-08-31 16:57:30 +01:00
committed by GitHub
parent 5e7bfb8908
commit 7ca765cef1
2 changed files with 10 additions and 5 deletions

View File

@@ -7,11 +7,11 @@ namespace Terminal.Gui.Drivers;
/// Detects ansi escape sequences in strings that have been read from /// Detects ansi escape sequences in strings that have been read from
/// the terminal (see <see cref="IAnsiResponseParser"/>). /// the terminal (see <see cref="IAnsiResponseParser"/>).
/// Handles navigation CSI key parsing such as <c>\x1b[A</c> (Cursor up) /// Handles navigation CSI key parsing such as <c>\x1b[A</c> (Cursor up)
/// and <c>\x1b[1;5A</c> (Cursor up with Ctrl) /// and <c>\x1b[1;5A</c> (Cursor/Function with modifier(s))
/// </summary> /// </summary>
public class CsiCursorPattern : AnsiKeyboardParserPattern public class CsiCursorPattern : AnsiKeyboardParserPattern
{ {
private readonly Regex _pattern = new (@"^\u001b\[(?:1;(\d+))?([A-DHF])$"); private readonly Regex _pattern = new (@"^\u001b\[(?:1;(\d+))?([A-DFHPQRS])$");
private readonly Dictionary<char, Key> _cursorMap = new () private readonly Dictionary<char, Key> _cursorMap = new ()
{ {
@@ -20,7 +20,13 @@ public class CsiCursorPattern : AnsiKeyboardParserPattern
{ 'C', Key.CursorRight }, { 'C', Key.CursorRight },
{ 'D', Key.CursorLeft }, { 'D', Key.CursorLeft },
{ 'H', Key.Home }, { 'H', Key.Home },
{ 'F', Key.End } { 'F', Key.End },
// F1F4 as per xterm VT100-style CSI sequences
{ 'P', Key.F1 },
{ 'Q', Key.F2 },
{ 'R', Key.F3 },
{ 'S', Key.F4 }
}; };
/// <inheritdoc/> /// <inheritdoc/>

View File

@@ -100,11 +100,10 @@ public class AnsiKeyboardParserTests
yield return new object [] { "\u001b[24~", Key.F12 }; yield return new object [] { "\u001b[24~", Key.F12 };
// Function keys with modifiers // Function keys with modifiers
/* Not currently supported
yield return new object [] { "\u001b[1;2P", Key.F1.WithShift }; yield return new object [] { "\u001b[1;2P", Key.F1.WithShift };
yield return new object [] { "\u001b[1;3Q", Key.F2.WithAlt }; yield return new object [] { "\u001b[1;3Q", Key.F2.WithAlt };
yield return new object [] { "\u001b[1;5R", Key.F3.WithCtrl }; yield return new object [] { "\u001b[1;5R", Key.F3.WithCtrl };
*/
} }
// Consolidated test for all keyboard events (e.g., arrow keys) // Consolidated test for all keyboard events (e.g., arrow keys)