Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: v2_develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ namespace Terminal.Gui.Drivers;
/// Detects ansi escape sequences in strings that have been read from
/// the terminal (see <see cref="IAnsiResponseParser"/>).
/// 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>
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 ()
{
Expand All @@ -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 }
};

/// <inheritdoc/>
Expand Down
3 changes: 1 addition & 2 deletions Tests/UnitTests/ConsoleDrivers/AnsiKeyboardParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading