Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 5, 2025

This PR completes the migration to the modern driver architecture by removing all legacy v1 drivers, eliminating "v2" terminology, and reorganizing the codebase for better maintainability and separation of concerns.

Removed Legacy Drivers (~4,000 lines)

Deleted the following legacy driver directories and all supporting code:

  • Terminal.Gui/Drivers/CursesDriver/ - ncurses-based driver with Unix bindings
  • Terminal.Gui/Drivers/NetDriver/ - Legacy .NET Console driver
  • Terminal.Gui/Drivers/WindowsDriver/ - Legacy Windows Console API driver
  • Associated main loops: UnixMainLoop, NetMainLoop, WindowsMainLoop
  • ncurses bindings (binding.cs, constants.cs, handles.cs)

Reorganized Driver Structure

Moved all files from the V2/ directory into a clean, organized structure:

Terminal.Gui/Drivers/
├── DotNetDriver/      # Cross-platform (was v2net)
├── WindowsDriver/     # Windows-optimized (was v2win)
├── UnixDriver/        # Unix-optimized (was v2unix)
├── FakeDriver/        # Modern test driver
└── [shared files]     # Common infrastructure

Simplified Driver Names

Driver names no longer use "v2" prefix:

  • "v2net""dotnet"
  • "v2win""windows"
  • "v2unix""unix"

Updated Application.GetDriverTypes() to return the new names.

Architecture Simplification

Merged Application Implementations

  • Deleted: ModernApplicationImpl.cs (previously ApplicationV2.cs)
  • Merged: All functionality into ApplicationImpl.cs in the App folder
  • Result: Single implementation class without unnecessary inheritance

Separated Platform-Independent from Platform-Specific Code

Reorganized codebase to clearly separate concerns:

Moved to /App (platform-independent):

  • /App/MainLoop/ - Main loop orchestration (ApplicationMainLoop<T>, MainLoopCoordinator, interfaces)
  • /App/Lifecycle/ - View lifecycle management (ToplevelTransitionManager, interface)
  • /App/NotInitializedException.cs - Application exception type

Remains in /Drivers (platform-specific):

  • Driver implementations (DotNetDriver, WindowsDriver, UnixDriver, FakeDriver)
  • Driver contracts and interfaces (IConsoleInput, IConsoleOutput, IComponentFactory, etc.)
  • Platform utilities (Platform.cs, PlatformDetection.cs)
  • Input/output abstractions (InputProcessor, OutputBase, OutputBuffer)

Clarified MainLoop Architecture

Renamed for clarity:

  • MainLoop.csLegacyMainLoopDriver.cs (marked obsolete, for FakeDriver compatibility)
  • MainLoop<T>ApplicationMainLoop<T> (the modern main application loop)
  • IMainLoop<T>IApplicationMainLoop<T> (interface for main loop)

Result:

  • No more naming confusion between legacy and modern implementations
  • Clear distinction: Legacy v1 driver loop vs modern component factory architecture
  • Comprehensive XML documentation on all main loop classes and interfaces

Removed V2 Terminology

Renamed all classes and types to remove "V2" terminology:

Core Classes:

  • ApplicationV2ApplicationImpl (merged)
  • FakeDriverV2FakeConsoleDriver
  • IFakeDriverV2IFakeConsoleDriver

Test Infrastructure:

  • V2TestDriverTestDriver
  • V2TestDriversTestDrivers
  • V2WinWindows, V2NetDotNet

Modern FakeDriver Implementation

Created a proper modern FakeDriver using the component factory architecture in Terminal.Gui/Drivers/FakeDriver/:

New Files:

  • FakeComponentFactory.cs - Factory for creating fake console components
  • FakeConsoleInput.cs - Fake input that extends ConsoleInput<ConsoleKeyInfo> and supports predefined input
  • FakeConsoleOutput.cs - Fake output that extends OutputBase and captures console output for verification

Architecture:

  • Implements IComponentFactory<ConsoleKeyInfo> pattern like DotNetDriver
  • Can be used by all test projects (not just fluent tests)
  • Supports predefined input for deterministic testing
  • Captures output for verification in tests

The legacy FakeDriver remains in place temporarily for backward compatibility with existing tests.

FakeDriver Testing - All Tests Passing ✅

Added comprehensive test suite for FakeDriver in Tests/UnitTests/ConsoleDrivers/FakeDriverTests.cs:

  • Tests for basic initialization and operation
  • Tests for AutoInitShutdown attribute
  • Tests for SetupFakeDriver attribute
  • Integration tests with views and windows
  • Clipboard tests
  • Error handling tests

Fixed issues:

  1. Application.Top creation - FakeApplicationFactory now creates Application.Top after Init
  2. Clipboard behaviors - ConsoleDriverFacade now respects FakeDriver.FakeBehaviors settings
  3. Driver name - Updated from "v2net" to "dotnet"
  4. Removed hanging tests - Removed 4 legacy FakeDriver tests that used Console.MockKeyPresses and hung indefinitely with modern architecture
  5. Added surrogate sequence tests - Added comprehensive UTF-16 surrogate pair validation tests to NetInputProcessorTests

Result: All 21 FakeDriver tests pass, plus 3 ConsoleDriverTests pass without hanging!

Removed Hanging Tests & Added Proper Coverage

Removed the following tests from ConsoleDriverTests.cs because they:

  • Used legacy FakeDriver patterns (Console.MockKeyPresses) incompatible with modern architecture
  • Hung indefinitely in Application.Run() loops
  • Tested general input/surrogate handling rather than FakeDriver-specific functionality

Removed tests:

  • FakeDriver_MockKeyPresses
  • FakeDriver_Only_Sends_Keystrokes_Through_MockKeyPresses
  • FakeDriver_IsValidInput_Wrong_Surrogate_Sequence
  • FakeDriver_IsValidInput_Correct_Surrogate_Sequence

Added replacement tests in NetInputProcessorTests.cs:

  • ProcessInput_Handles_Valid_Surrogate_Pair - Tests valid high+low surrogate sequences
  • ProcessInput_Handles_Invalid_High_Surrogate_Without_Low - Tests incomplete high surrogate
  • ProcessInput_Handles_Invalid_Low_Surrogate_Without_High - Tests orphaned low surrogate
  • ProcessInput_Handles_Invalid_Reversed_Surrogates - Tests reversed surrogate order

The new tests properly validate UTF-16 surrogate pair handling in the input processor layer where this logic actually resides.

Test Organization

Moved test files from Tests/UnitTests/ConsoleDrivers/V2/ to appropriate locations:

Moved to Application folder:

  • ApplicationV2Tests.csApplicationImplTests.cs
  • MainLoopCoordinatorTests.cs
  • MainLoopTTests.cs

Moved to ConsoleDrivers folder:

  • ConsoleInputTests.cs
  • MouseInterpreterTests.cs
  • NetInputProcessorTests.cs
  • WindowSizeMonitorTests.cs
  • WindowsInputProcessorTests.cs

Extracted Utilities

Created helper classes to support the reorganization:

  • WindowsKeyHelper - Static key conversion utilities extracted from legacy WindowsDriver
  • PlatformDetection - WSL and platform detection utilities
  • Reorganized clipboard implementations into driver-specific directories

Updated Documentation

  • docfx/docs/drivers.md - Removed legacy driver documentation, added modern driver info
  • XML documentation in Application.Driver.cs, ApplicationImpl.cs, Application.Initialization.cs
  • Updated ForceDriver documentation to reflect new driver names
  • Enhanced XML documentation for MainLoop classes with comprehensive descriptions

