From 4cc2530de04c79554c0747ba4a2ca877c46058b8 Mon Sep 17 00:00:00 2001 From: tznind Date: Thu, 17 Jul 2025 02:49:25 +0100 Subject: [PATCH 1/6] Assume we are running in a terminal that supports true color by default unless user explicitly forces 16 --- Terminal.Gui/Drivers/V2/MainLoopCoordinator.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Terminal.Gui/Drivers/V2/MainLoopCoordinator.cs b/Terminal.Gui/Drivers/V2/MainLoopCoordinator.cs index a2cc34c497..a70b089567 100644 --- a/Terminal.Gui/Drivers/V2/MainLoopCoordinator.cs +++ b/Terminal.Gui/Drivers/V2/MainLoopCoordinator.cs @@ -25,7 +25,6 @@ internal class MainLoopCoordinator : IMainLoopCoordinator private ConsoleDriverFacade _facade; private Task _inputTask; private readonly ITimedEvents _timedEvents; - private readonly bool _isWindowsTerminal; private readonly SemaphoreSlim _startupSemaphore = new (0, 1); @@ -61,7 +60,6 @@ IMainLoop loop _inputProcessor = inputProcessor; _outputFactory = outputFactory; _loop = loop; - _isWindowsTerminal = Environment.GetEnvironmentVariable ("WT_SESSION") is { } || Environment.GetEnvironmentVariable ("VSAPPIDNAME") != null; } /// @@ -162,11 +160,6 @@ private void BuildFacadeIfPossible () _loop.AnsiRequestScheduler, _loop.WindowSizeMonitor); - if (!_isWindowsTerminal) - { - Application.Force16Colors = _facade.Force16Colors = true; - } - Application.Driver = _facade; _startupSemaphore.Release (); From 7b79fa4e2ee71a1233795d5f0816dea65ace6d90 Mon Sep 17 00:00:00 2001 From: tznind Date: Thu, 7 Aug 2025 03:39:32 +0100 Subject: [PATCH 2/6] Add support for extra modifiers for F1 to F4 keys --- .../AnsiResponseParser/Keyboard/CsiCursorPattern.cs | 10 ++++++++-- .../ConsoleDrivers/AnsiKeyboardParserTests.cs | 3 +-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Terminal.Gui/Drivers/AnsiResponseParser/Keyboard/CsiCursorPattern.cs b/Terminal.Gui/Drivers/AnsiResponseParser/Keyboard/CsiCursorPattern.cs index 0255e7394c..0dee968351 100644 --- a/Terminal.Gui/Drivers/AnsiResponseParser/Keyboard/CsiCursorPattern.cs +++ b/Terminal.Gui/Drivers/AnsiResponseParser/Keyboard/CsiCursorPattern.cs @@ -11,7 +11,7 @@ namespace Terminal.Gui.Drivers; /// 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 d7bcedd18a..4e178bdc69 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) From 6a987a05f10440fbaabfea5edbebe92e69a0dbf1 Mon Sep 17 00:00:00 2001 From: tznind Date: Thu, 7 Aug 2025 03:46:06 +0100 Subject: [PATCH 3/6] Revert "Assume we are running in a terminal that supports true color by default unless user explicitly forces 16" This reverts commit 4cc2530de04c79554c0747ba4a2ca877c46058b8. --- Terminal.Gui/Drivers/V2/MainLoopCoordinator.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Terminal.Gui/Drivers/V2/MainLoopCoordinator.cs b/Terminal.Gui/Drivers/V2/MainLoopCoordinator.cs index a70b089567..a2cc34c497 100644 --- a/Terminal.Gui/Drivers/V2/MainLoopCoordinator.cs +++ b/Terminal.Gui/Drivers/V2/MainLoopCoordinator.cs @@ -25,6 +25,7 @@ internal class MainLoopCoordinator : IMainLoopCoordinator private ConsoleDriverFacade _facade; private Task _inputTask; private readonly ITimedEvents _timedEvents; + private readonly bool _isWindowsTerminal; private readonly SemaphoreSlim _startupSemaphore = new (0, 1); @@ -60,6 +61,7 @@ IMainLoop loop _inputProcessor = inputProcessor; _outputFactory = outputFactory; _loop = loop; + _isWindowsTerminal = Environment.GetEnvironmentVariable ("WT_SESSION") is { } || Environment.GetEnvironmentVariable ("VSAPPIDNAME") != null; } /// @@ -160,6 +162,11 @@ private void BuildFacadeIfPossible () _loop.AnsiRequestScheduler, _loop.WindowSizeMonitor); + if (!_isWindowsTerminal) + { + Application.Force16Colors = _facade.Force16Colors = true; + } + Application.Driver = _facade; _startupSemaphore.Release (); From c6219218826042c79517648327c12229a0e80e97 Mon Sep 17 00:00:00 2001 From: tznind Date: Thu, 7 Aug 2025 03:46:25 +0100 Subject: [PATCH 4/6] Cleanup --- .../Keyboard/CsiCursorPattern.cs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Terminal.Gui/Drivers/AnsiResponseParser/Keyboard/CsiCursorPattern.cs b/Terminal.Gui/Drivers/AnsiResponseParser/Keyboard/CsiCursorPattern.cs index 0dee968351..74ce069dbc 100644 --- a/Terminal.Gui/Drivers/AnsiResponseParser/Keyboard/CsiCursorPattern.cs +++ b/Terminal.Gui/Drivers/AnsiResponseParser/Keyboard/CsiCursorPattern.cs @@ -62,16 +62,16 @@ public class CsiCursorPattern : AnsiKeyboardParserPattern if (int.TryParse (modifierGroup, out int modifier)) { key = modifier switch - { - 2 => key.WithShift, - 3 => key.WithAlt, - 4 => key.WithAlt.WithShift, - 5 => key.WithCtrl, - 6 => key.WithCtrl.WithShift, - 7 => key.WithCtrl.WithAlt, - 8 => key.WithCtrl.WithAlt.WithShift, - _ => key - }; + { + 2 => key.WithShift, + 3 => key.WithAlt, + 4 => key.WithAlt.WithShift, + 5 => key.WithCtrl, + 6 => key.WithCtrl.WithShift, + 7 => key.WithCtrl.WithAlt, + 8 => key.WithCtrl.WithAlt.WithShift, + _ => key + }; } return key; From a3ce9fbcdfc0e8a605adf69035b18c9c1fd8ebd6 Mon Sep 17 00:00:00 2001 From: tznind Date: Mon, 11 Aug 2025 14:06:23 +0100 Subject: [PATCH 5/6] Update comments --- .../Drivers/AnsiResponseParser/Keyboard/CsiCursorPattern.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Terminal.Gui/Drivers/AnsiResponseParser/Keyboard/CsiCursorPattern.cs b/Terminal.Gui/Drivers/AnsiResponseParser/Keyboard/CsiCursorPattern.cs index 74ce069dbc..7cdeeadb75 100644 --- a/Terminal.Gui/Drivers/AnsiResponseParser/Keyboard/CsiCursorPattern.cs +++ b/Terminal.Gui/Drivers/AnsiResponseParser/Keyboard/CsiCursorPattern.cs @@ -7,7 +7,7 @@ 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 { From 0c4439fbb836183aed81dea70b4097ba23bc64d4 Mon Sep 17 00:00:00 2001 From: tznind Date: Mon, 11 Aug 2025 14:17:10 +0100 Subject: [PATCH 6/6] Code cleanup --- .../Keyboard/CsiCursorPattern.cs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Terminal.Gui/Drivers/AnsiResponseParser/Keyboard/CsiCursorPattern.cs b/Terminal.Gui/Drivers/AnsiResponseParser/Keyboard/CsiCursorPattern.cs index 7cdeeadb75..744658a767 100644 --- a/Terminal.Gui/Drivers/AnsiResponseParser/Keyboard/CsiCursorPattern.cs +++ b/Terminal.Gui/Drivers/AnsiResponseParser/Keyboard/CsiCursorPattern.cs @@ -62,16 +62,16 @@ public class CsiCursorPattern : AnsiKeyboardParserPattern if (int.TryParse (modifierGroup, out int modifier)) { key = modifier switch - { - 2 => key.WithShift, - 3 => key.WithAlt, - 4 => key.WithAlt.WithShift, - 5 => key.WithCtrl, - 6 => key.WithCtrl.WithShift, - 7 => key.WithCtrl.WithAlt, - 8 => key.WithCtrl.WithAlt.WithShift, - _ => key - }; + { + 2 => key.WithShift, + 3 => key.WithAlt, + 4 => key.WithAlt.WithShift, + 5 => key.WithCtrl, + 6 => key.WithCtrl.WithShift, + 7 => key.WithCtrl.WithAlt, + 8 => key.WithCtrl.WithAlt.WithShift, + _ => key + }; } return key;