Update `RaiseScreenChangedEvent` to no longer explicitly set the `Screen` property. Remove unnecessary `.ToArray()` conversion in `View.Draw`.
Clarify `Screen` property documentation in `IApplication` to specify constraints on location and size. Update tests to reflect the new behavior where setting the `Screen` property raises the `ScreenChanged` event. Rename and adjust test cases accordingly.
Added a thread-safe lock mechanism (`_lockScreen`) to ensure safe updates to the `_screen` field, enabling future support for changing the `Driver` based on screen values.
Improved the `ResetScreen` method documentation to clarify its purpose.
Optimized the `LayoutAndDraw` method by:
- Adding a layout step to adjust views based on screen size.
- Reducing unnecessary redraws by selectively updating views that require it.
- Ensuring the terminal driver flushes updates with `Driver?.Refresh()`.
Removed redundant logging to streamline the code.
Enhanced the `DrawContext` and `View` classes with detailed documentation and examples for implementing transparency. Improved the `OnDrawingContent` method and `DrawingContent` event to support reporting drawn regions for transparency.
Performed general code cleanup, including removing unused code, simplifying `ViewportSettings` usage, and improving property initialization. Minor namespace cleanup was also included.
The refactor includes:
- Modifying method signatures in classes like `AnimationScenario`, `Images`, `DrawingArea`, `AttributeView`, `Snake`, and others.
- Removing the parameterless `OnDrawingContent` method from the `View` class.
- Updating calls to the base class implementation to pass the `context` parameter.
- Adjusting comments and documentation to reflect the new method signature.
This change ensures consistency and prepares the codebase for more advanced drawing capabilities.
Enhanced `View` class drawing logic to ensure proper ordering of margin and subview rendering, and introduced `DoDrawContent` for encapsulated content drawing. Improved comments and documentation for better maintainability.
Updated tests to reflect the new redraw management methods. Made minor formatting changes and removed redundant code for consistency and readability.
Refactored `View` class to ensure `SuperView.SubViewNeedsDraw`
is managed correctly. Added logic to prevent clearing the flag
prematurely when sibling subviews still require drawing.
Introduced a new `SubViewNeedsDraw` property with a private
setter and added `TODO` comments for potential future
improvements, such as making it a computed property.
Updated and added tests in `NeedsDrawTests` and `StaticDrawTests`
to validate the corrected behavior and prevent regressions.
Re-enabled a previously skipped test after fixing the related bug.
Refactored `NeedsDraw` logic into a modular implementation in `View.NeedsDraw.cs`, introducing methods to manage drawing states more effectively. Updated `Menus.cs` event handlers to include null checks for robustness. Improved margin drawing logic in `Margin.cs` with better performance and debugging assertions.
Added comprehensive unit tests in `NeedsDrawTests.cs` and `StaticDrawTests.cs` to validate the new drawing logic, including edge cases and static `View.Draw` behavior. Removed redundant tests from `ViewDrawingFlowTests.cs`.
Refactored diagnostic flags handling in `UICatalogRunnable.cs` for clarity. Performed general code cleanup, leveraging modern C# features and improving maintainability.
Removed 5 analysis .md files from repository root:
- ALLOCATION_CALL_FLOW.md
- ALLOCATION_DOCS_README.md
- ALLOCATION_INVESTIGATION_SUMMARY.md
- HEAP_ALLOCATION_ANALYSIS.md
- OPTIMIZATION_RECOMMENDATIONS.md
These were temporary analysis documents used during investigation.
The key findings and optimizations are captured in the PR description.
Co-authored-by: tig <585482+tig@users.noreply.github.com>
Improved the drawing system by adding conditions to check `Border.NeedsDraw` and `Padding.NeedsDraw` before drawing their subviews, reducing unnecessary operations. Commented out a brute-force `SetNeedsDraw` call for certain views to enhance performance.
Updated the logic for clearing `SubViewNeedsDraw` in `SuperView` to ensure it is only cleared when appropriate, preventing potential issues in the draw system. Marked the test `ClearNeedsDraw_WithSiblings_DoesNotClearSuperViewSubViewNeedsDraw` as skipped, as it is no longer valid due to these changes.
Refactored the `View` class to include a `NeedsDraw` check in
multiple drawing methods, improving rendering efficiency.
Adjusted `OnDrewText` and `DrewText` event handling for
consistency. Removed unused code and redundant tests.
Rewrote and reorganized `ClearViewportTests` for clarity and
compatibility with the new `NeedsDraw` logic. Added new tests
to validate `ClearViewport` behavior under various conditions,
including transparent viewports, event cancellations, and
content-only clearing.
Updated namespaces for better alignment, disabled a noisy
`ComboBoxTests` test, and improved code formatting and
maintainability across files.
Refactored the `LayoutAndDraw` method in `ApplicationImpl.Screen.cs` to improve clarity, naming consistency, and redraw logic. Enhanced handling of the `Driver` object to optimize redraws.
Simplified `IterationImpl` in `ApplicationMainLoop.cs` by commenting out redundant checks. Fixed a bug in `SetCursor` to ensure null safety and improve cursor positioning logic.
Modified `ClearNeedsDraw` in `View.Drawing.cs` to prevent premature clearing of the `SuperView`'s `SubViewNeedsDraw` flag. Added explanatory comments to clarify the behavior.
Introduced new unit tests in `NeedsDrawTests.cs` to verify the correctness of `ClearNeedsDraw`:
- Ensured sibling views do not prematurely clear `SuperView`'s flags.
- Verified proper clearing of flags for views, adornments, and descendants.
Improved test coverage and added detailed comments to document expected behavior.
Refactor redraw logic by removing `needsDrawOrLayout` checks and
the `AnySubViewsNeedDrawn` method in `ApplicationMainLoop.cs`.
Always call `App?.LayoutAndDraw(forceRedraw: false)` to simplify
layout and drawing behavior.
Add redraw logging in `ApplicationImpl.Screen.cs` to track redraw
events consistently.
Update `DriverImpl.cs` to always write the `OutputBuffer` during
`Refresh`, ensuring output is consistently handled.
Refactored `OutputBase.Write()` to eliminate cursor flickering by removing the save/restore pattern for cursor visibility. Cursor visibility is now managed solely by `ApplicationMainLoop.SetCursor()`.
Introduced the distinction between the "Draw Cursor" (internal drawing position) and the "Terminal Cursor" (visible input indicator). This resolves issues caused by conflating these concepts in the original design.
Updated `cursor.md` to document the new design, clarify terminology, and emphasize the separation of concerns between drawing operations and cursor positioning.
Resolved issue #3444 (cursor flickering during `TableView` scrolling) and improved the efficiency of `View.PositionCursor()` by proposing caching strategies.
Improved documentation and ensured consistent, intentional cursor visibility and positioning throughout the library.
Applied ArrayPool pattern to GetDrawRegion method:
- Use ArrayPool<string>.Shared.Rent() instead of .ToArray() for grapheme arrays
- Track actual grapheme count separately from rented array length
- Return array to pool in finally block for guaranteed cleanup
- Handle rare case where array needs to grow during enumeration
Impact: Eliminates allocations on layout calculations
- GetDrawRegion called before drawing for text region calculations
- Same allocation pattern as Draw() which was already fixed
- Complements the Draw() optimization for complete text rendering pipeline
All unit tests pass (12,055 parallelizable + 1,173 non-parallel)
Co-authored-by: tig <585482+tig@users.noreply.github.com>
Added allocation-free grapheme counting to GraphemeHelper:
- New GetGraphemeCount() method counts graphemes without materializing array
- Uses TextElementEnumerator directly, avoiding .ToArray() allocation
- Updated Cell.Grapheme setter to use GetGraphemeCount() instead of .ToArray().Length
Impact: Eliminates allocation on every Cell.Grapheme property set
- Validation now happens without intermediate array allocation
- Particularly beneficial for cell-based operations and grid rendering
All unit tests pass (12,055 parallelizable + 1,173 non-parallel)
Co-authored-by: tig <585482+tig@users.noreply.github.com>
Applied ArrayPool pattern to eliminate grapheme array allocations:
- Use ArrayPool<string>.Shared.Rent() instead of .ToArray()
- Track actual grapheme count separately from rented array length
- Return array to pool in finally block for guaranteed cleanup
- Handle rare case where array needs to grow during enumeration
Impact: Eliminates 10-60+ allocations/second for animated content
- Progress bars: ~20-40 allocs/sec → 0
- Text-heavy UIs with frequent redraws significantly improved
All unit tests pass (12,055 parallelizable + 1,173 non-parallel)
Co-authored-by: tig <585482+tig@users.noreply.github.com>
Applied the same allocation-free pattern from GetCellMap() to GetMap():
- Reuse List<IntersectionDefinition> buffer instead of LINQ .ToArray()
- Use CollectionsMarshal.AsSpan() to create ReadOnlySpan
- Eliminates 1,920+ allocations per border redraw (80x24)
- Reduces from O(pixels) allocations to 1 allocation total
All unit tests pass (12,055 parallelizable + 1,173 non-parallel)
Co-authored-by: tig <585482+tig@users.noreply.github.com>
* Initial plan
* Delete AnsiColorNameResolver and MultiStandardColorNameResolver, add legacy 16-color names to StandardColor
Co-authored-by: tig <585482+tig@users.noreply.github.com>
* Refactor and enhance tests for Color, Region, and Lines
Refactored `Color` struct by removing unused methods and simplifying logic. Updated namespaces for better organization. Enhanced test coverage for `Color`, `Region`, and `LineCanvas` with new test cases, parameterized tests, and edge case handling.
Added `StraightLineExtensionsTests`, `StraightLineTests`, and `RegionClassTests` to validate behavior under various scenarios. Improved `MergeRectangles` stability and addressed crash patterns. Removed legacy features and unused code. Enhanced documentation and optimized performance in key methods.
* Improve Color struct and StandardColors functionality
Enhanced the Color struct to fully support the alpha channel for rendering intent while maintaining semantic color identity. Updated TryNameColor to ignore alpha when matching colors, ensuring transparency does not affect color resolution. Expanded XML documentation to clarify alpha channel usage and future alpha blending support.
Improved drawing documentation to explain the lifecycle, deferred rendering, and color support, including 24-bit true color and legacy 16-color compatibility. Added a new section on transparency and its role in rendering.
Revised StandardColors implementation to use modern C# features and ensure consistent ARGB mapping. Added comprehensive tests for StandardColors and Color, covering alpha handling, color parsing, thread safety, and aliased color resolution. Removed outdated tests relying on legacy behavior.
Enhanced code readability, maintainability, and test coverage to ensure correctness and backward compatibility.
* Code cleanup
* Code cleanup
* Fix warnings. Code cleanup
* Add comprehensive unit tests for ColorStrings class
Introduced a new test class `ColorStringsTests` under the
`DrawingTests.ColorTests` namespace to validate the functionality
of the `ColorStrings` class.
Key changes include:
- Added tests for `GetColorName` to verify behavior for standard
and non-standard colors, ignoring alpha channels, and handling
known colors.
- Added tests for `GetStandardColorNames` to ensure the method
returns a non-empty, alphabetically sorted collection containing
all `StandardColor` enum values.
- Implemented tests for `TryParseStandardColorName` to validate
case-insensitive parsing, hex color support, handling invalid
input, and `ReadOnlySpan<char>` compatibility.
- Added tests for `TryParseNamedColor` to verify parsing of named
and hex colors, handling of aliases, and `ReadOnlySpan<char>`
support.
- Added round-trip tests to ensure consistency between
`GetColorName`, `TryParseNamedColor`, `GetStandardColorNames`,
and `TryParseStandardColorName`.
These tests ensure robust validation of color parsing and naming
functionality.
---------
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>
* pre-alpha -> alpha
* don't build docs for v2_release
* Pulled from v2_release
* Refactor migration guide for Terminal.Gui v2
Restructured and expanded the migration guide to provide a comprehensive resource for transitioning from Terminal.Gui v1 to v2. Key updates include:
- Added a Table of Contents for easier navigation.
- Summarized major architectural changes in v2, including the instance-based application model, IRunnable architecture, and 24-bit TrueColor support.
- Updated examples to reflect new patterns, such as initializers replacing constructors and explicit disposal using `IDisposable`.
- Documented changes to the layout system, including the removal of `Absolute`/`Computed` styles and the introduction of `Viewport`.
- Standardized event patterns to use `object sender, EventArgs args`.
- Detailed updates to the Keyboard, Mouse, and Navigation APIs, including configurable key bindings and viewport-relative mouse coordinates.
- Replaced legacy components like `ScrollView` and `ContextMenu` with built-in scrolling and `PopoverMenu`.
- Clarified disposal rules and introduced best practices for resource management.
- Provided a complete migration example and a summary of breaking changes.
This update aims to simplify the migration process by addressing breaking changes, introducing new features, and aligning with modern .NET conventions.
* Updated runnable
* Refactor ApplicationStressTests for modularity and robustness
Refactored `ApplicationStressTests` to use `IApplication`
instances instead of static methods, enabling better
testability and alignment with dependency injection.
Enhanced timeout handling in `RunTest` with elapsed time
tracking and debugger-aware polling intervals. Improved
error handling by introducing exceptions for timeouts and
ensuring proper resource cleanup with `application.Dispose`.
Refactored `Launch` and `InvokeLeakTest` methods for
clarity and consistency. Removed redundant code and
improved overall readability and maintainability.
* Pulled from v2_release
* Refactor migration guide for Terminal.Gui v2
Restructured and expanded the migration guide to provide a comprehensive resource for transitioning from Terminal.Gui v1 to v2. Key updates include:
- Added a Table of Contents for easier navigation.
- Summarized major architectural changes in v2, including the instance-based application model, IRunnable architecture, and 24-bit TrueColor support.
- Updated examples to reflect new patterns, such as initializers replacing constructors and explicit disposal using `IDisposable`.
- Documented changes to the layout system, including the removal of `Absolute`/`Computed` styles and the introduction of `Viewport`.
- Standardized event patterns to use `object sender, EventArgs args`.
- Detailed updates to the Keyboard, Mouse, and Navigation APIs, including configurable key bindings and viewport-relative mouse coordinates.
- Replaced legacy components like `ScrollView` and `ContextMenu` with built-in scrolling and `PopoverMenu`.
- Clarified disposal rules and introduced best practices for resource management.
- Provided a complete migration example and a summary of breaking changes.
This update aims to simplify the migration process by addressing breaking changes, introducing new features, and aligning with modern .NET conventions.
* Refactor to use Application.Instance for lifecycle management
Replaced all occurrences of `ApplicationImpl.Instance` with the new `Application.Instance` property across the codebase to align with the updated application lifecycle model.
Encapsulated the `ApplicationImpl` class by making it `internal`, ensuring it is no longer directly accessible outside its assembly. Introduced the `[Obsolete]` `Application.Instance` property as a backward-compatible singleton for the legacy static `Application` model, while encouraging the use of `Application.Create()` for new code.
Updated `MessageBox` methods to use `Application.Instance` for consistent modal dialog management. Improved documentation to reflect these changes and emphasize the transition to the instance-based application model.
Performed code cleanup in multiple classes to ensure consistency and maintainability. These changes maintain backward compatibility while preparing the codebase for the eventual removal of the legacy `ApplicationImpl` class.
* Fix doc bug
* - Removed obsolete `.cd` class diagram files.
- Introduced `IRunnable` interface for decoupling component execution.
- Added fluent API for running dialogs and retrieving results.
- Enhanced `View` with `App` and `Driver` properties for better decoupling.
- Improved testability with support for mock and real applications.
- Implemented `IDisposable` for proper resource cleanup.
- Replaced `RunnableSessionStack` with `SessionStack` for session management.
- Updated driver architecture to align with the new model.
- Scoped `IKeyboard` to application contexts for modularity.
- Updated documentation with migration strategies and best practices.
These changes modernize the library, improve maintainability, and align with current development practices.
* Pulled from v2_release
* Refactor migration guide for Terminal.Gui v2
Restructured and expanded the migration guide to provide a comprehensive resource for transitioning from Terminal.Gui v1 to v2. Key updates include:
- Added a Table of Contents for easier navigation.
- Summarized major architectural changes in v2, including the instance-based application model, IRunnable architecture, and 24-bit TrueColor support.
- Updated examples to reflect new patterns, such as initializers replacing constructors and explicit disposal using `IDisposable`.
- Documented changes to the layout system, including the removal of `Absolute`/`Computed` styles and the introduction of `Viewport`.
- Standardized event patterns to use `object sender, EventArgs args`.
- Detailed updates to the Keyboard, Mouse, and Navigation APIs, including configurable key bindings and viewport-relative mouse coordinates.
- Replaced legacy components like `ScrollView` and `ContextMenu` with built-in scrolling and `PopoverMenu`.
- Clarified disposal rules and introduced best practices for resource management.
- Provided a complete migration example and a summary of breaking changes.
This update aims to simplify the migration process by addressing breaking changes, introducing new features, and aligning with modern .NET conventions.
* Update: Revamp Terminal.Gui v2 What's New document
Comprehensively updated the "What's New" document for Terminal.Gui v2 to improve clarity, structure, and usability. Key changes include:
- Updated the document title to better reflect its purpose.
- Added a detailed table of contents for improved navigation.
- Enhanced the "Overview" section with a concise summary of v2 improvements.
- Expanded the "Architectural Overhaul" section with a "Design Philosophy" subsection.
- Introduced new sections for the instance-based application model and IRunnable architecture.
- Modernized code examples to align with .NET best practices.
- Added detailed explanations for TrueColor, adornments, and user-configurable themes.
- Documented built-in scrolling, advanced layout features, and enhanced navigation.
- Listed new views (e.g., `CharMap`, `ColorPicker`) and improvements to existing views.
- Described enhanced input handling, including the new `Key` class and key binding system.
- Added sections on configuration persistence, debugging tools, and performance metrics.
- Highlighted support for Sixel images, AOT compatibility, and improved Unicode handling.
- Summarized the transformative updates in the conclusion.
These changes aim to provide a structured, developer-friendly guide to the new features and improvements in Terminal.Gui v2.
* Updadted README
Restructured and expanded the migration guide to provide a comprehensive resource for transitioning from Terminal.Gui v1 to v2. Key updates include:
- Added a Table of Contents for easier navigation.
- Summarized major architectural changes in v2, including the instance-based application model, IRunnable architecture, and 24-bit TrueColor support.
- Updated examples to reflect new patterns, such as initializers replacing constructors and explicit disposal using `IDisposable`.
- Documented changes to the layout system, including the removal of `Absolute`/`Computed` styles and the introduction of `Viewport`.
- Standardized event patterns to use `object sender, EventArgs args`.
- Detailed updates to the Keyboard, Mouse, and Navigation APIs, including configurable key bindings and viewport-relative mouse coordinates.
- Replaced legacy components like `ScrollView` and `ContextMenu` with built-in scrolling and `PopoverMenu`.
- Clarified disposal rules and introduced best practices for resource management.
- Provided a complete migration example and a summary of breaking changes.
This update aims to simplify the migration process by addressing breaking changes, introducing new features, and aligning with modern .NET conventions.