From 738a5ec53974c8f0f4e373b2a514562f133aef35 Mon Sep 17 00:00:00 2001 From: Tigger Kindel Date: Thu, 17 Aug 2023 11:42:45 -0600 Subject: [PATCH 1/7] setting up versioning --- GitVersion.yml | 37 +++++++++++++ Terminal.Gui/Terminal.Gui.csproj | 90 +++++++++++++++++++------------- Terminal.sln | 2 + global.json | 4 +- 4 files changed, 95 insertions(+), 38 deletions(-) create mode 100644 GitVersion.yml diff --git a/GitVersion.yml b/GitVersion.yml new file mode 100644 index 000000000..734e32408 --- /dev/null +++ b/GitVersion.yml @@ -0,0 +1,37 @@ +mode: ContinuousDeployment +tag-prefix: '[vV]' +continuous-delivery-fallback-tag: 'pre' +branches: + v1_develop: + mode: ContinuousDeployment + tag: pre + v1: + tag: rc + increment: Patch + source-branches: + - v1_develop + + v2_develop: + mode: ContinuousDeployment + tag: pre + v2: + tag: alpha + increment: Patch + source-branches: + - v2_develop +- + # feature: + # tag: useBranchName + # regex: ^features?[/-] + # source-branches: + # - v1 + # - v1_develop + # - v2 + # - v2_develop + + pull-request: + tag: PullRequest.{BranchName} + increment: Inherit +ignore: + sha: [] +merge-message-formats: {} diff --git a/Terminal.Gui/Terminal.Gui.csproj b/Terminal.Gui/Terminal.Gui.csproj index 30592f23d..e997f539d 100644 --- a/Terminal.Gui/Terminal.Gui.csproj +++ b/Terminal.Gui/Terminal.Gui.csproj @@ -1,39 +1,52 @@  + + + + + + + 2.0.0 + + + + portable + TRACE;DEBUG_IDISPOSABLE portable - CS1574 - - - - 2.0 - 2.0 - 2.0 - 2.0 + net7.0 + 10.0 + Terminal.Gui + Terminal.Gui + true + + + - - - - - - - - + + - + + + + + + + + True @@ -44,6 +57,9 @@ \ + + + True @@ -57,17 +73,26 @@ Strings.Designer.cs + + + - net7.0 - 10.0 - Terminal.Gui - Terminal.Gui - bin\Release\Terminal.Gui.xml - true - Terminal.Gui MIT https://github.com/gui-cs/Terminal.Gui/ + logo.png + README.md + csharp, terminal, c#, f#, gui, toolkit, console, tui + Cross platform Terminal UI toolkit for .NET + Miguel de Icaza, Tig Kindel + A toolkit for building rich console apps for .NET that works on Windows, Mac, and Linux/Unix. + Terminal.Gui - Cross platform Terminal User Interface (TUI) toolkit for .NET + + See: https://github.com/gui-cs/Terminal.Gui/releases + + bin\Release\Terminal.Gui.xml + true + true https://github.com/gui-cs/Terminal.Gui.git git true @@ -75,17 +100,10 @@ true + upstream true - logo.png - README.md - csharp, terminal, c#, f#, gui, toolkit, console, tui - Cross platform Terminal UI toolkit for .NET - Miguel de Icaza, Charlie Kindel - A toolkit for building rich console apps for .NET that works on Windows, Mac, and Linux/Unix. - Terminal.Gui - Cross platform Terminal User Interface (TUI) toolkit for .NET - - See: https://github.com/gui-cs/Terminal.Gui/releases - + true + + Miguel de Icaza, Tig Kindel (@tig), @BDisp - - \ No newline at end of file + diff --git a/Terminal.sln b/Terminal.sln index c3a820540..2474410eb 100644 --- a/Terminal.sln +++ b/Terminal.sln @@ -19,6 +19,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution CODE_OF_CONDUCT.md = CODE_OF_CONDUCT.md CONTRIBUTING.md = CONTRIBUTING.md .github\workflows\dotnet-core.yml = .github\workflows\dotnet-core.yml + GitVersion.yml = GitVersion.yml + global.json = global.json .github\workflows\publish.yml = .github\workflows\publish.yml README.md = README.md Terminal.sln.DotSettings = Terminal.sln.DotSettings diff --git a/global.json b/global.json index 539d965a8..cf0511e14 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk":{ - "version":"6.0.100", - "rollForward":"latestMajor" + "version":"7.0.200", + "rollForward":"latestMinor" } } From 720df9cd40fb6c80a447e34c312f34cb2f134b1b Mon Sep 17 00:00:00 2001 From: Tigger Kindel Date: Thu, 17 Aug 2023 11:57:50 -0600 Subject: [PATCH 2/7] setting up versioning --- GitVersion.yml | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/GitVersion.yml b/GitVersion.yml index 734e32408..d8a8d4453 100644 --- a/GitVersion.yml +++ b/GitVersion.yml @@ -5,29 +5,43 @@ branches: v1_develop: mode: ContinuousDeployment tag: pre + regex: ^v1_develop?[/-] + is-release-branch: false + source-branches: + - v1 v1: tag: rc increment: Patch - source-branches: - - v1_develop + regex: ^v2?[/-] + is-release-branch: false + source-branches: [] + is-mainline: true v2_develop: mode: ContinuousDeployment tag: pre - v2: - tag: alpha - increment: Patch + regex: ^v2_develop?[/-] + is-release-branch: false + tracks-release-branches: true source-branches: - v2_develop -- - # feature: - # tag: useBranchName - # regex: ^features?[/-] - # source-branches: - # - v1 - # - v1_develop - # - v2 - # - v2_develop + v2: + mode: ContinuousDeployment + tag: alpha + increment: Patch + regex: ^v2?[/-] + is-release-branch: false + source-branches: [] + is-mainline: true + + feature: + tag: useBranchName + regex: ^features?[/-] + source-branches: + - v1 + - v1_develop + - v2 + - v2_develop pull-request: tag: PullRequest.{BranchName} From 41019b118401a162cead247457ea9a04b18a24ed Mon Sep 17 00:00:00 2001 From: Tigger Kindel Date: Thu, 17 Aug 2023 12:19:55 -0600 Subject: [PATCH 3/7] setting up versioning --- GitVersion.yml | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/GitVersion.yml b/GitVersion.yml index d8a8d4453..2ef42b135 100644 --- a/GitVersion.yml +++ b/GitVersion.yml @@ -2,20 +2,20 @@ mode: ContinuousDeployment tag-prefix: '[vV]' continuous-delivery-fallback-tag: 'pre' branches: - v1_develop: - mode: ContinuousDeployment - tag: pre - regex: ^v1_develop?[/-] - is-release-branch: false - source-branches: - - v1 - v1: - tag: rc - increment: Patch - regex: ^v2?[/-] - is-release-branch: false - source-branches: [] - is-mainline: true + # v1_develop: + # mode: ContinuousDeployment + # tag: pre + # regex: ^v1_develop?[/-] + # is-release-branch: false + # source-branches: + # - v1 + # v1: + # tag: rc + # increment: Patch + # regex: ^v2?[/-] + # is-release-branch: false + # source-branches: [] + # is-mainline: true v2_develop: mode: ContinuousDeployment @@ -27,21 +27,21 @@ branches: - v2_develop v2: mode: ContinuousDeployment + is-release-branch: true tag: alpha increment: Patch regex: ^v2?[/-] - is-release-branch: false + is-source-branch-for: ['v2_develop'] source-branches: [] - is-mainline: true - feature: - tag: useBranchName - regex: ^features?[/-] - source-branches: - - v1 - - v1_develop - - v2 - - v2_develop + # feature: + # tag: useBranchName + # regex: ^features?[/-] + # source-branches: + # - v1 + # - v1_develop + # - v2 + # - v2_develop pull-request: tag: PullRequest.{BranchName} From 23b7ce3985e2925d3a309cae37839fcfebd891f6 Mon Sep 17 00:00:00 2001 From: Tigger Kindel Date: Thu, 17 Aug 2023 12:24:35 -0600 Subject: [PATCH 4/7] fighting with gitversion --- GitVersion.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/GitVersion.yml b/GitVersion.yml index 2ef42b135..f77b10ac2 100644 --- a/GitVersion.yml +++ b/GitVersion.yml @@ -21,18 +21,17 @@ branches: mode: ContinuousDeployment tag: pre regex: ^v2_develop?[/-] - is-release-branch: false + is-release-branch: true tracks-release-branches: true - source-branches: - - v2_develop + is-source-branch-for: ['v2'] + source-branches: [] v2: mode: ContinuousDeployment - is-release-branch: true + is-release-branch: false tag: alpha increment: Patch regex: ^v2?[/-] - is-source-branch-for: ['v2_develop'] - source-branches: [] + source-branches: ['v2_develop'] # feature: # tag: useBranchName From 6eceddd9c14ea3fa2b0a70b3678aaf303be2d022 Mon Sep 17 00:00:00 2001 From: Tigger Kindel Date: Thu, 17 Aug 2023 12:41:38 -0600 Subject: [PATCH 5/7] fixed config man bug --- Terminal.Gui/Terminal.Gui.csproj | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Terminal.Gui/Terminal.Gui.csproj b/Terminal.Gui/Terminal.Gui.csproj index e997f539d..fc60d1ee6 100644 --- a/Terminal.Gui/Terminal.Gui.csproj +++ b/Terminal.Gui/Terminal.Gui.csproj @@ -26,6 +26,15 @@ true + + + + + + + + + From 82b1dfbfb925e1abfdb0a93ef2e3841a8b069177 Mon Sep 17 00:00:00 2001 From: Tigger Kindel Date: Thu, 17 Aug 2023 13:04:34 -0600 Subject: [PATCH 6/7] backs out using _isWindowsTerminal for truecolor check --- Terminal.Gui/ConsoleDrivers/WindowsDriver.cs | 2 +- UICatalog/.editorconfig | 23 -------------------- UICatalog/Properties/launchSettings.json | 5 ++++- 3 files changed, 5 insertions(+), 25 deletions(-) delete mode 100644 UICatalog/.editorconfig diff --git a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs index 6b2178a6a..f1f0646dc 100644 --- a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs @@ -777,7 +777,7 @@ internal class WindowsDriver : ConsoleDriver { public WindowsConsole WinConsole { get; private set; } - public override bool SupportsTrueColor => RunningUnitTests || (_isWindowsTerminal && Environment.OSVersion.Version.Build >= 14931); + public override bool SupportsTrueColor => RunningUnitTests || (Environment.OSVersion.Version.Build >= 14931); public override bool Force16Colors { get => base.Force16Colors; diff --git a/UICatalog/.editorconfig b/UICatalog/.editorconfig deleted file mode 100644 index 040e7abd9..000000000 --- a/UICatalog/.editorconfig +++ /dev/null @@ -1,23 +0,0 @@ -[*.cs] -indent_style = tab -indent_size = 8 -tab_width = 8 -csharp_new_line_before_open_brace = methods,local_functions -csharp_new_line_before_else = false -csharp_new_line_before_catch = false -csharp_new_line_before_finally = false -end_of_line = crlf - -csharp_indent_case_contents = true -csharp_indent_switch_labels = false -csharp_indent_labels = flush_left -csharp_space_after_keywords_in_control_flow_statements = true -csharp_space_between_method_declaration_parameter_list_parentheses = false -csharp_space_between_method_call_parameter_list_parentheses = false -csharp_preserve_single_line_blocks = true -dotnet_style_require_accessibility_modifiers = never -csharp_style_var_when_type_is_apparent = true -csharp_prefer_braces = false -csharp_space_before_open_square_brackets = true -csharp_space_between_method_call_name_and_opening_parenthesis = true -csharp_space_between_method_declaration_name_and_open_parenthesis = true \ No newline at end of file diff --git a/UICatalog/Properties/launchSettings.json b/UICatalog/Properties/launchSettings.json index 00e9d9e71..0325ebcb2 100644 --- a/UICatalog/Properties/launchSettings.json +++ b/UICatalog/Properties/launchSettings.json @@ -1,7 +1,10 @@ { "profiles": { "UICatalog": { - "commandName": "Project" + "commandName": "Project", + "environmentVariables": { + "WT_SESSION": "1" + } }, "WSL : UICatalog": { "commandName": "Executable", From a3cb397ed7e5fdd711b22a92d52f3f352d97347f Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 23 Aug 2023 00:52:37 +0100 Subject: [PATCH 7/7] Fixes #2803. Harden EscSeqUtils --- Terminal.Gui/ConsoleDrivers/NetDriver.cs | 113 +++++++++++++++++------ 1 file changed, 83 insertions(+), 30 deletions(-) diff --git a/Terminal.Gui/ConsoleDrivers/NetDriver.cs b/Terminal.Gui/ConsoleDrivers/NetDriver.cs index 8cffd529e..27e930e84 100644 --- a/Terminal.Gui/ConsoleDrivers/NetDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/NetDriver.cs @@ -103,15 +103,17 @@ class NetWinVTConsole { static extern uint GetLastError (); } -internal class NetEvents { +internal class NetEvents : IDisposable { ManualResetEventSlim _inputReady = new ManualResetEventSlim (false); ManualResetEventSlim _waitForStart = new ManualResetEventSlim (false); ManualResetEventSlim _winChange = new ManualResetEventSlim (false); Queue _inputResultQueue = new Queue (); ConsoleDriver _consoleDriver; - volatile ConsoleKeyInfo [] _cki = null; - volatile static bool _isEscSeq; - bool _stopTasks; + ConsoleKeyInfo [] _cki; + bool _isEscSeq; + CancellationTokenSource _cancellationTokenSource; + CancellationToken _cancellationToken; + #if PROCESS_REQUEST bool _neededProcessRequest; #endif @@ -120,19 +122,16 @@ internal class NetEvents { public NetEvents (ConsoleDriver consoleDriver) { _consoleDriver = consoleDriver ?? throw new ArgumentNullException (nameof (consoleDriver)); + _cancellationTokenSource = new CancellationTokenSource (); + _cancellationToken = _cancellationTokenSource.Token; Task.Run (ProcessInputResultQueue); Task.Run (CheckWindowSizeChange); } - internal void StopTasks () - { - _stopTasks = true; - } - public InputResult? ReadConsoleInput () { while (true) { - if (_stopTasks) { + if (_cancellationToken.IsCancellationRequested) { return null; } _waitForStart.Set (); @@ -151,6 +150,24 @@ internal class NetEvents { } } + static ConsoleKeyInfo ReadConsoleKeyInfo (CancellationToken cancellationToken, bool intercept = true) + { + // if there is a key available, return it without waiting + // (or dispatching work to the thread queue) + if (Console.KeyAvailable) { + return Console.ReadKey (intercept); + } + + while (!cancellationToken.IsCancellationRequested) { + Task.Delay (100); + if (Console.KeyAvailable) { + return Console.ReadKey (intercept); + } + } + cancellationToken.ThrowIfCancellationRequested (); + return default; + } + void ProcessInputResultQueue () { while (true) { @@ -163,9 +180,18 @@ internal class NetEvents { ConsoleKeyInfo newConsoleKeyInfo = default; while (true) { - ConsoleKeyInfo consoleKeyInfo = Console.ReadKey (true); + if (_cancellationToken.IsCancellationRequested) { + return; + } + ConsoleKeyInfo consoleKeyInfo; + try { + consoleKeyInfo = ReadConsoleKeyInfo (_cancellationToken, true); + } catch (OperationCanceledException) { + return; + } if ((consoleKeyInfo.KeyChar == (char)Key.Esc && !_isEscSeq) - || (consoleKeyInfo.KeyChar != (char)Key.Esc && _isEscSeq)) { + || (consoleKeyInfo.KeyChar != (char)Key.Esc && _isEscSeq)) { + if (_cki == null && consoleKeyInfo.KeyChar != (char)Key.Esc && _isEscSeq) { _cki = EscSeqUtils.ResizeArray (new ConsoleKeyInfo ((char)Key.Esc, 0, false, false, false), _cki); @@ -179,17 +205,16 @@ internal class NetEvents { _isEscSeq = false; break; } else if (consoleKeyInfo.KeyChar == (char)Key.Esc && _isEscSeq && _cki != null) { - if (_cki != null) { - ProcessRequestResponse (ref newConsoleKeyInfo, ref key, _cki, ref mod); - _cki = null; + ProcessRequestResponse (ref newConsoleKeyInfo, ref key, _cki, ref mod); + _cki = null; + if (Console.KeyAvailable) { + _cki = EscSeqUtils.ResizeArray (consoleKeyInfo, _cki); + } else { + ProcessMapConsoleKeyInfo (consoleKeyInfo); } break; } else { - _inputResultQueue.Enqueue (new InputResult { - EventType = EventType.Key, - ConsoleKeyInfo = EscSeqUtils.MapConsoleKeyInfo (consoleKeyInfo) - }); - _isEscSeq = false; + ProcessMapConsoleKeyInfo (consoleKeyInfo); break; } } @@ -197,19 +222,25 @@ internal class NetEvents { _inputReady.Set (); } + + void ProcessMapConsoleKeyInfo (ConsoleKeyInfo consoleKeyInfo) + { + _inputResultQueue.Enqueue (new InputResult { + EventType = EventType.Key, + ConsoleKeyInfo = EscSeqUtils.MapConsoleKeyInfo (consoleKeyInfo) + }); + _isEscSeq = false; + } } void CheckWindowSizeChange () { - void RequestWindowSize () + void RequestWindowSize (CancellationToken cancellationToken) { - while (true) { + while (!cancellationToken.IsCancellationRequested) { // Wait for a while then check if screen has changed sizes - Task.Delay (500).Wait (); + Task.Delay (500, cancellationToken); - if (_stopTasks) { - return; - } int buffHeight, buffWidth; if (((NetDriver)_consoleDriver).IsWinPlatform) { buffHeight = Math.Max (Console.BufferHeight, 0); @@ -227,15 +258,20 @@ internal class NetEvents { return; } } + cancellationToken.ThrowIfCancellationRequested (); } while (true) { - if (_stopTasks) { + if (_cancellationToken.IsCancellationRequested) { return; } _winChange.Wait (); _winChange.Reset (); - RequestWindowSize (); + try { + RequestWindowSize (_cancellationToken); + } catch (OperationCanceledException) { + return; + } _inputReady.Set (); } } @@ -536,6 +572,23 @@ internal class NetEvents { _inputResultQueue.Enqueue (inputResult); } + + public void Dispose () + { + _cancellationTokenSource.Cancel (); + _cancellationTokenSource.Dispose (); + _cancellationTokenSource = null; + FlushIn (); + } + + void FlushIn () + { + // throws away any typeahead that has been typed by + // the user and has not yet been read by the program. + while (Console.KeyAvailable) { + Console.ReadKey (true); + } + } } internal class NetDriver : ConsoleDriver { @@ -563,7 +616,7 @@ internal class NetDriver : ConsoleDriver { public override void End () { - _mainLoop?._netEvents.StopTasks (); + _mainLoop?._netEvents.Dispose (); if (IsWinPlatform) { NetWinConsole?.Cleanup (); @@ -611,7 +664,7 @@ internal class NetDriver : ConsoleDriver { if (!RunningUnitTests) { Console.TreatControlCAsInput = true; - + Cols = Console.WindowWidth; Rows = Console.WindowHeight;