Breaking Changes

For code using legacy drivers directly:

  • new CursesDriver(), new NetDriver(), new WindowsDriver() will no longer compile
  • Use Application.ForceDriver = "dotnet"/"windows"/"unix" instead

For code using v2 driver names:

  • "v2net""dotnet"
  • "v2win""windows"
  • "v2unix""unix"

Most applications using Application.Init() without specifying a driver will be unaffected - the framework automatically selects the appropriate driver for the platform.

Testing

  • ✅ Solution builds with 0 errors
  • ✅ All 21 FakeDriver tests pass
  • ✅ All 3 ConsoleDriverTests pass (no hanging)
  • ✅ All 4 new surrogate sequence tests pass in NetInputProcessorTests
  • ✅ Basic application initialization tests pass

Summary

This PR removes ~4,000 lines of legacy code, eliminates all "V2" terminology, clarifies the MainLoop architecture with better naming and documentation, and creates a cleaner separation between platform-independent application infrastructure (/App) and platform-specific driver implementations (/Drivers). The modern component factory architecture is now the only architecture, with three production drivers (dotnet, windows, unix) and a fully functional modern fake driver for testing.

Fixes #4245

Original prompt

This section details on the original issue you should resolve

<issue_title>Remove CursesDriver, NetDriver, WindowsDriver, and legacy Application code and code that v2win/v2net introduced that wraps that legacy</issue_title>
<issue_description>From what I can see, there's no need for the 3 legacy drivers or the legacy Application code at this point. v2win and v2net seem pretty baked (see #4125 for remaining issues).

We should remove CursesDriver, NetDriver, WindowsDriver, and legacy Application code and code that v2wi n/v2net introduced that wraps that legacy ASAP.

This means we should also reorganize all the code in the V2 folder to be more structured an maintainable. No need to keep any "v2" terminology.

Image

</issue_description>

<agent_instructions>Carefully review the current codebase and this PR and develop a plan for it. When done, there should be 3 drivers: pure dotnet (v2net), windows optimized (v2win), and unix optimized (v2unix). The names of these drivers when done should be "dotnet", "windows", and "unix". When done all vestiages of the v1 drivers and architecture should be gone from the project. </agent_instructions>

Comments on the Issue (you are @copilot in this section)

@tig @tznind I started looking into this and I just go confused. I think you should be able to this much more quickly than I. @tig > Ok I'll see what I can do! > > Its going to be some major surgery.

But you do agree it needs to be done, right? Is there something I'm missing where the legacy code needs to still exist?</comment_new>
<comment_new>@tig
@tznind I'd be willing to help with this? Is there part of it you'd like to sub out to me?</comment_new>

Fixes #4245

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 5 commits October 5, 2025 18:56
Co-authored-by: tig <585482+tig@users.noreply.github.com>
Co-authored-by: tig <585482+tig@users.noreply.github.com>
Co-authored-by: tig <585482+tig@users.noreply.github.com>
Co-authored-by: tig <585482+tig@users.noreply.github.com>
Co-authored-by: tig <585482+tig@users.noreply.github.com>
Copilot AI changed the title [WIP] Remove CursesDriver, NetDriver, WindowsDriver, and legacy Application code and code that v2win/v2net introduced that wraps that legacy Remove legacy drivers (CursesDriver, NetDriver, WindowsDriver) and finalize v2 architecture Oct 5, 2025
Copilot AI requested a review from tig October 5, 2025 19:13
Copilot finished work on behalf of tig October 5, 2025 19:13
@tig
Copy link
Collaborator

tig commented Oct 5, 2025

@copilot Unit tests are failing

Co-authored-by: tig <585482+tig@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 5, 2025

@copilot Unit tests are failing

Fixed several test failures in commit a5e3b8c:

  1. Fixed component factory driver selection to prioritize factory type over driver name
  2. Added legacy driver fallback support for FakeDriver in tests
  3. Changed NotInitializedException to inherit from InvalidOperationException
  4. Updated test expectations to match new exception types

Key tests now passing: Init_NoParam_ForceDriver_Works, Run_t_Does_Not_Creates_Top_Without_Init

Some tests may still fail due to the architectural changes from legacy drivers to v2 - these will need further investigation if they're critical.

Copilot finished work on behalf of tig October 5, 2025 19:49
@tig
Copy link
Collaborator

tig commented Oct 5, 2025

@copilot I've pushed some changes. Many unit tests fail; esp those that depend on FakeDriver. Before working on that, please move the V2Application tests that are in UnitTestse/ConsoleDrivers out of that folder into the proper place.

@tig
Copy link
Collaborator

tig commented Oct 5, 2025

@copilot In the current code, what is the distinction between the Application and Applicationv2 class? Why do both still exist?

Co-authored-by: tig <585482+tig@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 5, 2025

@copilot I've pushed some changes. Many unit tests fail; esp those that depend on FakeDriver. Before working on that, please move the V2Application tests that are in UnitTestse/ConsoleDrivers out of t...

Moved all test files from Tests/UnitTests/ConsoleDrivers/V2/ in commit 7844f1e:

Application tests (moved to Tests/UnitTests/Application/):

  • ApplicationV2Tests.cs
  • MainLoopCoordinatorTests.cs
  • MainLoopTTests.cs

Driver tests (moved to Tests/UnitTests/ConsoleDrivers/):

  • ConsoleInputTests.cs
  • MouseInterpreterTests.cs
  • NetInputProcessorTests.cs
  • WindowSizeMonitorTests.cs
  • WindowsInputProcessorTests.cs

All namespaces updated and V2 subfolder removed. Build succeeds with 0 errors.

Copilot finished work on behalf of tig October 5, 2025 23:51
Copy link
Contributor Author

Copilot AI commented Oct 5, 2025

@copilot In the current code, what is the distinction between the Application and Applicationv2 class? Why do both still exist?

Application is a static class that serves as the public API gateway for the entire Terminal.Gui framework. It contains all the static methods and properties (like Application.Init(), Application.Run(), Application.Top, etc.) that developers use.

ApplicationImpl is the base implementation class that provides the actual functionality behind those static methods. It implements the IApplication interface.

ApplicationV2 extends ApplicationImpl and provides the modern driver architecture using component factories (DotNetDriver, WindowsDriver, UnixDriver).

The key connection: ApplicationImpl._lazyInstance is initialized with new ApplicationV2() (line 13 in ApplicationImpl.cs), making ApplicationV2 the default implementation. When you call static methods like Application.Init(), they delegate to ApplicationImpl.Instance.Init(), which is actually ApplicationV2.

Both exist because:

  • Application (static) = public API surface
  • ApplicationImpl = base implementation with extensibility point
  • ApplicationV2 = modern implementation that replaced the legacy driver architecture

The legacy drivers (CursesDriver, NetDriver, WindowsDriver) used ApplicationImpl directly, while the new architecture uses ApplicationV2 as the default.

Copilot finished work on behalf of tig October 5, 2025 23:54
@tig
Copy link
Collaborator

tig commented Oct 5, 2025

@copilot In the current code, what is the distinction between the Application and Applicationv2 class? Why do both still exist?

tig added 2 commits October 13, 2025 11:12
Updated `FakeDriver` to set `RunningUnitTests` to `true` and initialize dimensions using `FakeConsole`. Modified `TestRespondersDisposedAttribute` to set `ConsoleDriver.RunningUnitTests` in the `Before` method, ensuring proper behavior during unit tests.

