mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
* 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>
1135 lines
31 KiB
C#
1135 lines
31 KiB
C#
using UnitTests;
|
|
using Xunit.Abstractions;
|
|
|
|
namespace Terminal.Gui.ViewTests;
|
|
|
|
/// <summary>
|
|
/// Tests of the <see cref="View.Text"/> and <see cref="View.TextFormatter"/> properties.
|
|
/// </summary>
|
|
public class TextTests (ITestOutputHelper output)
|
|
{
|
|
[Fact]
|
|
[SetupFakeDriver]
|
|
public void Setting_With_Height_Horizontal ()
|
|
{
|
|
var top = new View { Width = 25, Height = 25 };
|
|
|
|
var label = new Label { Text = "Hello", /* Width = 10, Height = 2, */ ValidatePosDim = true };
|
|
var viewX = new View { Text = "X", X = Pos.Right (label), Width = 1, Height = 1 };
|
|
var viewY = new View { Text = "Y", Y = Pos.Bottom (label), Width = 1, Height = 1 };
|
|
|
|
top.Add (label, viewX, viewY);
|
|
top.Layout ();
|
|
|
|
Assert.Equal (new (0, 0, 5, 1), label.Frame);
|
|
|
|
top.LayoutSubViews ();
|
|
top.Draw ();
|
|
|
|
var expected = @"
|
|
HelloX
|
|
Y
|
|
";
|
|
|
|
Rectangle pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
|
|
|
|
label.Width = 10;
|
|
label.Height = 2;
|
|
|
|
Assert.Equal (new (0, 0, 10, 2), label.Frame);
|
|
|
|
top.LayoutSubViews ();
|
|
View.SetClipToScreen ();
|
|
top.Draw ();
|
|
|
|
expected = @"
|
|
Hello X
|
|
|
|
Y
|
|
";
|
|
|
|
pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Setting_With_Height_Vertical ()
|
|
{
|
|
// BUGBUG: Label is Width = Dim.Auto (), Height = Dim.Auto (), so Width & Height are ignored
|
|
var label = new Label
|
|
{ /*Width = 2, Height = 10, */
|
|
TextDirection = TextDirection.TopBottom_LeftRight, ValidatePosDim = true
|
|
};
|
|
var viewX = new View { Text = "X", X = Pos.Right (label), Width = 1, Height = 1 };
|
|
var viewY = new View { Text = "Y", Y = Pos.Bottom (label), Width = 1, Height = 1 };
|
|
|
|
var top = new Toplevel ();
|
|
top.Add (label, viewX, viewY);
|
|
RunState rs = Application.Begin (top);
|
|
|
|
label.Text = "Hello";
|
|
AutoInitShutdownAttribute.RunIteration ();
|
|
|
|
Assert.Equal (new (0, 0, 1, 5), label.Frame);
|
|
|
|
var expected = @"
|
|
HX
|
|
e
|
|
l
|
|
l
|
|
o
|
|
Y
|
|
";
|
|
|
|
Rectangle pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
|
|
|
|
label.Width = 2;
|
|
label.Height = 10;
|
|
AutoInitShutdownAttribute.RunIteration ();
|
|
|
|
Assert.Equal (new (0, 0, 2, 10), label.Frame);
|
|
|
|
expected = @"
|
|
H X
|
|
e
|
|
l
|
|
l
|
|
o
|
|
|
|
|
|
|
|
|
|
|
|
Y
|
|
"
|
|
;
|
|
|
|
pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
|
|
Application.End (rs);
|
|
top.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void TextDirection_Toggle ()
|
|
{
|
|
var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
|
|
|
|
var view = new View ();
|
|
win.Add (view);
|
|
var top = new Toplevel ();
|
|
top.Add (win);
|
|
|
|
RunState rs = Application.Begin (top);
|
|
AutoInitShutdownAttribute.FakeResize(new Size(15, 15)) ;
|
|
|
|
Assert.Equal (new (0, 0, 15, 15), win.Frame);
|
|
Assert.Equal (new (0, 0, 15, 15), win.Margin.Frame);
|
|
Assert.Equal (new (0, 0, 15, 15), win.Border.Frame);
|
|
Assert.Equal (new (1, 1, 13, 13), win.Padding.Frame);
|
|
|
|
Assert.Equal (TextDirection.LeftRight_TopBottom, view.TextDirection);
|
|
Assert.Equal (Rectangle.Empty, view.Frame);
|
|
Assert.Equal ("Absolute(0)", view.X.ToString ());
|
|
Assert.Equal ("Absolute(0)", view.Y.ToString ());
|
|
Assert.Equal ("Absolute(0)", view.Width.ToString ());
|
|
Assert.Equal ("Absolute(0)", view.Height.ToString ());
|
|
|
|
var expected = @"
|
|
┌─────────────┐
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
└─────────────┘
|
|
";
|
|
|
|
Rectangle pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
|
|
|
|
view.Text = "Hello World";
|
|
view.Width = 11;
|
|
view.Height = 1;
|
|
AutoInitShutdownAttribute.RunIteration ();
|
|
Assert.Equal (new (0, 0, 11, 1), view.Frame);
|
|
Assert.Equal ("Absolute(0)", view.X.ToString ());
|
|
Assert.Equal ("Absolute(0)", view.Y.ToString ());
|
|
Assert.Equal ("Absolute(11)", view.Width.ToString ());
|
|
Assert.Equal ("Absolute(1)", view.Height.ToString ());
|
|
|
|
expected = @"
|
|
┌─────────────┐
|
|
│Hello World │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
└─────────────┘
|
|
";
|
|
|
|
pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
|
|
|
|
view.Width = Dim.Auto ();
|
|
view.Height = Dim.Auto ();
|
|
view.Text = "Hello Worlds";
|
|
AutoInitShutdownAttribute.RunIteration ();
|
|
int len = "Hello Worlds".Length;
|
|
Assert.Equal (12, len);
|
|
Assert.Equal (new (0, 0, len, 1), view.Frame);
|
|
|
|
expected = @"
|
|
┌─────────────┐
|
|
│Hello Worlds │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
└─────────────┘
|
|
";
|
|
|
|
pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
|
|
|
|
view.TextDirection = TextDirection.TopBottom_LeftRight;
|
|
AutoInitShutdownAttribute.RunIteration ();
|
|
Assert.Equal (new (0, 0, 1, 12), view.Frame);
|
|
Assert.Equal (new (0, 0, 1, 12), view.Frame);
|
|
|
|
expected = @"
|
|
┌─────────────┐
|
|
│H │
|
|
│e │
|
|
│l │
|
|
│l │
|
|
│o │
|
|
│ │
|
|
│W │
|
|
│o │
|
|
│r │
|
|
│l │
|
|
│d │
|
|
│s │
|
|
│ │
|
|
└─────────────┘
|
|
";
|
|
|
|
pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
|
|
|
|
// Setting to false causes Width and Height to be set to the current ContentSize
|
|
view.Width = 1;
|
|
view.Height = 12;
|
|
AutoInitShutdownAttribute.RunIteration ();
|
|
Assert.Equal (new (0, 0, 1, 12), view.Frame);
|
|
|
|
view.Width = 12;
|
|
view.Height = 1;
|
|
view.TextFormatter.ConstrainToSize = new (12, 1);
|
|
AutoInitShutdownAttribute.RunIteration ();
|
|
Assert.Equal (new (12, 1), view.TextFormatter.ConstrainToSize);
|
|
Assert.Equal (new (0, 0, 12, 1), view.Frame);
|
|
|
|
top.ClearViewport ();
|
|
view.SetNeedsDraw ();
|
|
view.Draw ();
|
|
expected = @" HelloWorlds";
|
|
DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
|
|
|
|
AutoInitShutdownAttribute.RunIteration ();
|
|
|
|
// TextDirection.TopBottom_LeftRight - Height of 1 and Width of 12 means
|
|
// that the text will be spread "vertically" across 1 line.
|
|
// Hence no space.
|
|
expected = @"
|
|
┌─────────────┐
|
|
│HelloWorlds │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
└─────────────┘
|
|
";
|
|
|
|
pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
|
|
|
|
view.PreserveTrailingSpaces = true;
|
|
AutoInitShutdownAttribute.RunIteration ();
|
|
|
|
Assert.Equal (new (0, 0, 12, 1), view.Frame);
|
|
|
|
expected = @"
|
|
┌─────────────┐
|
|
│Hello Worlds │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
└─────────────┘
|
|
";
|
|
|
|
pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
|
|
|
|
view.PreserveTrailingSpaces = false;
|
|
Rectangle f = view.Frame;
|
|
view.Width = f.Height;
|
|
view.Height = f.Width;
|
|
view.TextDirection = TextDirection.TopBottom_LeftRight;
|
|
AutoInitShutdownAttribute.RunIteration ();
|
|
|
|
Assert.Equal (new (0, 0, 1, 12), view.Frame);
|
|
|
|
expected = @"
|
|
┌─────────────┐
|
|
│H │
|
|
│e │
|
|
│l │
|
|
│l │
|
|
│o │
|
|
│ │
|
|
│W │
|
|
│o │
|
|
│r │
|
|
│l │
|
|
│d │
|
|
│s │
|
|
│ │
|
|
└─────────────┘
|
|
";
|
|
|
|
pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
|
|
|
|
view.Width = Dim.Auto ();
|
|
view.Height = Dim.Auto ();
|
|
|
|
AutoInitShutdownAttribute.RunIteration ();
|
|
|
|
Assert.Equal (new (0, 0, 1, 12), view.Frame);
|
|
|
|
expected = @"
|
|
┌─────────────┐
|
|
│H │
|
|
│e │
|
|
│l │
|
|
│l │
|
|
│o │
|
|
│ │
|
|
│W │
|
|
│o │
|
|
│r │
|
|
│l │
|
|
│d │
|
|
│s │
|
|
│ │
|
|
└─────────────┘
|
|
";
|
|
|
|
pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
|
|
Application.End (rs);
|
|
top.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void View_IsEmpty_False_Minimum_Width ()
|
|
{
|
|
var text = "Views";
|
|
|
|
var view = new View
|
|
{
|
|
TextDirection = TextDirection.TopBottom_LeftRight,
|
|
Height = Dim.Fill () - text.Length,
|
|
Text = text
|
|
};
|
|
view.Width = Dim.Auto ();
|
|
view.Height = Dim.Auto ();
|
|
|
|
var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
|
|
win.Add (view);
|
|
var top = new Toplevel ();
|
|
top.Add (win);
|
|
RunState rs = Application.Begin (top);
|
|
AutoInitShutdownAttribute.FakeResize(new Size(4, 10));
|
|
|
|
Assert.Equal (5, text.Length);
|
|
|
|
Assert.Equal (new (0, 0, 1, 5), view.Frame);
|
|
Assert.Equal (new (1, 5), view.TextFormatter.ConstrainToSize);
|
|
Assert.Equal (new () { "Views" }, view.TextFormatter.GetLines ());
|
|
Assert.Equal (new (0, 0, 4, 10), win.Frame);
|
|
Assert.Equal (new (0, 0, 4, 10), Application.Top.Frame);
|
|
|
|
var expected = @"
|
|
┌──┐
|
|
│V │
|
|
│i │
|
|
│e │
|
|
│w │
|
|
│s │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
└──┘
|
|
";
|
|
|
|
Rectangle pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
|
|
Assert.Equal (new (0, 0, 4, 10), pos);
|
|
|
|
text = "0123456789";
|
|
Assert.Equal (10, text.Length);
|
|
|
|
//view.Height = Dim.Fill () - text.Length;
|
|
AutoInitShutdownAttribute.RunIteration ();
|
|
|
|
Assert.Equal (new (0, 0, 1, 5), view.Frame);
|
|
Assert.Equal (new (1, 5), view.TextFormatter.ConstrainToSize);
|
|
Exception exception = Record.Exception (() => Assert.Single (view.TextFormatter.GetLines ()));
|
|
Assert.Null (exception);
|
|
|
|
expected = @"
|
|
┌──┐
|
|
│V │
|
|
│i │
|
|
│e │
|
|
│w │
|
|
│s │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
└──┘
|
|
";
|
|
|
|
pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
|
|
Assert.Equal (new (0, 0, 4, 10), pos);
|
|
top.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
[SetupFakeDriver]
|
|
public void DimAuto_Vertical_TextDirection_Wide_Rune ()
|
|
{
|
|
var text = "界View";
|
|
|
|
var view = new View
|
|
{
|
|
TextDirection = TextDirection.TopBottom_LeftRight,
|
|
Text = text,
|
|
Width = Dim.Auto (),
|
|
Height = Dim.Auto ()
|
|
};
|
|
|
|
view.SetRelativeLayout (new (4, 10));
|
|
|
|
Assert.Equal (5, text.Length);
|
|
|
|
// Vertical text - 2 wide, 5 down
|
|
Assert.Equal (new (0, 0, 2, 5), view.Frame);
|
|
Assert.Equal (new (2, 5), view.TextFormatter.ConstrainToSize);
|
|
Assert.Equal (new () { "界View" }, view.TextFormatter.GetLines ());
|
|
|
|
view.Draw ();
|
|
|
|
var expected = @"
|
|
界
|
|
V
|
|
i
|
|
e
|
|
w ";
|
|
|
|
Rectangle pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Width_Height_SetMinWidthHeight_Narrow_Wide_Runes ()
|
|
{
|
|
var text = $"0123456789{Environment.NewLine}01234567891";
|
|
|
|
var horizontalView = new View
|
|
{
|
|
Width = Dim.Auto (),
|
|
Height = Dim.Auto (),
|
|
Text = text
|
|
};
|
|
|
|
var verticalView = new View
|
|
{
|
|
Width = Dim.Auto (),
|
|
Height = Dim.Auto (),
|
|
Y = 3,
|
|
|
|
//Height = 11,
|
|
//Width = 2,
|
|
Text = text,
|
|
TextDirection = TextDirection.TopBottom_LeftRight
|
|
};
|
|
|
|
var win = new Window
|
|
{
|
|
Width = Dim.Fill (),
|
|
Height = Dim.Fill (),
|
|
Text = "Window"
|
|
};
|
|
win.Add (horizontalView, verticalView);
|
|
var top = new Toplevel ();
|
|
top.Add (win);
|
|
RunState rs = Application.Begin (top);
|
|
AutoInitShutdownAttribute.FakeResize(new Size(20, 20));
|
|
|
|
Assert.Equal (new (0, 0, 11, 2), horizontalView.Frame);
|
|
Assert.Equal (new (0, 3, 2, 11), verticalView.Frame);
|
|
|
|
var expected = @"
|
|
┌──────────────────┐
|
|
│0123456789 │
|
|
│01234567891 │
|
|
│ │
|
|
│00 │
|
|
│11 │
|
|
│22 │
|
|
│33 │
|
|
│44 │
|
|
│55 │
|
|
│66 │
|
|
│77 │
|
|
│88 │
|
|
│99 │
|
|
│ 1 │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
└──────────────────┘
|
|
";
|
|
|
|
Rectangle pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
|
|
|
|
verticalView.Text = $"最初の行{Environment.NewLine}二行目";
|
|
AutoInitShutdownAttribute.RunIteration ();
|
|
Assert.Equal (new (0, 3, 4, 4), verticalView.Frame);
|
|
|
|
expected = @"
|
|
┌──────────────────┐
|
|
│0123456789 │
|
|
│01234567891 │
|
|
│ │
|
|
│最二 │
|
|
│初行 │
|
|
│の目 │
|
|
│行 │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
└──────────────────┘
|
|
";
|
|
|
|
pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
|
|
Application.End (rs);
|
|
top.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Width_Height_Stay_True_If_TextFormatter_Size_Fit ()
|
|
{
|
|
var text = "Finish 終";
|
|
|
|
var horizontalView = new View
|
|
{
|
|
Id = "horizontalView",
|
|
Width = Dim.Auto (), Height = Dim.Auto (), Text = text
|
|
};
|
|
|
|
var verticalView = new View
|
|
{
|
|
Id = "verticalView",
|
|
Y = 3,
|
|
Width = Dim.Auto (),
|
|
Height = Dim.Auto (),
|
|
Text = text,
|
|
TextDirection = TextDirection.TopBottom_LeftRight
|
|
};
|
|
var win = new Window { Id = "win", Width = Dim.Fill (), Height = Dim.Fill (), Text = "Window" };
|
|
win.Add (horizontalView, verticalView);
|
|
var top = new Toplevel ();
|
|
top.Add (win);
|
|
RunState rs = Application.Begin (top);
|
|
AutoInitShutdownAttribute.FakeResize(new Size(22, 22));
|
|
|
|
Assert.Equal (new (text.GetColumns (), 1), horizontalView.TextFormatter.ConstrainToSize);
|
|
Assert.Equal (new (2, 8), verticalView.TextFormatter.ConstrainToSize);
|
|
|
|
//Assert.Equal (new (0, 0, 10, 1), horizontalView.Frame);
|
|
//Assert.Equal (new (0, 3, 10, 9), verticalView.Frame);
|
|
|
|
var expected = @"
|
|
┌────────────────────┐
|
|
│Finish 終 │
|
|
│ │
|
|
│ │
|
|
│F │
|
|
│i │
|
|
│n │
|
|
│i │
|
|
│s │
|
|
│h │
|
|
│ │
|
|
│終 │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
└────────────────────┘
|
|
";
|
|
|
|
Rectangle pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
|
|
|
|
verticalView.Text = "最初の行二行目";
|
|
AutoInitShutdownAttribute.RunIteration ();
|
|
|
|
// height was initialized with 8 and can only grow or keep initial value
|
|
Assert.Equal (new (0, 3, 2, 7), verticalView.Frame);
|
|
|
|
expected = @"
|
|
┌────────────────────┐
|
|
│Finish 終 │
|
|
│ │
|
|
│ │
|
|
│最 │
|
|
│初 │
|
|
│の │
|
|
│行 │
|
|
│二 │
|
|
│行 │
|
|
│目 │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
└────────────────────┘
|
|
";
|
|
|
|
pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
|
|
Application.End (rs);
|
|
top.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Excess_Text_Is_Erased_When_The_Width_Is_Reduced ()
|
|
{
|
|
var lbl = new Label { Text = "123" };
|
|
var top = new Toplevel ();
|
|
top.Add (lbl);
|
|
RunState rs = Application.Begin (top);
|
|
AutoInitShutdownAttribute.RunIteration ();
|
|
|
|
Assert.Equal (new (0, 0, 3, 1), lbl.Frame);
|
|
|
|
Assert.Equal ("123 ", GetContents ());
|
|
|
|
lbl.Text = "12";
|
|
lbl.Layout ();
|
|
|
|
Assert.Equal (new (0, 0, 2, 1), lbl.Frame);
|
|
Assert.Equal (new (0, 0, 2, 1), lbl.NeedsDrawRect);
|
|
Assert.Equal (new (0, 0, 80, 25), lbl.SuperView.NeedsDrawRect);
|
|
Assert.True (lbl.SuperView.NeedsLayout);
|
|
AutoInitShutdownAttribute.RunIteration ();
|
|
|
|
Assert.Equal ("12 ", GetContents ());
|
|
|
|
string GetContents ()
|
|
{
|
|
var text = "";
|
|
|
|
for (var i = 0; i < 4; i++)
|
|
{
|
|
text += Application.Driver?.Contents [0, i].Rune;
|
|
}
|
|
|
|
return text;
|
|
}
|
|
|
|
Application.End (rs);
|
|
top.Dispose ();
|
|
}
|
|
|
|
[Theory]
|
|
[AutoInitShutdown]
|
|
[InlineData (true)]
|
|
[InlineData (false)]
|
|
public void View_Draw_Horizontal_Simple_TextAlignments (bool autoSize)
|
|
{
|
|
var text = "Hello World";
|
|
var width = 20;
|
|
|
|
var lblLeft = new View
|
|
{
|
|
Text = text,
|
|
Width = width,
|
|
Height = 1
|
|
};
|
|
|
|
if (autoSize)
|
|
{
|
|
lblLeft.Width = Dim.Auto ();
|
|
lblLeft.Height = Dim.Auto ();
|
|
}
|
|
|
|
var lblCenter = new View
|
|
{
|
|
Text = text,
|
|
Y = 1,
|
|
Width = width,
|
|
Height = 1,
|
|
TextAlignment = Alignment.Center
|
|
};
|
|
|
|
if (autoSize)
|
|
{
|
|
lblCenter.Width = Dim.Auto ();
|
|
lblCenter.Height = Dim.Auto ();
|
|
}
|
|
|
|
var lblRight = new View
|
|
{
|
|
Text = text,
|
|
Y = 2,
|
|
Width = width,
|
|
Height = 1,
|
|
TextAlignment = Alignment.End
|
|
};
|
|
|
|
if (autoSize)
|
|
{
|
|
lblRight.Width = Dim.Auto ();
|
|
lblRight.Height = Dim.Auto ();
|
|
}
|
|
|
|
var lblJust = new View
|
|
{
|
|
Text = text,
|
|
Y = 3,
|
|
Width = width,
|
|
Height = 1,
|
|
TextAlignment = Alignment.Fill
|
|
};
|
|
|
|
if (autoSize)
|
|
{
|
|
lblJust.Width = Dim.Auto ();
|
|
lblJust.Height = Dim.Auto ();
|
|
}
|
|
|
|
var frame = new FrameView { Width = Dim.Fill (), Height = Dim.Fill (), BorderStyle = LineStyle.Single };
|
|
frame.Add (lblLeft, lblCenter, lblRight, lblJust);
|
|
var top = new Toplevel ();
|
|
top.Add (frame);
|
|
Application.Begin (top);
|
|
AutoInitShutdownAttribute.FakeResize (new Size(width + 2, 6));
|
|
|
|
// frame.Width is width + border wide (20 + 2) and 6 high
|
|
|
|
if (autoSize)
|
|
{
|
|
Size expectedSize = new (11, 1);
|
|
Assert.Equal (expectedSize, lblLeft.TextFormatter.ConstrainToSize);
|
|
Assert.Equal (expectedSize, lblCenter.TextFormatter.ConstrainToSize);
|
|
Assert.Equal (expectedSize, lblRight.TextFormatter.ConstrainToSize);
|
|
Assert.Equal (expectedSize, lblJust.TextFormatter.ConstrainToSize);
|
|
}
|
|
else
|
|
{
|
|
Size expectedSize = new (width, 1);
|
|
Assert.Equal (expectedSize, lblLeft.TextFormatter.ConstrainToSize);
|
|
Assert.Equal (expectedSize, lblCenter.TextFormatter.ConstrainToSize);
|
|
Assert.Equal (expectedSize, lblRight.TextFormatter.ConstrainToSize);
|
|
Assert.Equal (expectedSize, lblJust.TextFormatter.ConstrainToSize);
|
|
}
|
|
|
|
Assert.Equal (new (0, 0, width + 2, 6), frame.Frame);
|
|
|
|
string expected;
|
|
|
|
if (autoSize)
|
|
{
|
|
expected = @"
|
|
┌────────────────────┐
|
|
│Hello World │
|
|
│Hello World │
|
|
│Hello World │
|
|
│Hello World │
|
|
└────────────────────┘
|
|
";
|
|
}
|
|
else
|
|
{
|
|
expected = @"
|
|
┌────────────────────┐
|
|
│Hello World │
|
|
│ Hello World │
|
|
│ Hello World│
|
|
│Hello World│
|
|
└────────────────────┘
|
|
";
|
|
}
|
|
|
|
Rectangle pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
|
|
Assert.Equal (new (0, 0, width + 2, 6), pos);
|
|
top.Dispose ();
|
|
}
|
|
|
|
[Theory]
|
|
[AutoInitShutdown]
|
|
[InlineData (true)]
|
|
[InlineData (false)]
|
|
public void View_Draw_Vertical_Simple_TextAlignments (bool autoSize)
|
|
{
|
|
var text = "Hello World";
|
|
var height = 20;
|
|
|
|
var lblLeft = new View
|
|
{
|
|
Text = text,
|
|
Width = 1,
|
|
Height = height,
|
|
TextDirection = TextDirection.TopBottom_LeftRight
|
|
};
|
|
|
|
if (autoSize)
|
|
{
|
|
lblLeft.Width = Dim.Auto ();
|
|
lblLeft.Height = Dim.Auto ();
|
|
}
|
|
|
|
var lblCenter = new View
|
|
{
|
|
Text = text,
|
|
X = 2,
|
|
Width = 1,
|
|
Height = height,
|
|
TextDirection = TextDirection.TopBottom_LeftRight,
|
|
VerticalTextAlignment = Alignment.Center
|
|
};
|
|
|
|
if (autoSize)
|
|
{
|
|
lblCenter.Width = Dim.Auto ();
|
|
lblCenter.Height = Dim.Auto ();
|
|
}
|
|
|
|
var lblRight = new View
|
|
{
|
|
Text = text,
|
|
X = 4,
|
|
Width = 1,
|
|
Height = height,
|
|
TextDirection = TextDirection.TopBottom_LeftRight,
|
|
VerticalTextAlignment = Alignment.End
|
|
};
|
|
|
|
if (autoSize)
|
|
{
|
|
lblRight.Width = Dim.Auto ();
|
|
lblRight.Height = Dim.Auto ();
|
|
}
|
|
|
|
var lblJust = new View
|
|
{
|
|
Text = text,
|
|
X = 6,
|
|
Width = 1,
|
|
Height = height,
|
|
TextDirection = TextDirection.TopBottom_LeftRight,
|
|
VerticalTextAlignment = Alignment.Fill
|
|
};
|
|
|
|
if (autoSize)
|
|
{
|
|
lblJust.Width = Dim.Auto ();
|
|
lblJust.Height = Dim.Auto ();
|
|
}
|
|
|
|
var frame = new FrameView { Width = Dim.Fill (), Height = Dim.Fill (), BorderStyle = LineStyle.Single };
|
|
|
|
frame.Add (lblLeft, lblCenter, lblRight, lblJust);
|
|
var top = new Toplevel ();
|
|
top.Add (frame);
|
|
Application.Begin (top);
|
|
AutoInitShutdownAttribute.FakeResize(new Size(9, height + 2));
|
|
|
|
if (autoSize)
|
|
{
|
|
Assert.Equal (new (1, 11), lblLeft.TextFormatter.ConstrainToSize);
|
|
Assert.Equal (new (1, 11), lblCenter.TextFormatter.ConstrainToSize);
|
|
Assert.Equal (new (1, 11), lblRight.TextFormatter.ConstrainToSize);
|
|
Assert.Equal (new (1, 11), lblJust.TextFormatter.ConstrainToSize);
|
|
Assert.Equal (new (0, 0, 9, height + 2), frame.Frame);
|
|
}
|
|
else
|
|
{
|
|
Assert.Equal (new (1, height), lblLeft.TextFormatter.ConstrainToSize);
|
|
Assert.Equal (new (1, height), lblCenter.TextFormatter.ConstrainToSize);
|
|
Assert.Equal (new (1, height), lblRight.TextFormatter.ConstrainToSize);
|
|
Assert.Equal (new (1, height), lblJust.TextFormatter.ConstrainToSize);
|
|
Assert.Equal (new (0, 0, 9, height + 2), frame.Frame);
|
|
}
|
|
|
|
string expected;
|
|
|
|
if (autoSize)
|
|
{
|
|
expected = @"
|
|
┌───────┐
|
|
│H H H H│
|
|
│e e e e│
|
|
│l l l l│
|
|
│l l l l│
|
|
│o o o o│
|
|
│ │
|
|
│W W W W│
|
|
│o o o o│
|
|
│r r r r│
|
|
│l l l l│
|
|
│d d d d│
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
└───────┘
|
|
";
|
|
}
|
|
else
|
|
{
|
|
expected = @"
|
|
┌───────┐
|
|
│H H│
|
|
│e e│
|
|
│l l│
|
|
│l l│
|
|
│o H o│
|
|
│ e │
|
|
│W l │
|
|
│o l │
|
|
│r o │
|
|
│l H │
|
|
│d W e │
|
|
│ o l │
|
|
│ r l │
|
|
│ l o │
|
|
│ d │
|
|
│ W W│
|
|
│ o o│
|
|
│ r r│
|
|
│ l l│
|
|
│ d d│
|
|
└───────┘
|
|
";
|
|
}
|
|
|
|
Rectangle pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
|
|
Assert.Equal (new (0, 0, 9, height + 2), pos);
|
|
top.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
[SetupFakeDriver]
|
|
public void Narrow_Wide_Runes ()
|
|
{
|
|
((IFakeConsoleDriver)Application.Driver!).SetBufferSize (32, 32);
|
|
var top = new View { Width = 32, Height = 32 };
|
|
|
|
var text = $"First line{Environment.NewLine}Second line";
|
|
var horizontalView = new View { Width = 20, Height = 1, Text = text };
|
|
|
|
// Autosize is off, so we have to explicitly set TextFormatter.Size
|
|
horizontalView.TextFormatter.ConstrainToSize = new (20, 1);
|
|
|
|
var verticalView = new View
|
|
{
|
|
Y = 3,
|
|
Height = 20,
|
|
Width = 1,
|
|
Text = text,
|
|
TextDirection = TextDirection.TopBottom_LeftRight
|
|
};
|
|
|
|
// Autosize is off, so we have to explicitly set TextFormatter.Size
|
|
verticalView.TextFormatter.ConstrainToSize = new (1, 20);
|
|
|
|
var frame = new FrameView { Width = Dim.Fill (), Height = Dim.Fill (), Text = "Window", BorderStyle = LineStyle.Single };
|
|
frame.Add (horizontalView, verticalView);
|
|
top.Add (frame);
|
|
top.BeginInit ();
|
|
top.EndInit ();
|
|
|
|
Assert.Equal (new (0, 0, 20, 1), horizontalView.Frame);
|
|
Assert.Equal (new (0, 3, 1, 20), verticalView.Frame);
|
|
|
|
top.Draw ();
|
|
|
|
var expected = @"
|
|
┌──────────────────────────────┐
|
|
│First line Second li │
|
|
│ │
|
|
│ │
|
|
│F │
|
|
│i │
|
|
│r │
|
|
│s │
|
|
│t │
|
|
│ │
|
|
│l │
|
|
│i │
|
|
│n │
|
|
│e │
|
|
│ │
|
|
│S │
|
|
│e │
|
|
│c │
|
|
│o │
|
|
│n │
|
|
│d │
|
|
│ │
|
|
│l │
|
|
│i │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
└──────────────────────────────┘
|
|
";
|
|
|
|
Rectangle pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
|
|
|
|
verticalView.Text = $"最初の行{Environment.NewLine}二行目";
|
|
Assert.True (verticalView.TextFormatter.NeedsFormat);
|
|
|
|
// Autosize is off, so we have to explicitly set TextFormatter.Size
|
|
// We know these glpyhs are 2 cols wide, so we need to widen the view
|
|
verticalView.Width = 2;
|
|
verticalView.TextFormatter.ConstrainToSize = new (2, 20);
|
|
Assert.True (verticalView.TextFormatter.NeedsFormat);
|
|
View.SetClipToScreen ();
|
|
top.Draw ();
|
|
Assert.Equal (new (0, 3, 2, 20), verticalView.Frame);
|
|
|
|
expected = @"
|
|
┌──────────────────────────────┐
|
|
│First line Second li │
|
|
│ │
|
|
│ │
|
|
│最 │
|
|
│初 │
|
|
│の │
|
|
│行 │
|
|
│ │
|
|
│二 │
|
|
│行 │
|
|
│目 │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
└──────────────────────────────┘
|
|
";
|
|
|
|
pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
|
|
}
|
|
|
|
[Fact]
|
|
[SetupFakeDriver]
|
|
public void SetText_RendersCorrectly ()
|
|
{
|
|
View view;
|
|
var text = "test";
|
|
|
|
view = new Label { Text = text };
|
|
view.BeginInit ();
|
|
view.EndInit ();
|
|
view.Draw ();
|
|
|
|
DriverAssert.AssertDriverContentsWithFrameAre (text, output);
|
|
}
|
|
}
|