diff --git a/GitVersion.yml b/GitVersion.yml new file mode 100644 index 000000000..f77b10ac2 --- /dev/null +++ b/GitVersion.yml @@ -0,0 +1,50 @@ +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 + + v2_develop: + mode: ContinuousDeployment + tag: pre + regex: ^v2_develop?[/-] + is-release-branch: true + tracks-release-branches: true + is-source-branch-for: ['v2'] + source-branches: [] + v2: + mode: ContinuousDeployment + is-release-branch: false + tag: alpha + increment: Patch + regex: ^v2?[/-] + 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/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; 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/Terminal.Gui/Terminal.Gui.csproj b/Terminal.Gui/Terminal.Gui.csproj index 30592f23d..fc60d1ee6 100644 --- a/Terminal.Gui/Terminal.Gui.csproj +++ b/Terminal.Gui/Terminal.Gui.csproj @@ -1,39 +1,61 @@  + + + + + + + 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 +66,9 @@ \ + + + True @@ -57,17 +82,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 +109,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/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", 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" } }