Temporarily disabled the `Button_CanFocus_False_Raises_Accepted_Correctly` test in `ViewCommandTests` by adding a `Skip` parameter to the `[Fact]` attribute, referencing issue #4270.
@tig
Copy link
Collaborator

tig commented Oct 14, 2025

@tznind Just pushed some fixes that enable all unit tests to pass reliably locally, but still seeing CI/CD failures.

There's some weridness in there still for sure, and I'm eager to get this merged so we can move on.

I can't see why the non-par tests are failing in CI/CD. Frustrating.

I'll keep poking at it, but keyboarding continues to be painful. 😒

tig added 2 commits October 14, 2025 08:46
Modified the `dotnet test` command in the `Run UnitTestsParallelizable` step to set `xunit.stopOnFail` to `false`. This ensures that the test runner does not stop execution on the first failure, allowing all tests to execute regardless of individual test outcomes.
Refactored `ClearContents_Called_When_Top_Frame_Changes` test:
- Added `[AutoInitShutdown]` attribute for automatic lifecycle management.
- Replaced manual `Application.Init` and `Application.Top` setup with `Application.Begin` and `RunState`.
- Simplified event handling by defining `ClearedContents` handler inline.
- Removed explicit cleanup logic, relying on `Application.End` for teardown.

Updated `using` directives to include `UnitTests` namespace.
@tig
Copy link
Collaborator

tig commented Oct 14, 2025

All passed! I'm skeptcial tho.

@BDisp
Copy link
Collaborator

BDisp commented Oct 14, 2025

The reason why the ClearContents_Called_When_Top_Frame_Changes unit test is failing is because the static ClearScreenNextIteration property is set to true when Application.TopLevels.Count == 1 in the View.Layout.cs and thus the Assert.Equal (0, clearedContentsRaised); fail. With your fix calling the Application.Begin before the first call to Application.LayoutAndDraw (); ensure that layout isn't needed and thus the asserting pass. Good catch.

tig added 4 commits October 14, 2025 09:47
Update ApplicationImpl initialization parameter

Changed the second parameter of the `impl.Init` method in the
`FakeApplicationFactory` class from `"dotnet"` to `"fake"`.
Updated the `dotnet test` command in `unit-tests.yml` to set the `xunit.stopOnFail` parameter to `true`. This change ensures that test execution halts immediately upon encountering a failure, allowing quicker identification and resolution of issues. Note that this may prevent the full test suite from running in the event of a failure.
Updated `unit-tests.yml` to set `xunit.stopOnFail` to `false`
in both `Run UnitTests` and `Run UnitTestsParallelizable`
steps. This ensures that the test runner does not stop
execution on the first test failure, allowing all tests
to complete even if some fail.
@tig
Copy link
Collaborator

tig commented Oct 14, 2025

@tznind & @BDisp please pull this down and see if you can get any of the unit tests to fail. Thanks.

@tig
Copy link
Collaborator

tig commented Oct 15, 2025

Gonna do one more commit to this to force another test pass...

tig added 7 commits October 15, 2025 12:06
Updated the `<remarks>` section in `RuneExtensions.GetColumns` to include details about the `wcwidth` implementation and improved readability with `<para>` tags. Added `wcwidth` to the user dictionary in `Terminal.sln.DotSettings` to avoid spelling errors.
Updated the remarks section of the `GetColumns` method in the
`RuneExtensions` class to enhance readability by reformatting
and properly indenting `<para>` tags. The content remains
unchanged, describing the method's implementation via `wcwidth`
and its role as a Terminal.Gui extension for `System.Text.Rune`.
Replaced legacy drivers (`CursesDriver`, `NetDriver`) with
`UnixDriver` and `DotNetDriver` across the codebase, including
comments, method names, and test cases. Updated documentation
and remarks to reflect the new driver names and platforms.

Revamped clipboard handling with new platform-specific
implementations: `UnixClipboard` for Unix, `MacOSXClipboard`
for macOS, and `WSLClipboard` for Linux under WSL. Removed
the old `CursesClipboard` and consolidated clipboard logic.

Updated test cases to align with the new drivers and clipboard
implementations. Improved naming consistency and cleaned up
redundant code. Updated the README and documentation to
reflect these changes.
This commit removes the `PlatformColor` property from the `Attribute` struct, simplifying the codebase by eliminating platform-specific color handling. The following changes were made:

- Removed `PlatformColor` from the `Attribute` struct, including its initialization, usage, and related comments.
- Updated constructors to no longer initialize or use `PlatformColor`.
- Modified `Equals` and `GetHashCode` methods to exclude `PlatformColor`.
- Updated `UnixComponentFactory` documentation to remove references to "v2unix."
- Renamed `v2TestDriver` to `testDriver` in the `With` class for clarity.
- Removed `PlatformColor` references in `DriverAssert` and related error messages.
- Deleted test cases in `AttributeTests` that relied on `PlatformColor`.
- Cleaned up comments and TODOs related to `PlatformColor` and `UnixDriver`.

These changes reflect a shift away from platform-dependent color management, improving code clarity and reducing complexity.

Remove `PlatformColor` and simplify `Attribute` logic

The `PlatformColor` property has been removed from the `Attribute` struct, along with its associated logic, simplifying the codebase and eliminating platform-specific dependencies. Constructors, equality checks, and hash code generation in `Attribute` have been updated accordingly.

The `CurrentAttribute` property in `ConsoleDriver` and `OutputBuffer` has been simplified, removing dependencies on `Application.Driver`. The `MakeColor` method logic has been removed or simplified in related classes.

Tests in `AttributeTests` have been refactored to reflect these changes, focusing on `Foreground`, `Background`, and `Style`. Unix-specific logic tied to `PlatformColor` has been eliminated.

Additional updates include renaming parameters in the `With` class for clarity, simplifying `DriverAssert` output, and performing minor code cleanups to improve readability and maintainability.
Updated documentation to reflect the new modular driver architecture in Terminal.Gui v2.

- Revised `namespace-drivers.md` to include new components (`IConsoleInput`, `IConsoleOutput`, `IInputProcessor`, `IOutputBuffer`, `IWindowSizeMonitor`) and terminal size monitoring.
- Replaced "Key Components" with "Architecture Overview" and added details on the **Component Factory** pattern.
- Documented the four driver implementations (`DotNetDriver`, `WindowsDriver`, `UnixDriver`, `FakeDriver`) and their platform-specific optimizations.
- Added a "Threading Model" section to explain the multi-threaded design for responsive input handling.
- Updated examples to demonstrate driver capabilities and explicit driver selection.

In `drivers.md`:
- Expanded the "Overview" to emphasize the modular, component-based architecture.
- Reorganized "Drivers" into "Available Drivers" and added details on `FakeDriver` for unit testing.
- Added sections on "Initialization Flow," "Shutdown Flow," and platform-specific driver details.
- Provided examples for accessing driver components and creating custom drivers.

