diff --git a/.github/workflows/dotnet-core.yml b/.github/workflows/dotnet-core.yml index 750f7d93f..2cf7c9339 100644 --- a/.github/workflows/dotnet-core.yml +++ b/.github/workflows/dotnet-core.yml @@ -9,32 +9,40 @@ on: branches: [ v1_release, v1_develop ] paths-ignore: - '**.md' - jobs: - build: - runs-on: ubuntu-latest + non_parallel_unittests: + name: Non-Parallel Unit Tests + runs-on: ${{ matrix.os }} + strategy: + # Turn off fail-fast to let all runners run even if there are errors + fail-fast: true + matrix: + os: [ ubuntu-latest ] + timeout-minutes: 10 steps: - - uses: actions/checkout@v4 + + - name: Checkout code + uses: actions/checkout@v4 - name: Setup .NET Core uses: actions/setup-dotnet@v4 with: - dotnet-version: 7.0 + dotnet-version: 8.x dotnet-quality: 'ga' - name: Install dependencies run: | dotnet restore - - name: Build Debug - run: | - dotnet build --configuration Debug --no-restore + - name: Build Solution Debug + run: dotnet build --configuration Debug --no-restore - name: Test run: | - sed -i 's/"stopOnFail": false/"stopOnFail": true/g' UnitTests/xunit.runner.json - dotnet test --no-restore --verbosity normal #--collect:"XPlat Code Coverage" --settings UnitTests/coverlet.runsettings + #sed -i 's/"stopOnFail": false/"stopOnFail": true/g' UnitTests/xunit.runner.json + dotnet test --no-restore --verbosity normal + #--collect:"XPlat Code Coverage" --settings UnitTests/coverlet.runsettings #mv -v UnitTests/TestResults/*/*.* UnitTests/TestResults/ # Note: this step is currently not writing to the gist for some reason diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 39ba8ccd5..6d5fac6b6 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -2,7 +2,7 @@ name: Publish Terminal.Gui on: push: - branches: [ v1_release, v1_develop, v2_release, v2_develop ] + branches: [ v1_release, v1_develop ] tags: - v* paths-ignore: @@ -18,35 +18,34 @@ jobs: with: fetch-depth: 0 # fetch-depth is needed for GitVersion - - name: Install GitVersion - uses: gittools/actions/gitversion/setup@v1 - with: - versionSpec: '5.x' - includePrerelease: true - - - name: Determine Version - uses: gittools/actions/gitversion/execute@v1 - with: - useConfigFile: true - #additionalArguments: /b develop - id: gitversion # step id used as reference for output values - - - name: Setup dotnet + - name: Setup .NET Core uses: actions/setup-dotnet@v4 with: - dotnet-version: 8.0 + dotnet-version: 8.x dotnet-quality: 'ga' - + + - name: Install GitVersion + uses: gittools/actions/gitversion/setup@v3.1.11 + with: + versionSpec: '6.0.x' + + - name: Determine Version + uses: gittools/actions/gitversion/execute@v3.1.11 + with: + useConfigFile: true + updateAssemblyInfo: true + id: gitversion # step id used as reference for output values + - name: Install dependencies run: dotnet restore - name: Build Release run: | - dotnet-gitversion /updateprojectfiles - dotnet build --no-restore -c Release + dotnet build Terminal.Gui/Terminal.Gui.csproj --no-incremental --nologo --force --configuration Release + dotnet test Terminal.Gui/Terminal.Gui.csproj --configuration Release - name: Pack - run: dotnet pack -c Release --include-symbols -p:Version='${{ steps.gitversion.outputs.SemVer }}' + run: dotnet pack Terminal.Gui/Terminal.Gui.csproj -c Release --include-symbols -p:Version='${{ steps.gitversion.outputs.SemVer }}' # - name: Test to generate Code Coverage Report # run: | @@ -71,4 +70,4 @@ jobs: # echo "Badge data: ${{steps.create_coverage_badge.outputs.badge}}" - name: Publish to NuGet.org - run: dotnet nuget push Terminal.Gui/bin/Release/Terminal.Gui.${{ steps.gitversion.outputs.SemVer }}.nupkg --api-key ${{ secrets.NUGET_API_KEY }} + run: dotnet nuget push Terminal.Gui/bin/Release/Terminal.Gui.${{ steps.gitversion.outputs.SemVer }}.nupkg --api-key ${{ secrets.NUGET_API_KEY }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 6c06d23ff..e2b23118e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,24 +1,70 @@ -bin -obj -~$* -*.userprefs -*~ -packages -.vs -# User-specific files +# Build artifacts +[Bb]in/ +[Oo]bj/ +[Rr]elease/ +[Dd]ebug/ +[Xx]64/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ + +# User-local settings and caches +*.rsuser +*.suo *.user +*.userosscache +*.sln.docstates +*.userprefs +_ReSharper.** +*.[Rr]e[Ss]harper +*.DotSettings.user +.devcontainer/ +.vscode/ +.vs/ + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Roslyn generated cs files +**.g.cs + +# Common temporary files +~$* +*~ + +# Exclude everything in packages directory except the packages/build directory +**/[Pp]ackages/* +!**/[Pp]ackages/build/ # API Docs docfx/api docfx/_site +# Test Results UnitTests/TestResults +TestResults -#git merge files +# git merge files *.orig - -.vscode/ +*.theirs +*.ours demo.* *.deb + +*.tui/ + +*.dotCover + +logs/ + +BenchmarkDotNet.Artifacts/ + +*.log + +*.log.* + +log.* diff --git a/GitVersion.yml b/GitVersion.yml index 138dc2ac9..5c97c6a86 100644 --- a/GitVersion.yml +++ b/GitVersion.yml @@ -1,29 +1,88 @@ -mode: ContinuousDeployment +# This file configures GitVersion 6.x to work with Terminal.Gui's GitFlow branching strategy. +# +# Terminal.Gui uses the GitFlow branching strategy. +# https://gitversion.net/docs/learn/branching-strategies/gitflow/ +# +# - We have two main branches: `v1_release` and `v1_develop`. +# - `v1_release` is the main branch for V1 releases and matches the latest NuGet release package (e.g., 1.0.0); +# prior to release, it uses pre-release labels (e.g., 1.0.0-prealpha.1). +# - `v1_develop` is the development branch for V2 and always carries a pre-release label (e.g., 1.1.0-develop.1). +# - Development happens on feature branches off `v1_develop`. +# - For releases, we merge feature branches into `v1_develop`, then `v1_develop` into `v1_release`. +# - The ./.github/workflows/publish.yml builds and publishes on pushes to `v1_develop` and `v1_release`. +# +# Branches +# - v1_release: Main branch for V1 (historical) +# - v1_develop: Develop branch for V1 (historical) +# +# Package Naming: +# - from v1_develop: 2.1.0-develop.1 (minor version increments) +# - from v1_release (pre-release): 2.0.0-prealpha.1 or 2.0.0-beta.1 +# - from v1_release (release): 2.0.0 (patch version increments) +# +mode: ContinuousDelivery # GitVersion 6.x uses Mainline mode for GitFlow, focusing on main branch releases + +# We prefix our tags with 'v' or 'V' (e.g., v1.0.0) tag-prefix: '[vV]' -continuous-delivery-fallback-tag: pre + branches: - v1_develop: - mode: ContinuousDeployment - tag: pre - regex: v1_develop - source-branches: - - v1_release - pre-release-weight: 100 - v1_release: - tag: rc + + # V2 Release Branch + main: + # Matches the v1_release branch + regex: ^v1_release$ + # Uses 'prealpha' as pre-release label before official release + label: '' + # Increments patch version (x.y.z+1) on commits increment: Patch - regex: v1_release - source-branches: - - v1_develop - - v1_release - v1_feature: - tag: useBranchName - regex: ^features?[/-] - source-branches: - - v1_develop - - v1_release + # Specifies v1_develop as the source branch + source-branches: ['develop'] + pre-release-weight: 100 + + # V2 Development Branch + develop: + # Matches the v1_develop branch + regex: v1_develop + # Adds 'develop' as pre-release label (e.g., 2.1.0-develop.1) + label: develop + # Increments minor version (x.y+1.z) on commits + increment: Minor + # No source branches specified as this is the root of development + source-branches: [] + # Indicates this branch feeds into release branches + tracks-release-branches: true + + # # V1 Branches - Included for historical reference + # v1_develop: + # regex: v1_develop + # label: v1_develop + # increment: Minor + # source-branches: ['v1_release'] + # # Lower weight keeps V1 pre-releases sorted below V2 + # pre-release-weight: 100 + + # v1_release: + # regex: v1_release + # # Empty label for stable releases + # label: '' + # increment: Patch + # source-branches: ['v1_develop'] + + # Pull Request Branches + # Configures versioning for PRs (e.g., 2.0.0-pr.feature-123.1) pull-request: - tag: PullRequest.{BranchName} + # Matches typical PR branch names + regex: ^(pull|pull\-requests|pr)[/-] + # Uses 'pr' prefix with branch name in the label (e.g., pr.feature-123) + label: pr.{BranchName} + # Inherits increment strategy from source branch increment: Inherit + source-branches: + - develop + - main + # High weight ensures PR versions sort after regular pre-releases + pre-release-weight: 30000 + +# Ignore specific commits if needed (currently empty) ignore: - sha: [] + sha: [] \ No newline at end of file diff --git a/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs b/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs index 3e23b78a5..7ffa43eea 100644 --- a/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs +++ b/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs @@ -97,7 +97,7 @@ namespace Terminal.Gui { this.mainLoop = mainLoop; pipe (wakeupPipes); AddWatch (wakeupPipes [0], Condition.PollIn, ml => { - read (wakeupPipes [1], ignore, (IntPtr)1); + read (wakeupPipes [0], ignore, (IntPtr)1); return true; }); } diff --git a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs index f575de14b..0abcc6024 100644 --- a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs @@ -18,7 +18,6 @@ namespace Terminal.Gui { public const int STD_ERROR_HANDLE = -12; internal IntPtr InputHandle, OutputHandle; - IntPtr ScreenBuffer; readonly uint originalConsoleMode; CursorVisibility? initialCursorVisibility = null; CursorVisibility? currentCursorVisibility = null; @@ -40,47 +39,47 @@ namespace Terminal.Gui { public bool WriteToConsole (Size size, CharInfo [] charInfoBuffer, Coord coords, SmallRect window) { - if (ScreenBuffer == IntPtr.Zero) { - ReadFromConsoleOutput (size, coords, ref window); - } + //if (OutputHandle == IntPtr.Zero) { + // ReadFromConsoleOutput (size, coords, ref window); + //} - return WriteConsoleOutput (ScreenBuffer, charInfoBuffer, coords, new Coord () { X = window.Left, Y = window.Top }, ref window); + return WriteConsoleOutput (OutputHandle, charInfoBuffer, coords, new Coord () { X = window.Left, Y = window.Top }, ref window); } - public void ReadFromConsoleOutput (Size size, Coord coords, ref SmallRect window) - { - ScreenBuffer = CreateConsoleScreenBuffer ( - DesiredAccess.GenericRead | DesiredAccess.GenericWrite, - ShareMode.FileShareRead | ShareMode.FileShareWrite, - IntPtr.Zero, - 1, - IntPtr.Zero - ); - if (ScreenBuffer == INVALID_HANDLE_VALUE) { - var err = Marshal.GetLastWin32Error (); + //public void ReadFromConsoleOutput (Size size, Coord coords, ref SmallRect window) + //{ + // OutputHandle = CreateConsoleScreenBuffer ( + // DesiredAccess.GenericRead | DesiredAccess.GenericWrite, + // ShareMode.FileShareRead | ShareMode.FileShareWrite, + // IntPtr.Zero, + // 1, + // IntPtr.Zero + // ); + // if (ScreenBuffer == INVALID_HANDLE_VALUE) { + // var err = Marshal.GetLastWin32Error (); - if (err != 0) - throw new System.ComponentModel.Win32Exception (err); - } + // if (err != 0) + // throw new System.ComponentModel.Win32Exception (err); + // } - if (!initialCursorVisibility.HasValue && GetCursorVisibility (out CursorVisibility visibility)) { - initialCursorVisibility = visibility; - } + // if (!initialCursorVisibility.HasValue && GetCursorVisibility (out CursorVisibility visibility)) { + // initialCursorVisibility = visibility; + // } - if (!SetConsoleActiveScreenBuffer (ScreenBuffer)) { - throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error ()); - } + // if (!SetConsoleActiveScreenBuffer (ScreenBuffer)) { + // throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error ()); + // } - OriginalStdOutChars = new CharInfo [size.Height * size.Width]; + // OriginalStdOutChars = new CharInfo [size.Height * size.Width]; - if (!ReadConsoleOutput (ScreenBuffer, OriginalStdOutChars, coords, new Coord () { X = 0, Y = 0 }, ref window)) { - throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error ()); - } - } + // if (!ReadConsoleOutput (ScreenBuffer, OriginalStdOutChars, coords, new Coord () { X = 0, Y = 0 }, ref window)) { + // throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error ()); + // } + //} public bool SetCursorPosition (Coord position) { - return SetConsoleCursorPosition (ScreenBuffer, position); + return SetConsoleCursorPosition (OutputHandle, position); } public void SetInitialCursorVisibility () @@ -92,11 +91,11 @@ namespace Terminal.Gui { public bool GetCursorVisibility (out CursorVisibility visibility) { - if (ScreenBuffer == IntPtr.Zero) { + if (OutputHandle == IntPtr.Zero) { visibility = CursorVisibility.Invisible; return false; } - if (!GetConsoleCursorInfo (ScreenBuffer, out ConsoleCursorInfo info)) { + if (!GetConsoleCursorInfo (OutputHandle, out ConsoleCursorInfo info)) { var err = Marshal.GetLastWin32Error (); if (err != 0) { throw new System.ComponentModel.Win32Exception (err); @@ -149,7 +148,7 @@ namespace Terminal.Gui { bVisible = ((uint)visibility & 0xFF00) != 0 }; - if (!SetConsoleCursorInfo (ScreenBuffer, ref info)) + if (!SetConsoleCursorInfo (OutputHandle, ref info)) return false; currentCursorVisibility = visibility; @@ -165,28 +164,28 @@ namespace Terminal.Gui { } ConsoleMode = originalConsoleMode; - if (!SetConsoleActiveScreenBuffer (OutputHandle)) { - var err = Marshal.GetLastWin32Error (); - Console.WriteLine ("Error: {0}", err); - } + //if (!SetConsoleActiveScreenBuffer (OutputHandle)) { + // var err = Marshal.GetLastWin32Error (); + // Console.WriteLine ("Error: {0}", err); + //} - if (ScreenBuffer != IntPtr.Zero) { - CloseHandle (ScreenBuffer); - } + //if (ScreenBuffer != IntPtr.Zero) { + // CloseHandle (ScreenBuffer); + //} - ScreenBuffer = IntPtr.Zero; + //ScreenBuffer = IntPtr.Zero; } internal Size GetConsoleBufferWindow (out Point position) { - if (ScreenBuffer == IntPtr.Zero) { + if (OutputHandle == IntPtr.Zero) { position = Point.Empty; return Size.Empty; } var csbi = new CONSOLE_SCREEN_BUFFER_INFOEX (); csbi.cbSize = (uint)Marshal.SizeOf (csbi); - if (!GetConsoleScreenBufferInfoEx (ScreenBuffer, ref csbi)) { + if (!GetConsoleScreenBufferInfoEx (OutputHandle, ref csbi)) { //throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error ()); position = Point.Empty; return Size.Empty; @@ -212,65 +211,65 @@ namespace Terminal.Gui { return sz; } - internal Size SetConsoleWindow (short cols, short rows) - { - var csbi = new CONSOLE_SCREEN_BUFFER_INFOEX (); - csbi.cbSize = (uint)Marshal.SizeOf (csbi); + //internal Size SetConsoleWindow (short cols, short rows) + //{ + // var csbi = new CONSOLE_SCREEN_BUFFER_INFOEX (); + // csbi.cbSize = (uint)Marshal.SizeOf (csbi); - if (!GetConsoleScreenBufferInfoEx (ScreenBuffer, ref csbi)) { - throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error ()); - } - var maxWinSize = GetLargestConsoleWindowSize (ScreenBuffer); - var newCols = Math.Min (cols, maxWinSize.X); - var newRows = Math.Min (rows, maxWinSize.Y); - csbi.dwSize = new Coord (newCols, Math.Max (newRows, (short)1)); - csbi.srWindow = new SmallRect (0, 0, newCols, newRows); - csbi.dwMaximumWindowSize = new Coord (newCols, newRows); - if (!SetConsoleScreenBufferInfoEx (ScreenBuffer, ref csbi)) { - throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error ()); - } - var winRect = new SmallRect (0, 0, (short)(newCols - 1), (short)Math.Max (newRows - 1, 0)); - if (!SetConsoleWindowInfo (OutputHandle, true, ref winRect)) { - //throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error ()); - return new Size (cols, rows); - } - SetConsoleOutputWindow (csbi); - return new Size (winRect.Right + 1, newRows - 1 < 0 ? 0 : winRect.Bottom + 1); - } + // if (!GetConsoleScreenBufferInfoEx (ScreenBuffer, ref csbi)) { + // throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error ()); + // } + // var maxWinSize = GetLargestConsoleWindowSize (ScreenBuffer); + // var newCols = Math.Min (cols, maxWinSize.X); + // var newRows = Math.Min (rows, maxWinSize.Y); + // csbi.dwSize = new Coord (newCols, Math.Max (newRows, (short)1)); + // csbi.srWindow = new SmallRect (0, 0, newCols, newRows); + // csbi.dwMaximumWindowSize = new Coord (newCols, newRows); + // if (!SetConsoleScreenBufferInfoEx (ScreenBuffer, ref csbi)) { + // throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error ()); + // } + // var winRect = new SmallRect (0, 0, (short)(newCols - 1), (short)Math.Max (newRows - 1, 0)); + // if (!SetConsoleWindowInfo (OutputHandle, true, ref winRect)) { + // //throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error ()); + // return new Size (cols, rows); + // } + // SetConsoleOutputWindow (csbi); + // return new Size (winRect.Right + 1, newRows - 1 < 0 ? 0 : winRect.Bottom + 1); + //} - void SetConsoleOutputWindow (CONSOLE_SCREEN_BUFFER_INFOEX csbi) - { - if (ScreenBuffer != IntPtr.Zero && !SetConsoleScreenBufferInfoEx (ScreenBuffer, ref csbi)) { - throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error ()); - } - } + //void SetConsoleOutputWindow (CONSOLE_SCREEN_BUFFER_INFOEX csbi) + //{ + // if (ScreenBuffer != IntPtr.Zero && !SetConsoleScreenBufferInfoEx (ScreenBuffer, ref csbi)) { + // throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error ()); + // } + //} - internal Size SetConsoleOutputWindow (out Point position) - { - if (ScreenBuffer == IntPtr.Zero) { - position = Point.Empty; - return Size.Empty; - } + //internal Size SetConsoleOutputWindow (out Point position) + //{ + // if (ScreenBuffer == IntPtr.Zero) { + // position = Point.Empty; + // return Size.Empty; + // } - var csbi = new CONSOLE_SCREEN_BUFFER_INFOEX (); - csbi.cbSize = (uint)Marshal.SizeOf (csbi); - if (!GetConsoleScreenBufferInfoEx (ScreenBuffer, ref csbi)) { - throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error ()); - } - var sz = new Size (csbi.srWindow.Right - csbi.srWindow.Left + 1, - Math.Max (csbi.srWindow.Bottom - csbi.srWindow.Top + 1, 0)); - position = new Point (csbi.srWindow.Left, csbi.srWindow.Top); - SetConsoleOutputWindow (csbi); - var winRect = new SmallRect (0, 0, (short)(sz.Width - 1), (short)Math.Max (sz.Height - 1, 0)); - if (!SetConsoleScreenBufferInfoEx (OutputHandle, ref csbi)) { - throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error ()); - } - if (!SetConsoleWindowInfo (OutputHandle, true, ref winRect)) { - throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error ()); - } + // var csbi = new CONSOLE_SCREEN_BUFFER_INFOEX (); + // csbi.cbSize = (uint)Marshal.SizeOf (csbi); + // if (!GetConsoleScreenBufferInfoEx (ScreenBuffer, ref csbi)) { + // throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error ()); + // } + // var sz = new Size (csbi.srWindow.Right - csbi.srWindow.Left + 1, + // Math.Max (csbi.srWindow.Bottom - csbi.srWindow.Top + 1, 0)); + // position = new Point (csbi.srWindow.Left, csbi.srWindow.Top); + // SetConsoleOutputWindow (csbi); + // var winRect = new SmallRect (0, 0, (short)(sz.Width - 1), (short)Math.Max (sz.Height - 1, 0)); + // if (!SetConsoleScreenBufferInfoEx (OutputHandle, ref csbi)) { + // throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error ()); + // } + // if (!SetConsoleWindowInfo (OutputHandle, true, ref winRect)) { + // throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error ()); + // } - return sz; - } + // return sz; + //} //bool ContinueListeningForConsoleEvents = true; @@ -734,7 +733,7 @@ namespace Terminal.Gui { WinConsole = new WindowsConsole (); clipboard = new WindowsClipboard (); - isWindowsTerminal = Environment.GetEnvironmentVariable ("WT_SESSION") != null; + isWindowsTerminal = Environment.GetEnvironmentVariable ("WT_SESSION") != null || Environment.GetEnvironmentVariable ("VSAPPIDNAME") != null; } public override void PrepareToRun (MainLoop mainLoop, Action keyHandler, Action keyDownHandler, Action keyUpHandler, Action mouseHandler) @@ -748,28 +747,28 @@ namespace Terminal.Gui { mLoop.ProcessInput = (e) => ProcessInput (e); - mLoop.WinChanged = (e) => { - ChangeWin (e); - }; + //mLoop.WinChanged = (e) => { + // ChangeWin (e); + //}; } - private void ChangeWin (Size e) - { - var w = e.Width; - if (w == cols - 3 && e.Height < rows) { - w += 3; - } - var newSize = WinConsole.SetConsoleWindow ( - (short)Math.Max (w, 16), (short)Math.Max (e.Height, 0)); + //private void ChangeWin (Size e) + //{ + // var w = e.Width; + // if (w == cols - 3 && e.Height < rows) { + // w += 3; + // } + // var newSize = WinConsole.SetConsoleWindow ( + // (short)Math.Max (w, 16), (short)Math.Max (e.Height, 0)); - left = 0; - top = 0; - cols = newSize.Width; - rows = newSize.Height; - ResizeScreen (); - UpdateOffScreen (); - TerminalResized.Invoke (); - } + // left = 0; + // top = 0; + // cols = newSize.Width; + // rows = newSize.Height; + // ResizeScreen (); + // UpdateOffScreen (); + // TerminalResized.Invoke (); + //} void ProcessInput (WindowsConsole.InputRecord inputEvent) { @@ -893,6 +892,14 @@ namespace Terminal.Gui { case WindowsConsole.EventType.Focus: keyModifiers = null; break; + + case WindowsConsole.EventType.WindowBufferSize: + cols = inputEvent.WindowBufferSizeEvent.size.X; + rows = inputEvent.WindowBufferSizeEvent.size.Y; + + ResizeScreen (); + TerminalResized.Invoke (); + break; } } @@ -1970,7 +1977,21 @@ namespace Terminal.Gui { class WindowsClipboard : ClipboardBase { public WindowsClipboard () { - IsSupported = IsClipboardFormatAvailable (cfUnicodeText); + IsSupported = CheckClipboardIsAvailable (); + } + + private static bool CheckClipboardIsAvailable () + { + // Attempt to open the clipboard + if (OpenClipboard (IntPtr.Zero)) { + // Clipboard is available + // Close the clipboard after use + CloseClipboard (); + + return true; + } + // Clipboard is not available + return false; } public override bool IsSupported { get; } diff --git a/Terminal.Gui/Views/Menu.cs b/Terminal.Gui/Views/Menu.cs index 444f695a6..464fa3b4d 100644 --- a/Terminal.Gui/Views/Menu.cs +++ b/Terminal.Gui/Views/Menu.cs @@ -1238,7 +1238,7 @@ namespace Terminal.Gui { mi = openCurrentMenu.barItems.Children [openCurrentMenu.current]; } else if (openCurrentMenu.barItems.IsTopLevel) { mi = openCurrentMenu.barItems; - } else { + } else if (openCurrentMenu?.current > -1) { mi = openMenu.barItems.Children [openMenu.current]; } MenuOpened?.Invoke (mi); diff --git a/UICatalog/UICatalog.csproj b/UICatalog/UICatalog.csproj index 89dcd4c0c..a05ebdf02 100644 --- a/UICatalog/UICatalog.csproj +++ b/UICatalog/UICatalog.csproj @@ -21,7 +21,7 @@ - + diff --git a/UnitTests/Menus/MenuTests.cs b/UnitTests/Menus/MenuTests.cs index 35b0a18ae..d62b7b709 100644 --- a/UnitTests/Menus/MenuTests.cs +++ b/UnitTests/Menus/MenuTests.cs @@ -219,8 +219,7 @@ Edit View = mCurrent })); Assert.True (menu.IsMenuOpen); - Assert.Equal ("_File", miCurrent.Parent.Title); - Assert.Equal ("_New", miCurrent.Title); + Assert.Null (miCurrent); Assert.True (mCurrent.MouseEvent (new MouseEvent () { X = 1, @@ -229,8 +228,7 @@ Edit View = mCurrent })); Assert.True (menu.IsMenuOpen); - Assert.Equal ("_File", miCurrent.Parent.Title); - Assert.Equal ("_New", miCurrent.Title); + Assert.Null (miCurrent); Assert.True (mCurrent.MouseEvent (new MouseEvent () { X = 1, @@ -239,8 +237,7 @@ Edit View = mCurrent })); Assert.True (menu.IsMenuOpen); - Assert.Equal ("_File", miCurrent.Parent.Title); - Assert.Equal ("_Save", miCurrent.Title); + Assert.Null (miCurrent); // close the menu Assert.True (menu.MouseEvent (new MouseEvent () { @@ -265,8 +262,7 @@ Edit Assert.True (mCurrent.ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ()))); Assert.True (menu.IsMenuOpen); - Assert.Equal ("_File", miCurrent.Parent.Title); - Assert.Equal ("_New", miCurrent.Title); + Assert.Null (miCurrent); // close the menu Assert.True (menu.ProcessHotKey (new KeyEvent (Key.F9, new KeyModifiers ()))); diff --git a/UnitTests/UnitTests.csproj b/UnitTests/UnitTests.csproj index d7e5c2d2a..63f2ba107 100644 --- a/UnitTests/UnitTests.csproj +++ b/UnitTests/UnitTests.csproj @@ -19,10 +19,10 @@ - + - + all runtime; build; native; contentfiles; analyzers; buildtransitive