mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
* Improve wide character handling in output buffer Enhances rendering and state management for wide (double-width) characters. Marks both cells as clean after rendering wide graphemes, ensures replacement cells are marked dirty when partially clipped, and uses Move/AddStr for proper wide character handling and invalidation. * Fix FillRect to handle wide Unicode chars correctly Refactored OutputBufferImpl.FillRect to properly handle wide (double-width) Unicode characters, fixing visual corruption when overwriting CJK text (e.g., with MessageBox borders). Removed the char-based FillRect overload in favor of Rune-based handling. Added helper methods for attribute/dirty management and wide glyph invalidation. Updated OutputBase.Write to always mark adjacent cells dirty for wide chars. Updated tests and added OutputBufferWideCharTests to verify correct behavior in all scenarios. This resolves issue #4466 and ensures robust rendering for wide Unicode text. * Handle wide grapheme clusters in OutputBase rendering Added logic to mark both cells of wide grapheme clusters as clean after rendering, preventing unnecessary redraws. Also included a commented-out preprocessor directive and using statement for potential future use. * Clarify comment for IsDirty logic on wide graphemes Updated the comment explaining why the next cell is marked clean (IsDirty = false) after handling wide graphemes, and added a reference to GitHub issue #4466 for context. * Update test for dirty flag after wide glyph write Adjusted OutputBaseTests to expect column 1's dirty flag to be cleared after writing a wide glyph to column 0, matching current OutputBase.Write behavior. Added clarifying comment and GitHub issue reference. * Update Tests/UnitTestsParallelizable/Drivers/OutputBufferWideCharTests.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Terminal.Gui/Drivers/OutputBufferImpl.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Terminal.Gui/Drivers/OutputBase.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
UnitTests.Parallelizable
This project contains unit tests that can run in parallel without interference. Tests here must not depend on global state or static Application infrastructure.
Important Notes
- Many tests in
UnitTestsblindly use the the legacy model they don't actually need to - These tests CAN be rewritten to remove unnecessary dependencies and migrated here
- Many tests APPEAR to be integration tests but are just poorly written and cover multiple surface areas - these can be split into focused unit tests
- When in doubt, analyze if the test truly needs global state or can be refactored
Example Migrations
Simple Property Test (no changes needed)
// Before (in UnitTests)
[Fact]
public void Constructor_Sets_Defaults ()
{
var view = new Button ();
Assert.Empty (view.Text);
}
// After (in UnitTests.Parallelizable) - just move it!
[Fact]
public void Constructor_Sets_Defaults ()
{
var view = new Button ();
Assert.Empty (view.Text);
}
Remove Unnecessary [SetupFakeApplication]
// Before (in UnitTests)
[Fact]
[SetupFakeApplication]
public void Event_Fires_When_Property_Changes ()
{
var view = new Button ();
var fired = false;
view.TextChanged += (s, e) => fired = true;
view.Text = "Hello";
Assert.True (fired);
}
// After (in UnitTests.Parallelizable) - remove attribute!
[Fact]
public void Event_Fires_When_Property_Changes ()
{
var view = new Button ();
var fired = false;
view.TextChanged += (s, e) => fired = true;
view.Text = "Hello";
Assert.True (fired);
}
Replace Application.Begin with View Initialization
// Before (in UnitTests)
[Fact]
[AutoInitShutdown]
public void Focus_Test ()
{
var view = new Button ();
var top = new Runnable ();
top.Add (view);
Application.Begin (top);
view.SetFocus ();
Assert.True (view.HasFocus);
top.Dispose ();
}
// After (in UnitTests.Parallelizable) - use BeginInit/EndInit!
[Fact]
public void Focus_Test ()
{
var superView = new View ();
var view = new Button ();
superView.Add (view);
superView.BeginInit ();
superView.EndInit ();
view.SetFocus ();
Assert.True (view.HasFocus);
}
Running Tests
Tests in this project run in parallel automatically. To run them:
dotnet test Tests/UnitTestsParallelizable/UnitTests.Parallelizable.csproj