In `index.md`:
- Updated "Cross Platform" feature to reflect new driver names and clarified compatibility with SSH and monochrome terminals.
@tig tig merged commit 2be8397 into v2_develop Oct 15, 2025
11 checks passed
@tig tig deleted the copilot/fix-b6590cf0-cec4-462a-98d6-a1f9b6313715 branch October 15, 2025 19:24
BDisp pushed a commit to BDisp/Terminal.Gui that referenced this pull request Oct 15, 2025
… structure (gui-cs#4270)

* Initial plan

* Remove legacy drivers and reorganize v2 architecture

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Extract Windows key helper utilities and fix build

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Fix all test references to legacy drivers

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Update documentation to reflect new driver architecture

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Remove V2.cd diagram file

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Fix test failures: support legacy drivers and update exception handling

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* updated driver names

* Move V2 tests from ConsoleDrivers/V2 to proper locations

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Rename ApplicationV2 to ModernApplicationImpl to remove v2 terminology

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Remove V2 terminology from test drivers and FakeDriver classes

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Merge ModernApplicationImpl into ApplicationImpl and move to App folder

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Create modern FakeDriver with component factory architecture in Terminal.Gui project

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Refactor: Move non-platform-dependent code from /Drivers to /App

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Code cleanup and org

* Unit test reorg

* Refactor MainLoop architecture: rename classes and enhance documentation for clarity

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Add comprehensive FakeDriver tests (WIP - some tests need fixes)

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Fixed FakeDriver build failures

* Fix all FakeDriver test failures - Application.Top creation and clipboard behaviors

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Fixed FakeDriver build failures2

* Remove hanging legacy FakeDriver tests that use Console.MockKeyPresses

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Fixed some tests

* Fixed more tests

* Fixed more tests

* Fix bad copilot (gui-cs#4277)

* Update Terminal.Gui/Drivers/FakeDriver/FakeConsoleOutput.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Refactor Application Init and Update Tests

Refactored `Application.Init` to improve initialization logic:
- Added fallback to `ForceDriver` when `driverName` is null.
- Changed repeated `Init` calls to throw `InvalidOperationException`.
- Updated `_driverName` assignment logic for robustness.

Enhanced `IConsoleDriver` with detailed remarks on implementations.

Revised test cases to align with updated `Application.Init` behavior:
- Replaced `FakeDriver` with `null` and `driverName: "fake"`.
- Skipped or commented out tests incompatible with new logic.
- Improved formatting and removed redundant setup code.

Improved code style and consistency across the codebase:
- Standardized parameter formatting and spacing.
- Removed outdated comments and unused code.

General cleanup to enhance readability and maintainability.

* Warp fix copilot (gui-cs#4278)

* More fixes (gui-cs#4279)

* Fixes/works around test failures and temporarily disable failing test

Updated `FakeDriver` to set `RunningUnitTests` to `true` and initialize dimensions using `FakeConsole`. Modified `TestRespondersDisposedAttribute` to set `ConsoleDriver.RunningUnitTests` in the `Before` method, ensuring proper behavior during unit tests.

Temporarily disabled the `Button_CanFocus_False_Raises_Accepted_Correctly` test in `ViewCommandTests` by adding a `Skip` parameter to the `[Fact]` attribute, referencing issue gui-cs#4270.

* Allow all tests to run despite failures in UnitTests

Modified the `dotnet test` command in the `Run UnitTestsParallelizable` step to set `xunit.stopOnFail` to `false`. This ensures that the test runner does not stop execution on the first failure, allowing all tests to execute regardless of individual test outcomes.

* Refactor ApplicationScreenTests for cleaner setup/teardown

Refactored `ClearContents_Called_When_Top_Frame_Changes` test:
- Added `[AutoInitShutdown]` attribute for automatic lifecycle management.
- Replaced manual `Application.Init` and `Application.Top` setup with `Application.Begin` and `RunState`.
- Simplified event handling by defining `ClearedContents` handler inline.
- Removed explicit cleanup logic, relying on `Application.End` for teardown.

Updated `using` directives to include `UnitTests` namespace.

* Attempt to fix intermittent local test failures.

Update ApplicationImpl initialization parameter

Changed the second parameter of the `impl.Init` method in the
`FakeApplicationFactory` class from `"dotnet"` to `"fake"`.

* Code cleanup to cause Action to re-run.

* Stop tests on first failure in UnitTestsParallelizable

Updated the `dotnet test` command in `unit-tests.yml` to set the `xunit.stopOnFail` parameter to `true`. This change ensures that test execution halts immediately upon encountering a failure, allowing quicker identification and resolution of issues. Note that this may prevent the full test suite from running in the event of a failure.

* Allow all tests to run despite failures in CI

Updated `unit-tests.yml` to set `xunit.stopOnFail` to `false`
in both `Run UnitTests` and `Run UnitTestsParallelizable`
steps. This ensures that the test runner does not stop
execution on the first test failure, allowing all tests
to complete even if some fail.

* Enhance RuneExtensions docs and update user dictionary

Updated the `<remarks>` section in `RuneExtensions.GetColumns` to include details about the `wcwidth` implementation and improved readability with `<para>` tags. Added `wcwidth` to the user dictionary in `Terminal.sln.DotSettings` to avoid spelling errors.

* Improve XML doc formatting in RuneExtensions.cs

Updated the remarks section of the `GetColumns` method in the
`RuneExtensions` class to enhance readability by reformatting
and properly indenting `<para>` tags. The content remains
unchanged, describing the method's implementation via `wcwidth`
and its role as a Terminal.Gui extension for `System.Text.Rune`.

* Refactor drivers and improve clipboard handling

Replaced legacy drivers (`CursesDriver`, `NetDriver`) with
`UnixDriver` and `DotNetDriver` across the codebase, including
comments, method names, and test cases. Updated documentation
and remarks to reflect the new driver names and platforms.

Revamped clipboard handling with new platform-specific
implementations: `UnixClipboard` for Unix, `MacOSXClipboard`
for macOS, and `WSLClipboard` for Linux under WSL. Removed
the old `CursesClipboard` and consolidated clipboard logic.

Updated test cases to align with the new drivers and clipboard
implementations. Improved naming consistency and cleaned up
redundant code. Updated the README and documentation to
reflect these changes.

* Remove `PlatformColor` from `Attribute` struct

This commit removes the `PlatformColor` property from the `Attribute` struct, simplifying the codebase by eliminating platform-specific color handling. The following changes were made:

- Removed `PlatformColor` from the `Attribute` struct, including its initialization, usage, and related comments.
- Updated constructors to no longer initialize or use `PlatformColor`.
- Modified `Equals` and `GetHashCode` methods to exclude `PlatformColor`.
- Updated `UnixComponentFactory` documentation to remove references to "v2unix."
- Renamed `v2TestDriver` to `testDriver` in the `With` class for clarity.
- Removed `PlatformColor` references in `DriverAssert` and related error messages.
- Deleted test cases in `AttributeTests` that relied on `PlatformColor`.
- Cleaned up comments and TODOs related to `PlatformColor` and `UnixDriver`.

These changes reflect a shift away from platform-dependent color management, improving code clarity and reducing complexity.

Remove `PlatformColor` and simplify `Attribute` logic

The `PlatformColor` property has been removed from the `Attribute` struct, along with its associated logic, simplifying the codebase and eliminating platform-specific dependencies. Constructors, equality checks, and hash code generation in `Attribute` have been updated accordingly.

The `CurrentAttribute` property in `ConsoleDriver` and `OutputBuffer` has been simplified, removing dependencies on `Application.Driver`. The `MakeColor` method logic has been removed or simplified in related classes.

Tests in `AttributeTests` have been refactored to reflect these changes, focusing on `Foreground`, `Background`, and `Style`. Unix-specific logic tied to `PlatformColor` has been eliminated.

Additional updates include renaming parameters in the `With` class for clarity, simplifying `DriverAssert` output, and performing minor code cleanups to improve readability and maintainability.

* Refactor Terminal.Gui driver architecture for v2

Updated documentation to reflect the new modular driver architecture in Terminal.Gui v2.

- Revised `namespace-drivers.md` to include new components (`IConsoleInput`, `IConsoleOutput`, `IInputProcessor`, `IOutputBuffer`, `IWindowSizeMonitor`) and terminal size monitoring.
- Replaced "Key Components" with "Architecture Overview" and added details on the **Component Factory** pattern.
- Documented the four driver implementations (`DotNetDriver`, `WindowsDriver`, `UnixDriver`, `FakeDriver`) and their platform-specific optimizations.
- Added a "Threading Model" section to explain the multi-threaded design for responsive input handling.
- Updated examples to demonstrate driver capabilities and explicit driver selection.

In `drivers.md`:
- Expanded the "Overview" to emphasize the modular, component-based architecture.
- Reorganized "Drivers" into "Available Drivers" and added details on `FakeDriver` for unit testing.
- Added sections on "Initialization Flow," "Shutdown Flow," and platform-specific driver details.
- Provided examples for accessing driver components and creating custom drivers.

In `index.md`:
- Updated "Cross Platform" feature to reflect new driver names and clarified compatibility with SSH and monochrome terminals.

* Moved files around

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tig <585482+tig@users.noreply.github.com>
Co-authored-by: Tig <tig@users.noreply.github.com>
Co-authored-by: Thomas Nind <31306100+tznind@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
tig added a commit that referenced this pull request Oct 16, 2025
…e badly using VSDebugConsole.exe (#4275)

* Fixes #4274. Using Windows Host Console v2win is rendering window size badly using VSDebugConsole.exe

* Fixes #4259. Our wcwidth library is out of date (#4281)

* Update package versions and remove hack code from RuneExtensions

Updated several package versions in `Directory.Packages.props`, including `JetBrains.Annotations`, `Microsoft.Extensions.Logging.Abstractions`, `System.IO.Abstractions`, and `Wcwidth`.

Refactored methods in `RuneExtensions.cs`:
- Simplified `GetColumns` by removing special Unicode handling.
- Renamed constants to follow naming conventions.
- Improved logic and readability in `DecodeSurrogatePair`, `Encode`, and `GetEncodingLength`.
- Streamlined `IsSurrogatePair` and `MakePrintable` for clarity and efficiency.

* Update package version ranges for flexibility

Updated the `JetBrains.Annotations` package to use a version range
starting from `2025.2.2` to allow future updates. Adjusted the
`Microsoft.Extensions.Logging.Abstractions` package to a version
range `[9.0.0,10)` for compatibility. Changed `System.IO.Abstractions`
to a range `[22.0.16,23)` and `Wcwidth` to `[3.0.0,)` to enable
future updates within specified ranges.

* Remove legacy drivers, simplify architecture, and reorganize codebase structure (#4270)

* Initial plan

* Remove legacy drivers and reorganize v2 architecture

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Extract Windows key helper utilities and fix build

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Fix all test references to legacy drivers

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Update documentation to reflect new driver architecture

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Remove V2.cd diagram file

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Fix test failures: support legacy drivers and update exception handling

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* updated driver names

* Move V2 tests from ConsoleDrivers/V2 to proper locations

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Rename ApplicationV2 to ModernApplicationImpl to remove v2 terminology

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Remove V2 terminology from test drivers and FakeDriver classes

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Merge ModernApplicationImpl into ApplicationImpl and move to App folder

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Create modern FakeDriver with component factory architecture in Terminal.Gui project

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Refactor: Move non-platform-dependent code from /Drivers to /App

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Code cleanup and org

* Unit test reorg

* Refactor MainLoop architecture: rename classes and enhance documentation for clarity

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Add comprehensive FakeDriver tests (WIP - some tests need fixes)

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Fixed FakeDriver build failures

* Fix all FakeDriver test failures - Application.Top creation and clipboard behaviors

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Fixed FakeDriver build failures2

* Remove hanging legacy FakeDriver tests that use Console.MockKeyPresses

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Fixed some tests

* Fixed more tests

* Fixed more tests

* Fix bad copilot (#4277)

* Update Terminal.Gui/Drivers/FakeDriver/FakeConsoleOutput.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Refactor Application Init and Update Tests

Refactored `Application.Init` to improve initialization logic:
- Added fallback to `ForceDriver` when `driverName` is null.
- Changed repeated `Init` calls to throw `InvalidOperationException`.
- Updated `_driverName` assignment logic for robustness.

Enhanced `IConsoleDriver` with detailed remarks on implementations.

Revised test cases to align with updated `Application.Init` behavior:
- Replaced `FakeDriver` with `null` and `driverName: "fake"`.
- Skipped or commented out tests incompatible with new logic.
- Improved formatting and removed redundant setup code.

Improved code style and consistency across the codebase:
- Standardized parameter formatting and spacing.
- Removed outdated comments and unused code.

General cleanup to enhance readability and maintainability.

* Warp fix copilot (#4278)

* More fixes (#4279)

* Fixes/works around test failures and temporarily disable failing test

Updated `FakeDriver` to set `RunningUnitTests` to `true` and initialize dimensions using `FakeConsole`. Modified `TestRespondersDisposedAttribute` to set `ConsoleDriver.RunningUnitTests` in the `Before` method, ensuring proper behavior during unit tests.

Temporarily disabled the `Button_CanFocus_False_Raises_Accepted_Correctly` test in `ViewCommandTests` by adding a `Skip` parameter to the `[Fact]` attribute, referencing issue #4270.

* Allow all tests to run despite failures in UnitTests

Modified the `dotnet test` command in the `Run UnitTestsParallelizable` step to set `xunit.stopOnFail` to `false`. This ensures that the test runner does not stop execution on the first failure, allowing all tests to execute regardless of individual test outcomes.

* Refactor ApplicationScreenTests for cleaner setup/teardown

Refactored `ClearContents_Called_When_Top_Frame_Changes` test:
- Added `[AutoInitShutdown]` attribute for automatic lifecycle management.
- Replaced manual `Application.Init` and `Application.Top` setup with `Application.Begin` and `RunState`.
- Simplified event handling by defining `ClearedContents` handler inline.
- Removed explicit cleanup logic, relying on `Application.End` for teardown.

Updated `using` directives to include `UnitTests` namespace.

* Attempt to fix intermittent local test failures.

Update ApplicationImpl initialization parameter

Changed the second parameter of the `impl.Init` method in the
`FakeApplicationFactory` class from `"dotnet"` to `"fake"`.

* Code cleanup to cause Action to re-run.

* Stop tests on first failure in UnitTestsParallelizable

Updated the `dotnet test` command in `unit-tests.yml` to set the `xunit.stopOnFail` parameter to `true`. This change ensures that test execution halts immediately upon encountering a failure, allowing quicker identification and resolution of issues. Note that this may prevent the full test suite from running in the event of a failure.

* Allow all tests to run despite failures in CI

Updated `unit-tests.yml` to set `xunit.stopOnFail` to `false`
in both `Run UnitTests` and `Run UnitTestsParallelizable`
steps. This ensures that the test runner does not stop
execution on the first test failure, allowing all tests
to complete even if some fail.

* Enhance RuneExtensions docs and update user dictionary

Updated the `<remarks>` section in `RuneExtensions.GetColumns` to include details about the `wcwidth` implementation and improved readability with `<para>` tags. Added `wcwidth` to the user dictionary in `Terminal.sln.DotSettings` to avoid spelling errors.

* Improve XML doc formatting in RuneExtensions.cs

Updated the remarks section of the `GetColumns` method in the
`RuneExtensions` class to enhance readability by reformatting
and properly indenting `<para>` tags. The content remains
unchanged, describing the method's implementation via `wcwidth`
and its role as a Terminal.Gui extension for `System.Text.Rune`.

* Refactor drivers and improve clipboard handling

Replaced legacy drivers (`CursesDriver`, `NetDriver`) with
`UnixDriver` and `DotNetDriver` across the codebase, including
comments, method names, and test cases. Updated documentation
and remarks to reflect the new driver names and platforms.

Revamped clipboard handling with new platform-specific
implementations: `UnixClipboard` for Unix, `MacOSXClipboard`
for macOS, and `WSLClipboard` for Linux under WSL. Removed
the old `CursesClipboard` and consolidated clipboard logic.

Updated test cases to align with the new drivers and clipboard
implementations. Improved naming consistency and cleaned up
redundant code. Updated the README and documentation to
reflect these changes.

* Remove `PlatformColor` from `Attribute` struct

This commit removes the `PlatformColor` property from the `Attribute` struct, simplifying the codebase by eliminating platform-specific color handling. The following changes were made:

- Removed `PlatformColor` from the `Attribute` struct, including its initialization, usage, and related comments.
- Updated constructors to no longer initialize or use `PlatformColor`.
- Modified `Equals` and `GetHashCode` methods to exclude `PlatformColor`.
- Updated `UnixComponentFactory` documentation to remove references to "v2unix."
- Renamed `v2TestDriver` to `testDriver` in the `With` class for clarity.
- Removed `PlatformColor` references in `DriverAssert` and related error messages.
- Deleted test cases in `AttributeTests` that relied on `PlatformColor`.
- Cleaned up comments and TODOs related to `PlatformColor` and `UnixDriver`.

These changes reflect a shift away from platform-dependent color management, improving code clarity and reducing complexity.

Remove `PlatformColor` and simplify `Attribute` logic

The `PlatformColor` property has been removed from the `Attribute` struct, along with its associated logic, simplifying the codebase and eliminating platform-specific dependencies. Constructors, equality checks, and hash code generation in `Attribute` have been updated accordingly.

The `CurrentAttribute` property in `ConsoleDriver` and `OutputBuffer` has been simplified, removing dependencies on `Application.Driver`. The `MakeColor` method logic has been removed or simplified in related classes.

Tests in `AttributeTests` have been refactored to reflect these changes, focusing on `Foreground`, `Background`, and `Style`. Unix-specific logic tied to `PlatformColor` has been eliminated.

Additional updates include renaming parameters in the `With` class for clarity, simplifying `DriverAssert` output, and performing minor code cleanups to improve readability and maintainability.

* Refactor Terminal.Gui driver architecture for v2

Updated documentation to reflect the new modular driver architecture in Terminal.Gui v2.

- Revised `namespace-drivers.md` to include new components (`IConsoleInput`, `IConsoleOutput`, `IInputProcessor`, `IOutputBuffer`, `IWindowSizeMonitor`) and terminal size monitoring.
- Replaced "Key Components" with "Architecture Overview" and added details on the **Component Factory** pattern.
- Documented the four driver implementations (`DotNetDriver`, `WindowsDriver`, `UnixDriver`, `FakeDriver`) and their platform-specific optimizations.
- Added a "Threading Model" section to explain the multi-threaded design for responsive input handling.
- Updated examples to demonstrate driver capabilities and explicit driver selection.

In `drivers.md`:
- Expanded the "Overview" to emphasize the modular, component-based architecture.
- Reorganized "Drivers" into "Available Drivers" and added details on `FakeDriver` for unit testing.
- Added sections on "Initialization Flow," "Shutdown Flow," and platform-specific driver details.
- Provided examples for accessing driver components and creating custom drivers.

In `index.md`:
- Updated "Cross Platform" feature to reflect new driver names and clarified compatibility with SSH and monochrome terminals.

* Moved files around

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tig <585482+tig@users.noreply.github.com>
Co-authored-by: Tig <tig@users.noreply.github.com>
Co-authored-by: Thomas Nind <31306100+tznind@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Fix nit test.

* Change ClearScreenNextIteration to internal and trying to fix unit test failure

* Reuse method and fix text field color to normal, probably due some changed configuration

* Fix scenario Shortcut not restoring Application.Quit

* Giving more time to load Scrolling scenario and display failing scenario

* Revert changes and add more assertions

* Forcing CI tests again and I suspect that is causing by UpdateFromJson unit test

* Changed test to force fake driver

* Ensure restore the original colors

* Fix ResetToHardCodedDefaults method

* Tested with this before and the tests pass

* Revert "Tested with this before and the tests pass"

This reverts commit 297b885.

* Revert "Fix ResetToHardCodedDefaults method"

This reverts commit 3a28c5e.

* Trying to fix scenario tests

---------

Co-authored-by: Tig <tig@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tig <585482+tig@users.noreply.github.com>
Co-authored-by: Thomas Nind <31306100+tznind@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
tig added a commit that referenced this pull request Oct 19, 2025
…#4287)

* Fixes #4274. Using Windows Host Console v2win is rendering window size badly using VSDebugConsole.exe

* Fixes #4259. Our wcwidth library is out of date (#4281)

* Update package versions and remove hack code from RuneExtensions

Updated several package versions in `Directory.Packages.props`, including `JetBrains.Annotations`, `Microsoft.Extensions.Logging.Abstractions`, `System.IO.Abstractions`, and `Wcwidth`.

Refactored methods in `RuneExtensions.cs`:
- Simplified `GetColumns` by removing special Unicode handling.
- Renamed constants to follow naming conventions.
- Improved logic and readability in `DecodeSurrogatePair`, `Encode`, and `GetEncodingLength`.
- Streamlined `IsSurrogatePair` and `MakePrintable` for clarity and efficiency.

* Update package version ranges for flexibility

Updated the `JetBrains.Annotations` package to use a version range
starting from `2025.2.2` to allow future updates. Adjusted the
`Microsoft.Extensions.Logging.Abstractions` package to a version
range `[9.0.0,10)` for compatibility. Changed `System.IO.Abstractions`
to a range `[22.0.16,23)` and `Wcwidth` to `[3.0.0,)` to enable
future updates within specified ranges.

* Remove legacy drivers, simplify architecture, and reorganize codebase structure (#4270)

* Initial plan

* Remove legacy drivers and reorganize v2 architecture

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Extract Windows key helper utilities and fix build

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Fix all test references to legacy drivers

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Update documentation to reflect new driver architecture

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Remove V2.cd diagram file

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Fix test failures: support legacy drivers and update exception handling

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* updated driver names

* Move V2 tests from ConsoleDrivers/V2 to proper locations

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Rename ApplicationV2 to ModernApplicationImpl to remove v2 terminology

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Remove V2 terminology from test drivers and FakeDriver classes

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Merge ModernApplicationImpl into ApplicationImpl and move to App folder

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Create modern FakeDriver with component factory architecture in Terminal.Gui project

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Refactor: Move non-platform-dependent code from /Drivers to /App

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Code cleanup and org

* Unit test reorg

* Refactor MainLoop architecture: rename classes and enhance documentation for clarity

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Add comprehensive FakeDriver tests (WIP - some tests need fixes)

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Fixed FakeDriver build failures

* Fix all FakeDriver test failures - Application.Top creation and clipboard behaviors

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Fixed FakeDriver build failures2

* Remove hanging legacy FakeDriver tests that use Console.MockKeyPresses

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Fixed some tests

* Fixed more tests

* Fixed more tests

* Fix bad copilot (#4277)

* Update Terminal.Gui/Drivers/FakeDriver/FakeConsoleOutput.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Refactor Application Init and Update Tests

Refactored `Application.Init` to improve initialization logic:
- Added fallback to `ForceDriver` when `driverName` is null.
- Changed repeated `Init` calls to throw `InvalidOperationException`.
- Updated `_driverName` assignment logic for robustness.

Enhanced `IConsoleDriver` with detailed remarks on implementations.

Revised test cases to align with updated `Application.Init` behavior:
- Replaced `FakeDriver` with `null` and `driverName: "fake"`.
- Skipped or commented out tests incompatible with new logic.
- Improved formatting and removed redundant setup code.

Improved code style and consistency across the codebase:
- Standardized parameter formatting and spacing.
- Removed outdated comments and unused code.

General cleanup to enhance readability and maintainability.

* Warp fix copilot (#4278)

* More fixes (#4279)

* Fixes/works around test failures and temporarily disable failing test

Updated `FakeDriver` to set `RunningUnitTests` to `true` and initialize dimensions using `FakeConsole`. Modified `TestRespondersDisposedAttribute` to set `ConsoleDriver.RunningUnitTests` in the `Before` method, ensuring proper behavior during unit tests.

Temporarily disabled the `Button_CanFocus_False_Raises_Accepted_Correctly` test in `ViewCommandTests` by adding a `Skip` parameter to the `[Fact]` attribute, referencing issue #4270.

* Allow all tests to run despite failures in UnitTests

Modified the `dotnet test` command in the `Run UnitTestsParallelizable` step to set `xunit.stopOnFail` to `false`. This ensures that the test runner does not stop execution on the first failure, allowing all tests to execute regardless of individual test outcomes.

* Refactor ApplicationScreenTests for cleaner setup/teardown

Refactored `ClearContents_Called_When_Top_Frame_Changes` test:
- Added `[AutoInitShutdown]` attribute for automatic lifecycle management.
- Replaced manual `Application.Init` and `Application.Top` setup with `Application.Begin` and `RunState`.
- Simplified event handling by defining `ClearedContents` handler inline.
- Removed explicit cleanup logic, relying on `Application.End` for teardown.

Updated `using` directives to include `UnitTests` namespace.

* Attempt to fix intermittent local test failures.

Update ApplicationImpl initialization parameter

Changed the second parameter of the `impl.Init` method in the
`FakeApplicationFactory` class from `"dotnet"` to `"fake"`.

* Code cleanup to cause Action to re-run.

* Stop tests on first failure in UnitTestsParallelizable

Updated the `dotnet test` command in `unit-tests.yml` to set the `xunit.stopOnFail` parameter to `true`. This change ensures that test execution halts immediately upon encountering a failure, allowing quicker identification and resolution of issues. Note that this may prevent the full test suite from running in the event of a failure.

* Allow all tests to run despite failures in CI

Updated `unit-tests.yml` to set `xunit.stopOnFail` to `false`
in both `Run UnitTests` and `Run UnitTestsParallelizable`
steps. This ensures that the test runner does not stop
execution on the first test failure, allowing all tests
to complete even if some fail.

* Enhance RuneExtensions docs and update user dictionary

Updated the `<remarks>` section in `RuneExtensions.GetColumns` to include details about the `wcwidth` implementation and improved readability with `<para>` tags. Added `wcwidth` to the user dictionary in `Terminal.sln.DotSettings` to avoid spelling errors.

* Improve XML doc formatting in RuneExtensions.cs

Updated the remarks section of the `GetColumns` method in the
`RuneExtensions` class to enhance readability by reformatting
and properly indenting `<para>` tags. The content remains
unchanged, describing the method's implementation via `wcwidth`
and its role as a Terminal.Gui extension for `System.Text.Rune`.

* Refactor drivers and improve clipboard handling

Replaced legacy drivers (`CursesDriver`, `NetDriver`) with
`UnixDriver` and `DotNetDriver` across the codebase, including
comments, method names, and test cases. Updated documentation
and remarks to reflect the new driver names and platforms.

Revamped clipboard handling with new platform-specific
implementations: `UnixClipboard` for Unix, `MacOSXClipboard`
for macOS, and `WSLClipboard` for Linux under WSL. Removed
the old `CursesClipboard` and consolidated clipboard logic.

Updated test cases to align with the new drivers and clipboard
implementations. Improved naming consistency and cleaned up
redundant code. Updated the README and documentation to
reflect these changes.

* Remove `PlatformColor` from `Attribute` struct

This commit removes the `PlatformColor` property from the `Attribute` struct, simplifying the codebase by eliminating platform-specific color handling. The following changes were made:

- Removed `PlatformColor` from the `Attribute` struct, including its initialization, usage, and related comments.
- Updated constructors to no longer initialize or use `PlatformColor`.
- Modified `Equals` and `GetHashCode` methods to exclude `PlatformColor`.
- Updated `UnixComponentFactory` documentation to remove references to "v2unix."
- Renamed `v2TestDriver` to `testDriver` in the `With` class for clarity.
- Removed `PlatformColor` references in `DriverAssert` and related error messages.
- Deleted test cases in `AttributeTests` that relied on `PlatformColor`.
- Cleaned up comments and TODOs related to `PlatformColor` and `UnixDriver`.

These changes reflect a shift away from platform-dependent color management, improving code clarity and reducing complexity.

Remove `PlatformColor` and simplify `Attribute` logic

The `PlatformColor` property has been removed from the `Attribute` struct, along with its associated logic, simplifying the codebase and eliminating platform-specific dependencies. Constructors, equality checks, and hash code generation in `Attribute` have been updated accordingly.

The `CurrentAttribute` property in `ConsoleDriver` and `OutputBuffer` has been simplified, removing dependencies on `Application.Driver`. The `MakeColor` method logic has been removed or simplified in related classes.

Tests in `AttributeTests` have been refactored to reflect these changes, focusing on `Foreground`, `Background`, and `Style`. Unix-specific logic tied to `PlatformColor` has been eliminated.

Additional updates include renaming parameters in the `With` class for clarity, simplifying `DriverAssert` output, and performing minor code cleanups to improve readability and maintainability.

* Refactor Terminal.Gui driver architecture for v2

Updated documentation to reflect the new modular driver architecture in Terminal.Gui v2.

- Revised `namespace-drivers.md` to include new components (`IConsoleInput`, `IConsoleOutput`, `IInputProcessor`, `IOutputBuffer`, `IWindowSizeMonitor`) and terminal size monitoring.
- Replaced "Key Components" with "Architecture Overview" and added details on the **Component Factory** pattern.
- Documented the four driver implementations (`DotNetDriver`, `WindowsDriver`, `UnixDriver`, `FakeDriver`) and their platform-specific optimizations.
- Added a "Threading Model" section to explain the multi-threaded design for responsive input handling.
- Updated examples to demonstrate driver capabilities and explicit driver selection.

In `drivers.md`:
- Expanded the "Overview" to emphasize the modular, component-based architecture.
- Reorganized "Drivers" into "Available Drivers" and added details on `FakeDriver` for unit testing.
- Added sections on "Initialization Flow," "Shutdown Flow," and platform-specific driver details.
- Provided examples for accessing driver components and creating custom drivers.

In `index.md`:
- Updated "Cross Platform" feature to reflect new driver names and clarified compatibility with SSH and monochrome terminals.

* Moved files around

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tig <585482+tig@users.noreply.github.com>
Co-authored-by: Tig <tig@users.noreply.github.com>
Co-authored-by: Thomas Nind <31306100+tznind@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Fix nit test.

* Change ClearScreenNextIteration to internal and trying to fix unit test failure

* Reuse method and fix text field color to normal, probably due some changed configuration

* Fix scenario Shortcut not restoring Application.Quit

* Giving more time to load Scrolling scenario and display failing scenario

* Revert changes and add more assertions

* Forcing CI tests again and I suspect that is causing by UpdateFromJson unit test

* Changed test to force fake driver

* Ensure restore the original colors

* Update test runner behavior in unit-tests.yml

Changed `fail-fast` to `false` in `non_parallel_unittests` to allow all runners to complete even if errors occur. Updated `xunit.stopOnFail` to `true` in both `Run UnitTests` and `Run UnitTestsParallelizable` steps to stop test execution immediately upon failure. These changes improve test handling and execution consistency.

Refactor and enhance configuration and scheme handling

Refactored `ConfigurationManager` and `Scope<T>` to improve clarity and ensure proper resetting to hardcoded defaults. Updated `Color` constructor to use ARGB values for accuracy. Added debug assertions and logging for better test reliability.

Expanded test coverage:
- Verified hardcoded schemes and themes reset correctly.
- Added tests for `UpdateFromJson` behavior and `Color.ToString` output.
- Improved `SchemeManager` and `SchemeTests` to validate attributes and scheme overrides.

General improvements include better state management during tests and enhanced readability of event handlers.

* Found cause of #4288 and provided a workaround

* Reverted unneeded change to ComboBoxTests

* Fixed test that wasn't actually testing anything

* Added more precise unit test showing issue

* Added more precise unit test showing issue2

* Made test even more precise

* Potential fix for underlying issue

* Fixed test that broke with last change

* Reverted`ConfigurationManager` to return `_hardCodedConfigPropertyCache` directly, eliminating deep copy overhead for better performance.

Added a new test in `ConfigurationManagerTests` to verify that `GetHardCodedConfigPropertyCache` always returns the same reference. Updated existing tests to reflect this change.

Refactored `SchemeManagerTests` to use `try-finally` blocks for proper cleanup and improved test reliability. Applied similar changes to other test methods for consistency.

Re-enabled the `UpdateFrom_Corrupts_Schemes_HardCodeDefaults` test in `ThemeScopeTests` as the underlying issue has been rnot been esolved.

* Updated the `Disable` method calls across test classes to use
the new overload with a `true` parameter, ensuring consistent
behavior.

* Refactor and fix configuration and theme management

Refactored method names across multiple classes for clarity and consistency (e.g., `LoadCurrentValues` to `UpdateToCurrentValues`, `ResetToHardCodedDefaults` to `LoadHardCodedDefaults`). Removed redundant attributes from `ConfigurationManager`.

Implemented a workaround for `SchemeManager` to address issues with hard-coded schemes being overwritten. Updated `ThemeManager` logic to ensure proper initialization and updates of themes.

Aligned unit tests with refactored methods and added comments to document changes. Made minor adjustments to improve code maintainability, including handling of property values and removal of unused variables.

* Fix hard-coded defaults corruption in ThemeScope

Replaced `ResetToCurrentValues` with `ResetToHardCodedDefaults` across multiple files to address corruption of hard-coded defaults.

- Added a partial workaround in `ConfigurationManager.cs` to prevent overwriting hard-coded schemes in `ThemeScope`.
- Highlighted known issues with `UpdateToCurrentValues` in `ThemeManager.cs`.
- Updated tests in `ConfigurationManagerTests`, `SchemeManagerTests`, and others to reflect the reset method.
- Skipped or modified tests that rely on `ResetToCurrentValues` due to its corruption issues.
- Refactored `GlyphTests` to ensure proper cleanup using `try-finally`.
- Added comments and skipped tests to document and work around known bugs (e.g., #4288).

* Clarify comments and add theme reset functionality

Updated comments in `SchemeManager` and `ThemeManager` to clarify that the workaround for hardcoded schemes is partial.

Added a new `LoadHardCodedDefaults` method to `ThemeManager`, marked with `[RequiresUnreferencedCode]` and `[RequiresDynamicCode]`, to reset themes to hardcoded defaults. This method ensures proper initialization by throwing an exception if `ConfigurationManager` is not initialized.

Updated `ThemeManager` to call `SchemeManager.LoadToHardCodedDefaults` during the theme reset process, ensuring consistent loading of hardcoded schemes.

* Removed special handling for the "Schemes" key in `hardCodedThemeProperties`,

* Code cleanup

Refactored XML documentation comments for better readability.
Enhanced exception handling in `GetScheme(Schemes)` by adding a null check and throwing `ArgumentException` for invalid inputs.
Simplified method definitions by converting multi-line methods to single-line.
Updated attributes for `LoadToHardCodedDefaults` to align with the `SetSchemes` method.
Refactored `LoadToHardCodedDefaults` implementation for cleaner code.

Added support for Visual Studio debug console in `WindowsDriver`, including disabling the alternative screen buffer, preserving original console colors, and restoring them on shutdown.

Performed general code cleanup, including removing unnecessary comments and improving inline comments for clarity.

* Refactor and remove redundant validation methods

Removed `Validate` methods from `ConfigurationManager`, `Scope<T>`, and `ThemeManager`, indicating a shift in validation responsibilities. Enabled nullable reference types in `Scope.cs` to enforce stricter nullability checks. Simplified `Scope<T>` constructor and replaced explicit type declarations with `var` for improved readability. Adjusted LINQ query formatting and removed unused `using System.Text.Json;` to clean up dependencies. Made minor formatting changes for consistency and maintainability.

* Refactor ConfigurationManager for clarity and safety

Renamed `ResetToCurrentValues` to `UpdateToCurrentValues` for better clarity and updated all references, including comments and documentation. Introduced `_hardCodedConfigPropertyCacheLock` to ensure thread-safety when accessing `_hardCodedConfigPropertyCache`. Updated `Reset` terminology to `Update` across the codebase to reflect the updated behavior.

Improved `SerializerContext` initialization with concise syntax and fixed a formatting issue in a `Console.WriteLine` statement. Reformatted filtering logic for `configPropertiesByScope` for better readability.

Updated test cases in `AppSettingsScopeTests` and `ConfigurationManagerTests` to align with the renamed method and ensure consistent functionality.

* Code cleanup

Improve readability and handle null in serialization

Refactored LINQ queries to remove redundant line breaks, improving code readability. Updated comments for clarity and adjusted tone. Added a null check for the `prop` variable during serialization to ensure proper handling of null values by writing `null` to the JSON writer.

* Code Cleanup - Refactor ThemeManager and improve nullability handling

Updated ThemeManager to improve method visibility, naming consistency, and documentation. Introduced `GetHardCodedThemes` and `SetThemes` for better encapsulation. Made `DEFAULT_THEME_NAME` public for broader access. Enhanced nullability handling across multiple files using the null-forgiving operator (`!`) to suppress warnings.

Refactored `Themes.cs` to ensure proper cleanup of `allViewsView`. Simplified assertions in test files to reflect updated method visibility and removed redundant checks. Improved code clarity and maintainability throughout the codebase.

---------

Co-authored-by: BDisp <bd.bdisp@gmail.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tig <585482+tig@users.noreply.github.com>
Co-authored-by: Thomas Nind <31306100+tznind@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove CursesDriver, NetDriver, WindowsDriver, and legacy Application code and code that v2win/v2net introduced that wraps that legacy

4 participants