From 7ca765cef1e910c73d35f1b81e78260404033d69 Mon Sep 17 00:00:00 2001 From: Thomas Nind <31306100+tznind@users.noreply.github.com> Date: Sun, 31 Aug 2025 16:57:30 +0100 Subject: [PATCH] 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 4cc2530de04c79554c0747ba4a2ca877c46058b8. * Cleanup * Update comments * Code cleanup --------- Co-authored-by: Tig --- .../AnsiResponseParser/Keyboard/CsiCursorPattern.cs | 12 +++++++++--- .../ConsoleDrivers/AnsiKeyboardParserTests.cs | 3 +-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Terminal.Gui/Drivers/AnsiResponseParser/Keyboard/CsiCursorPattern.cs b/Terminal.Gui/Drivers/AnsiResponseParser/Keyboard/CsiCursorPattern.cs index 0255e7394..744658a76 100644 --- a/Terminal.Gui/Drivers/AnsiResponseParser/Keyboard/CsiCursorPattern.cs +++ b/Terminal.Gui/Drivers/AnsiResponseParser/Keyboard/CsiCursorPattern.cs @@ -7,11 +7,11 @@ namespace Terminal.Gui.Drivers; /// Detects ansi escape sequences in strings that have been read from /// the terminal (see ). /// Handles navigation CSI key parsing such as \x1b[A (Cursor up) -/// and \x1b[1;5A (Cursor up with Ctrl) +/// and \x1b[1;5A (Cursor/Function with modifier(s)) /// 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 _cursorMap = new () { @@ -20,7 +20,13 @@ public class CsiCursorPattern : AnsiKeyboardParserPattern { 'C', Key.CursorRight }, { 'D', Key.CursorLeft }, { 'H', Key.Home }, - { 'F', Key.End } + { 'F', Key.End }, + + // F1–F4 as per xterm VT100-style CSI sequences + { 'P', Key.F1 }, + { 'Q', Key.F2 }, + { 'R', Key.F3 }, + { 'S', Key.F4 } }; /// diff --git a/Tests/UnitTests/ConsoleDrivers/AnsiKeyboardParserTests.cs b/Tests/UnitTests/ConsoleDrivers/AnsiKeyboardParserTests.cs index d7bcedd18..4e178bdc6 100644 --- a/Tests/UnitTests/ConsoleDrivers/AnsiKeyboardParserTests.cs +++ b/Tests/UnitTests/ConsoleDrivers/AnsiKeyboardParserTests.cs @@ -100,11 +100,10 @@ public class AnsiKeyboardParserTests yield return new object [] { "\u001b[24~", Key.F12 }; // Function keys with modifiers - /* Not currently supported 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;5R", Key.F3.WithCtrl }; - */ + } // Consolidated test for all keyboard events (e.g., arrow keys)