Commit Graph

8219 Commits

Author SHA1 Message Date
Tig
f41b009f7c Maybe fix #4444 2025-12-23 11:57:56 -07:00
Tig
fd3ac9c95e Improve Dialog/MessageBox sizing and design-time support
Refactor Dialog and MessageBox sizing logic to use the greater of percentage-based minimums or required subview size, ensuring dialogs are never too small for their content. Lower default minimum sizes for both Dialog and MessageBox.

Implement IDesignable for Dialog, providing design-time sample content and buttons. Dialog appearance now switches styles based on modal/design mode.

Refactor Dialogs demo for clarity, error handling, and modern C# usage. Update View content size calculations to include all subviews (including padding) for more accurate layout.

General code modernization: use C# 9/10 features, improve readability, and maintainability.
2025-12-23 11:18:57 -07:00
Tig
8e89239daa Update Dialog.cs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-12-22 21:19:13 -07:00
Tig
8a829dc6f3 Tweaks.
Refactor Dialog tests to use fake driver; cleanup config

- Migrated Dialog alignment/layout tests to ViewsTests using FakeDriverBase and a fake driver for improved isolation and parallelization.
- Removed old DialogTests from UnitTests; new tests use explicit disposal and resource management.
- Refactored Dialog static default properties to use auto-properties with [ConfigurationProperty] attributes, removing old backing fields and simplifying code.
- Made DriverAssert public for cross-project test use.
- Removed obsolete test migration and performance analysis markdown docs.
- Improved test infrastructure for future migrations.
2025-12-22 15:50:19 -07:00
copilot-swe-agent[bot]
740557e879 Address code review feedback
- Initialize maxHeight with descriptive default value (1)
- Add comment to clarify padding update condition logic
- Add Dispose override to unsubscribe from FrameChanged events
- Prevents potential memory leaks from event handlers

Co-authored-by: tig <585482+tig@users.noreply.github.com>
2025-12-22 04:08:25 +00:00
copilot-swe-agent[bot]
2421066a42 Fix MessageBox test expectations for bottom Padding layout
- Updated test expectations to match new layout where buttons are in Padding
- Text content now has separate space from button row in Padding
- One edge case (empty message + button) no longer auto-expands width for button
- All Dialog and MessageBox tests now passing

Co-authored-by: tig <585482+tig@users.noreply.github.com>
2025-12-22 04:00:01 +00:00
copilot-swe-agent[bot]
804d874ba0 Implement bottom Padding for Dialog buttons - WIP
- Modified Dialog.AddButton() to add buttons to Padding when available
- Added EndInit() override to move buttons from Dialog to Padding
- Added UpdatePaddingBottom() to set Padding thickness based on button height
- Added FrameChanged event handler for dynamic padding updates
- Updated MessageBox tests to reflect new layout (buttons in separate Padding area)
- Dialog tests still passing

Co-authored-by: tig <585482+tig@users.noreply.github.com>
2025-12-22 03:54:01 +00:00
copilot-swe-agent[bot]
e69a82aea4 Initial plan 2025-12-22 03:36:46 +00:00
Copilot
fb4043afbc Fixes #3829. Rename Slider to LinearRange and implement CWP (#4509)
* Initial plan

* Rename Slider to LinearRange - files and code updated

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

* Fix variable name mismatches in scenario files

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

* Fix typos in comments identified by code review

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

* Update HelpText for consistency with LinearRange rename

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

* Refactor LinearRange properties to use CWP with CWPPropertyHelper

- Added CWP events (Changing/Changed) for Type, LegendsOrientation, MinimumInnerSpacing, ShowLegends, ShowEndSpacing, and UseMinimumSize properties
- Used CWPPropertyHelper for consistent property change workflow
- Added virtual OnChanging/OnChanged methods for each property
- All existing tests pass

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

* Fix CWP property implementations - remove duplicate field updates in doWork

- CWPPropertyHelper updates the ref parameter, so doWork should only contain side effects
- Fixed Type, MinimumInnerSpacing, LegendsOrientation, ShowLegends, ShowEndSpacing, and UseMinimumSize
- Added comprehensive CWP tests for property changes (9 new tests, all passing)
- All 45 pre-existing LinearRange tests still pass (10 were already failing before changes)

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

* Add fluent integration tests for LinearRange

- Created LinearRangeFluentTests with 5 test scenarios
- Tests cover rendering, navigation, type changes with CWP events, range selection, and vertical orientation
- All tests build successfully

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

* Fix unit tests and address review comments

- Fixed review comments: Updated Title properties from "_Slider" to "_LinearRange" in DimAutoDemo and ViewportSettings
- Fixed review comment: Renamed filterSlider to filterLinearRange in Mouse.cs
- Fixed CWP implementation: Use local variable instead of backing field as ref parameter to CWPPropertyHelper
- This ensures doWork can update the backing field BEFORE SetContentSize() reads it
- All 55 LinearRange tests now passing (was 45/55, now 55/55)

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

* Update DimAutoDemo.cs

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

* Update ViewportSettings.cs

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

* code cleanup

* Refactor LinearRanges scenario for clarity and modularity

Refactored the LinearRanges scenario to separate UI setup, configuration, and event logic. The Main() method now handles all UI layout, configuration controls, and event wiring, while MakeSliders() is responsible only for adding LinearRange controls to the main window. Updated event handlers to use discard parameters for unused arguments and modernized code with collection initializers and LINQ. This results in a clearer separation of concerns and improved maintainability.

* un did change

* cleanup

* cleanup

* cleanup

* fixed unit test
code cleanup

---------

Co-authored-by: Tig <tig@users.noreply.github.com>
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: Copilot <175728472+Copilot@users.noreply.github.com>
2025-12-21 10:40:09 -07:00
Copilot
4145b984ba Fixes #2485 ++ - Wizard v2 architecture modernization with Padding-based layout (#4510)
* Initial plan

* Fix Wizard v2 architecture issues - ScrollBar API, event handlers, key bindings

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

* Implement issue #4155 - Put nav buttons in bottom Padding, Help in right Padding

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

* Address code review feedback - Extract helper method, improve null checks

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

* Fix disposal issue - Ensure _helpTextView is always disposed

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

* Refactor & improvements. WIP

* Tweaking layout

* Wizard tweaks

* Added View.GetSubViews that optinoally gets subviews of adornments

* Refactor Wizard API: modern events, layout, and design

- Replaced custom event args with standard .NET event args (CancelEventArgs, ValueChangingEventArgs, etc.)
- Removed Finished event; use Accepting for wizard completion
- Updated Cancelled, MovingBack, MovingNext to use CancelEventArgs
- Refactored UICatalog scenarios and tests to new event model
- Improved WizardStep sizing and wizard auto-resizing to content
- Enhanced IDesignable for Wizard and WizardStep with richer design-time UI
- Simplified help text padding logic in WizardStep
- Removed obsolete code and modernized code style throughout
- Improves API consistency, usability, and .NET idiomatic usage

* Fixes #4515 - Navigating into and out of Adornments does not work

* WIP. QUite broken.

* All fixed?

* Tweaks.

* Exclude Margin subviews from drawing; add shadow tests

Update Margin adornment to skip drawing subviews that are themselves Margin views, preventing unsupported nested Margin rendering. Add unit tests to verify that opaque-shadowed buttons in Margin are not drawn, while Border and Padding still support shadow rendering. Update test class to use output helper and assert driver output.

* Final code cleanup and test improvements.

* Update Margin.cs

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

* Update View.cs

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

* Update View.Hierarchy.cs

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

* Update View.Hierarchy.cs

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

* Refactor: code style, formatting, and minor logic cleanup

- Standardized spacing and formatting for method signatures and object initializations.
- Converted simple methods and properties to expression-bodied members for conciseness.
- Replaced named arguments with positional arguments for consistency.
- Improved XML documentation formatting for readability.
- Simplified logic in event handlers (e.g., Wizard Back button).
- Removed redundant checks where properties are guaranteed to exist.
- Fixed minor bugs related to padding, height calculation, and event handling.
- Adopted consistent use of `var` for local variables.
- Corrected namespace declarations.
- Refactored methods returning constants to use expression-bodied syntax.
- General code cleanup for clarity and maintainability; no breaking changes.

* api docs

---------

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: Copilot <175728472+Copilot@users.noreply.github.com>
2025-12-21 07:42:04 -07:00
Tig
af0efb3c64 Partially modernizes Scenarios (#4512) 2025-12-19 20:02:04 -07:00
Copilot
8f4ad8a7d4 Fixes #4147. HotKeySpecifier 0xFFFF does not clear HotKey (#4508)
* Initial plan

* Fix: Set HotKey to Key.Empty when HotKeySpecifier is 0xFFFF

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

* Fix code style: Use explicit type instead of var for View

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

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tig <585482+tig@users.noreply.github.com>
2025-12-18 07:20:30 -07:00
Ryan Martin
bc897278ed Update version ranges for Microsoft.Extensions.Logging.Abstractions and Microsoft.Extensions.DependencyInjection packages (#4511)
Co-authored-by: Tig <tig@users.noreply.github.com>
2025-12-18 07:15:22 -07:00
Copilot
f4b10511c0 Fixes #4495 - Adds SuperViewChanging event to View following Cancellable Work Pattern (#4503)
* Initial plan

* Add SuperViewChanging event infrastructure and tests

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

* Refactor SuperViewChanging to follow Cancellable Work Pattern with cancellation support

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

* Remove SuperViewChangingEventArgs class and use CancelEventArgs<View?> directly

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

* Simplified SuperViewChanged

* Refactor SuperView change to use CWP and event args

Refactored the handling of SuperView changes in the View hierarchy to use the Cancellable Work Pattern (CWP) and standardized event argument types. The SuperView property is now settable only via an internal SetSuperView method, which leverages CWP for property changes and cancellation.

- Updated OnSuperViewChanging to accept ValueChangingEventArgs<View?>.
- SuperViewChanging event now uses EventHandler<ValueChangingEventArgs<View?>>; cancellation is via e.Handled = true.
- OnSuperViewChanged and SuperViewChanged now use ValueChangedEventArgs<View?>.
- All SuperView assignments in Add, Remove, and RemoveAll now use SetSuperView, which returns a bool for cancellation.
- CWPPropertyHelper.ChangeProperty now accepts a sender parameter, passed to event handlers.
- All property changes in View now pass this as sender to ChangeProperty.
- Updated event handler signatures and overrides in MenuBar, StatusBar, TextField, and TextView.
- Updated unit tests to use new event args and cancellation pattern.
- Minor code cleanups and improved comments.

These changes modernize and standardize property change handling, improving API consistency, extensibility, and testability.

* Refactor subview removal and event arg types

Removed redundant index check when removing subviews in View.cs, simplifying the cleanup loop. Updated TextField.OnSuperViewChanged to use a non-nullable ValueChangedEventArgs<View> parameter, enforcing stricter type safety.

---------

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>
2025-12-18 06:32:01 -07:00
Copilot
993487d0a1 Fixes #4493 - GetViewsUnderLocation does not return subviews of Adornment if Parent has a Subview under Adornment (#4507)
* Initial plan

* Add failing test that reproduces GetViewsUnderLocation bug

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

* Fix GetViewsUnderLocation to correctly order adornment subviews

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

* Remove debug output from test

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

* Address code review: Extract duplicate coordinate conversion

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

* Code cleanup

* code cleanup

---------

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>
2025-12-18 06:31:07 -07:00
Tig
ff18ad4532 Fixes build warnings recently introduced (#4506)
* Fixed warnings I recently introduced.

Replaced nullable App references with null-forgiving operator (!) in MessageBox and dialog calls to suppress nullable warnings. Updated XML docs to use Dim.Fill() and clarified method references. Made Application.Popover registration null-safe. Fixed test output helper usage in ShadowTests. No functional changes.

* Fixes Release build warnings
2025-12-17 12:57:38 -07:00
BDisp
1a54ff0872 Fixes #4502. Shadows in overlapping views are not rendered consistently (#4465)
* Fixes Wide Glyphs

* Fix some unit tests failure

* Fix more unit tests

* Fixes #4468 - `MouseGrab` regressions (#4469)

* Fixed mouse grab issue

* Fixed mouse grab regrssions.

* Update Terminal.Gui/ViewBase/View.Mouse.cs

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

* Update Terminal.Gui/ViewBase/View.Mouse.cs

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

* Update Terminal.Gui/ViewBase/View.Mouse.cs

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

* Update Terminal.Gui/ViewBase/View.Mouse.cs

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

* Update Terminal.Gui/ViewBase/View.Mouse.cs

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

* Update Terminal.Gui/ViewBase/View.Mouse.cs

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

* code cleanup

* Update Terminal.Gui/ViewBase/View.Mouse.cs

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

* Addressing pr feedback

* updated mouse.md

---------

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

* Fixes #4050. Rename Command.Select and Selecting to Activate/Activating (#4470)

* Initial plan

* Rename Command.Select to Command.Activate and Selecting to Activating

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

* Add Activating event propagation to SuperView

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

* Update all comments and docs referencing Select to Activate

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

* Fix event log messages in examples to use Activating/Activate

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

* Revert automatic Activating event propagation that broke tests

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

* Update docfx documentation to use Activate/Activating terminology

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

* renames

* Revert "Add Activating event propagation to SuperView"

This reverts commit 6d82bee9ad.

* added command diagrams

* mermaid

* updated level 3

* again

* Select->Activate in MouseTests.cs

* Update Terminal.Gui/Views/Selectors/FlagSelector.cs

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

* Refactor: Rename Selecting to Activating in View APIs

Renamed the `Selecting` event and `OnSelecting` method to
`Activating` and `OnActivating` to better reflect their purpose.
Updated all related comments, test method names, variables,
and assertions in `View` and `ViewCommandTests` to align with
the new terminology.

Improved code clarity by using `_` for unused parameters in
lambda expressions. Renamed properties like `HandleSelecting`
to `HandleActivating` and adjusted naming conventions for
consistency (e.g., `OnactivatingCount` to `OnActivatingCount`).

These changes enhance readability, maintainability, and
terminology consistency across the codebase.

* Update Terminal.Gui/Views/Selectors/OptionSelector.cs

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

* Typos

---------

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: Copilot <175728472+Copilot@users.noreply.github.com>

* Add support for wide glyphs into the ShadowStyle.Transparent

* The "IsDirty" content of the wide glyphs should be completely false after being displayed on the screen.

* FillRect must always call AddStr method to properly handle wide characters to invalidate overlapped wide glyphs, etc.

* We must set clip to the driver screen in the case where the view isn't Adornment and SuperView is null, allowing dialogs, popovers, etc to be drawn

* These assertions are important to ensure that the drawing state is consistent

* Subviews must be drawn after the superview content being drawn

* The attribute of next column of a wide glyph should be the same if it's in the clipped area

* Applied #4486

* Updated root view clipping logic to use App's screen or a large default rectangle, ensuring proper drawing area. Added comments clarifying subview drawing order and explaining issues with certain Debug.Assert checks in complex hierarchies, suggesting unit tests instead.

* Remove ClearFrame and always draw Margin if Thickness set

Removed the unused ClearFrame method from the View class. Updated DrawAdornments to always draw the Margin when its Thickness is not empty, regardless of ShadowStyle. This simplifies the drawing logic and removes unnecessary checks.

* Fix margin thickness adjustment

* Fix shadow draw on overlapped views

* Only draw shadows at the end of each runnable

* Only call ClearNeedsDraw in the static Draw method

* Replace unit test as requested

* Also use reverse in margins although not making difference

* Fix the ShadowStyle, ShadowWidth and ShadowHeight logic

* Making sure nothing broke.

* ShadowWidth and ShadowHeight always default to 1 at invalid values

* Removes unused parameter

* Using Rune.ReplacementChar to not confusing with space char inserted by the clearing region

* Using Rune.ReplacementChar

* Using Rune.ReplacementChar

* Fix merge error

* Fixing unit tests

* Reverting changes

* Fixing unit tests

* Fix unit test

* Fix shadow on overlapped views

* Cleanup code

---------

Co-authored-by: Tig <tig@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tig <585482+tig@users.noreply.github.com>
2025-12-17 11:56:31 -07:00
Tig
c19ca48c7b Require non-null IApplication in MessageBox API (#4499) 2025-12-17 05:42:48 -07:00
Tig
9e0fa4c106 Merge pull request #4500 from tig/v2_4488-PopoverMenu 2025-12-17 05:39:26 -07:00
Tig
5bf5a64ef2 Merge branch 'v2_develop' into v2_4488-PopoverMenu 2025-12-16 14:25:16 -07:00
Tig
0a9f4b8ef1 Fixes #4492, #4480 - Transparent shadows cause underlying wide glyph rendering issues (#4490)
* WIP - experiments in fixing shadow rendering issues based on #4465

Previously, shadow size was fixed at 1x1. This change introduces ShadowWidth and ShadowHeight properties to both Margin and View, allowing variable shadow dimensions. The Margin class now manages its own shadow sizing, enforcing valid values based on ShadowStyle (e.g., Opaque and Transparent require a minimum of 1, and Opaque only allows 1). Margin.Thickness is dynamically adjusted to account for shadow size, with original values preserved and restored as needed.

ShadowView rendering is updated to correctly handle wide graphemes (such as emojis) in the shadow area, preventing rendering errors. The View class exposes ShadowWidth and ShadowHeight, synchronizing with Margin. Extensive new unit tests verify correct behavior for shadow sizing, style changes, thickness adjustments, and rendering, including edge cases and visual output.

Additional minor bug fixes and refactoring are included, such as proper management of Margin's cached clip region and correcting a loop order bug in ShadowView. The codebase is also modernized with recent C# features.

* more merge

* added border tests

* Experiment...

* Incorporated latest wideglyphs

* Comment tweaks

* Add Adornments and ViewportSettings editors to WideGlyphs

Introduce AdornmentsEditor and ViewportSettingsEditor with custom border styles and positioning, enhancing UI editing capabilities. Also update arrangeableViewAtEven to use Color.Black and Color.Green, and adjust a commented border style from Dashed to Dotted.

* Fix scenario editors and tweak scenarios.

Enhance ShadowStyles with a second shadow window (transparent style) and a button event handler that shows a message box. In WideGlyphs, add AdornmentsEditor and ViewportSettingsEditor for view property editing, apply custom color schemes to arrangeable views, and update superView with a transparent shadow and increased shadow width. These changes improve interactivity and visualization in the demo scenarios.

* Fix scenario editors and tweak scenarios.

Enhance ShadowStyles with a second shadow window (transparent style) and a button event handler that shows a message box. In WideGlyphs, add AdornmentsEditor and ViewportSettingsEditor for view property editing, apply custom color schemes to arrangeable views, and update superView with a transparent shadow and increased shadow width. These changes improve interactivity and visualization in the demo scenarios.

* Make replacement char themeable via Glyphs.ReplacementChar

Adds Glyphs.ReplacementChar as a configurable replacement character, replacing all uses of Rune.ReplacementChar. The default is now a space (' ') and can be set via config.json. Updates all rendering, string decoding, and buffer invalidation logic to use the new property, ensuring consistency and themeability. Updates tests and comments accordingly. Also includes minor UI tweaks in WideGlyphs.cs and .DotSettings updates.

* merging

* merge errors

* merged

* merged

* Refactor shadow properties to Margin; update tests

ShadowWidth and ShadowHeight are now managed solely in the Margin class, with related properties and validation logic removed from View. All code and tests now use view.Margin.ShadowWidth/ShadowHeight. Tests and documentation were updated accordingly, and wide glyph handling in test output was improved for consistency.

* Simplify ShadowSize; remove it from View as it's infreqnetly used. Make it a Size to reduce API surface area.

Replace ShadowWidth/ShadowHeight with a single ShadowSize property (of type Size) in the Margin class and related code. Update all usages, validation logic, and tests to use ShadowSize.Width and ShadowSize.Height. Introduce TryValidateShadowSize for unified validation. Modernize code with C# features and improve clarity and maintainability by treating shadow dimensions as a single unit.

* reveted

* Fix wide glyph attribute handling for second column

Ensure the attribute for the second column of wide glyphs is set correctly when within the clip region, addressing issues #4258 and #4492. Add comprehensive unit tests to verify correct attribute assignment and output rendering, including scenarios with transparent shadows. Remove obsolete test code for clarity. This improves color/style consistency for wide glyphs, especially in overlapping UI situations.

* added url
2025-12-16 14:23:32 -07:00
Tig
2802ccf5bf Merge branch 'v2_develop' into v2_4488-PopoverMenu 2025-12-16 14:06:28 -07:00
Tig
21407c710f Rewrite and expand Popovers.md documentation
Completely overhauled Popovers.md with a comprehensive guide to popovers in Terminal.Gui. Added detailed explanations, requirements, and best practices for creating, registering, and managing popovers. Included extensive code examples for PopoverMenu, custom popovers, and common scenarios such as context menus and autocomplete. Documented keyboard and mouse event handling, lifecycle management, and provided an API reference. Removed outdated and unstructured content.
2025-12-16 13:37:46 -07:00
Tig
4dc193b6a3 Expand and clarify popover XML documentation
Significantly improve and expand XML documentation for IPopover, PopoverBaseImpl, and PopoverMenu. Add detailed remarks on popover lifecycle, registration requirements, focus, input, and mouse handling. Provide usage examples, parameter and exception documentation, and clarify method/property summaries. Warn about the need to register popovers before showing. No functional code changes except for minor summary tweaks for clarity.
2025-12-16 13:30:58 -07:00
Purple
4673cfc106 Showing popup everytime we have new suggestions (#4482) 2025-12-15 19:33:22 -07:00
Tig
4c772bd5f3 Fixes #4497 - makes replacement char conifgurable (#4498)
* Add Glyphs.ReplacementChar config property

Introduced Glyphs.ReplacementChar to allow overriding the Unicode replacement character, defaulting to a space (' '). Updated both config.json and Glyphs.cs with this property, scoped to ThemeScope and documented as an override for Rune.ReplacementChar.

* Standardize to Glyphs.ReplacementChar for wide char invalidation

Replaced all uses of Rune.ReplacementChar.ToString() with Glyphs.ReplacementChar.ToString() in OutputBufferImpl and related tests. This ensures consistent use of the replacement character when invalidating or overwriting wide characters in the output buffer.

* Add configurable wide glyph replacement chars to OutputBuffer

Allows setting custom replacement characters for wide glyphs that cannot fit in the available space via IOutputBuffer.SetReplacementChars. Updated IDriver to expose GetOutputBuffer. All code paths and tests now use the configurable characters, improving testability and flexibility. Tests now use '①' and '②' for clarity instead of the default replacement character.

* Fixed warnings.

* Update IOutputBuffer.cs

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

* Add tests for wide char clipping edge cases in OutputBuffer

Added three unit tests to OutputBufferWideCharTests.cs to verify and document OutputBufferImpl's behavior when wide (double-width) characters are written at the edges of a clipping region. Tests cover cases where the first or second column of a wide character is outside the clip, as well as when both columns are inside. The tests assert correct use of replacement characters, dirty flags, and column advancement, and document that certain code paths are currently unreachable due to IsValidLocation checks.

* Clarify dead code path with explanatory comments

Added comments to mark a rarely executed code path as dead code, noting it is apparently never called. Referenced the related test scenario AddStr_WideChar_FirstColumnOutsideClip_SecondColumnInside_CurrentBehavior for context. No functional changes were made.

* Remove dead code for wide char partial clip handling

Removed unreachable code that handled the case where the first column of a wide character is outside the clipping region but the second column is inside. This logic was marked as dead code and never called. Now, only the cases where the second column is outside the clip or both columns are in bounds are handled. This simplifies the code and removes unnecessary checks.

* Replaces Glyphs.ReplacementChar with Glyphs.WideGlyphReplacement to clarify its use for clipped wide glyphs. Updates IOutputBuffer to use SetWideGlyphReplacement (single Rune) instead of SetReplacementChars (two Runes). Refactors OutputBufferImpl and all test code to use the new property and method. Removes second-column replacement logic, simplifying the API and improving consistency. Updates comments and test assertions to match the new naming and behavior.

* Update themes in config.json and add new UI Catalog props

Renamed "UI Catalog Theme" to "UI Catalog" and removed the
"Glyphs.ReplacementChar" property. Added several new properties
to the "UI Catalog" theme, including default shadow, highlight
states, button alignment, and separator line style. Also added
"Glyphs.WideGlyphReplacement" to the "Hot Dog Stand" theme.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-12-15 09:26:52 -07:00
Tig
fb1a3e03f3 Fixes some bugs in the Scenario/EditorsAndHelpers and backports WideGlyphs (#4494)
* Fix scenario editors and tweak scenarios.

Enhance ShadowStyles with a second shadow window (transparent style) and a button event handler that shows a message box. In WideGlyphs, add AdornmentsEditor and ViewportSettingsEditor for view property editing, apply custom color schemes to arrangeable views, and update superView with a transparent shadow and increased shadow width. These changes improve interactivity and visualization in the demo scenarios.

* Fix scenario editors and tweak scenarios.

Enhance ShadowStyles with a second shadow window (transparent style) and a button event handler that shows a message box. In WideGlyphs, add AdornmentsEditor and ViewportSettingsEditor for view property editing, apply custom color schemes to arrangeable views, and update superView with a transparent shadow and increased shadow width. These changes improve interactivity and visualization in the demo scenarios.

* Scenario Editors code cleanup & latent bug fixes.

Refactored event handler patterns to use correct sender values and discards for unused parameters, aligning with .NET conventions. Cleaned up code by removing redundant usings and comments, and clarified logic in property setters and switch statements. Enhanced robustness and clarity in editor components, fixing issues with value changes, event subscriptions, and nullability. Improved disposal logic in EditorBase and made minor UI and label adjustments. Added "diag" to the custom dictionary. These changes modernize event handling and address subtle bugs in the UICatalog editors.

* code cleanup

* Update Examples/UICatalog/Scenarios/EditorsAndHelpers/EditorBase.cs

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

* PR feedback.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-12-14 17:31:57 -07:00
Tig
84f977937b Adds transparent shadow test (#4487)
* Add tests for overlapped view transparent shadow config

* Add test for transparent shadow showing background text

Added a unit test to verify that overlapped views with transparent shadows allow background text to show through the shadow area. The test checks both right and bottom shadow regions and asserts that the underlying content is visible, ensuring correct rendering behavior.

* Add test for transparent shadow in overlapped views

Adds Overlapped_View_With_TransparentShadow_Driver_Output_Shows_Background_Text to verify that background text is visible through transparent shadows in overlapped views. The test checks for correct rendering, ANSI color codes, and ensures the shadow area displays the expected background character.

* Refactor transparent shadow test for stricter output check

Update Overlapped_View_With_TransparentShadow_Driver_Output_Shows_Background_Text to use a smaller screen, dynamic sizing, and new overlapped view text. Replace loose output assertion with strict ANSI output comparison. Make shadow cell coordinate calculation dynamic based on view frame.

* Consolidate transparent shadow tests into ShadowStyleTests

Moved the transparent shadow driver output test from OverlappedViewTransparentShadowTests to ShadowStyleTests for better organization. Removed the now-redundant OverlappedViewTransparentShadowTests class and updated ShadowStyleTests to support output logging. All transparent shadow rendering tests are now grouped under ShadowStyleTests.
2025-12-12 18:24:34 -07:00
Tig
48d6e13138 Fixes #4466 - FillRect Corrupts Wide Characters When Overlapping (#4486)
* 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>
2025-12-12 16:57:29 -07:00
Copilot
e7a4df492d Fixes #4050. Rename Command.Select and Selecting to Activate/Activating (#4470)
* Initial plan

* Rename Command.Select to Command.Activate and Selecting to Activating

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

* Add Activating event propagation to SuperView

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

* Update all comments and docs referencing Select to Activate

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

* Fix event log messages in examples to use Activating/Activate

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

* Revert automatic Activating event propagation that broke tests

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

* Update docfx documentation to use Activate/Activating terminology

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

* renames

* Revert "Add Activating event propagation to SuperView"

This reverts commit 6d82bee9ad.

* added command diagrams

* mermaid

* updated level 3

* again

* Select->Activate in MouseTests.cs

* Update Terminal.Gui/Views/Selectors/FlagSelector.cs

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

* Refactor: Rename Selecting to Activating in View APIs

Renamed the `Selecting` event and `OnSelecting` method to
`Activating` and `OnActivating` to better reflect their purpose.
Updated all related comments, test method names, variables,
and assertions in `View` and `ViewCommandTests` to align with
the new terminology.

Improved code clarity by using `_` for unused parameters in
lambda expressions. Renamed properties like `HandleSelecting`
to `HandleActivating` and adjusted naming conventions for
consistency (e.g., `OnactivatingCount` to `OnActivatingCount`).

These changes enhance readability, maintainability, and
terminology consistency across the codebase.

* Update Terminal.Gui/Views/Selectors/OptionSelector.cs

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

* Typos

---------

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: Copilot <175728472+Copilot@users.noreply.github.com>
2025-12-09 12:42:34 -07:00
Tig
b2cf674e0b Fixes #4468 - MouseGrab regressions (#4469)
* Fixed mouse grab issue

* Fixed mouse grab regrssions.

* Update Terminal.Gui/ViewBase/View.Mouse.cs

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

* Update Terminal.Gui/ViewBase/View.Mouse.cs

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

* Update Terminal.Gui/ViewBase/View.Mouse.cs

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

* Update Terminal.Gui/ViewBase/View.Mouse.cs

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

* Update Terminal.Gui/ViewBase/View.Mouse.cs

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

* Update Terminal.Gui/ViewBase/View.Mouse.cs

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

* code cleanup

* Update Terminal.Gui/ViewBase/View.Mouse.cs

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

* Addressing pr feedback

* updated mouse.md

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-12-09 08:32:04 -07:00
Copilot
aab90e1fbc Fixes #4463 - Adds LineCanvas.GetRegion() - 10x performance regression in RenderLineCanvas (#4464)
* Initial plan

* Revert xunit maxParallelThreads to default to fix performance issue

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

* Fix 10x performance regression in RenderLineCanvas

Found via binary search of 51 commits that commit 027018368 introduced
the slowdown by calling context.AddDrawnRectangle() for every cell in
the LineCanvas (thousands of times per frame).

Fixed by reporting the entire LineCanvas.Bounds once instead of per-cell.

Test results:
- Before: 1m 33s (10x slower than v2_release)
- After: 9s (same as v2_release)

Fixes the performance issue in AllViews_Draw_Does_Not_Layout test.

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

* Add comment clarifying LineCanvas coordinate system

Addresses code review feedback about coordinate system conversion.
LineCanvas.Bounds is already in screen-relative coordinates since
cells are stored with screen positions (used with Driver.Move).

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

* Build non-rectangular Region from LineCanvas cells efficiently

Instead of reporting entire LineCanvas.Bounds (which includes empty space),
efficiently build a Region that encompasses only the actual line cells.

Algorithm groups contiguous horizontal cells into spans per row, avoiding
per-cell overhead while accurately representing the non-rectangular shape.

Performance maintained: 10s (same as v2_release)
All tests pass: 5695 drawing tests, 200 LineCanvas tests, 33 transparency tests

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

* Address code review feedback - improve robustness

- Remove redundant empty check (caller already verifies)
- Add safety check for empty row groups to prevent IndexOutOfRangeException
- Update documentation to clarify precondition

Tests still pass with 9s performance.

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

* Optimize BuildRegionFromLineCells - eliminate redundant sort

Remove redundant OrderBy since X values are already sorted from the
initial OrderBy().ThenBy() operation. Also remove unreachable empty
check since GroupBy guarantees non-empty groups.

Performance maintained at 9s.

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

* Final code review fixes - improve comments and add defensive check

- Clarify comment about sorting behavior
- Add defensive empty check for edge cases
- Performance maintained at 10s

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

* Move BuildRegionFromCells to LineCanvas class

Moved the BuildRegionFromCells method from View.Drawing.cs to LineCanvas
where it logically belongs as a public static method.

Updated View.Drawing.cs to call Drawing.LineCanvas.BuildRegionFromCells.

Performance maintained at 9s. All tests pass.

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

* Update documentation for BuildRegionFromCells

- Clarify that method handles empty cellMap gracefully
- Improve comment explaining the defensive empty check
- Performance maintained at 10s

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

* Rename BuildRegionFromCells to GetRegion

Renamed the method as requested to have a more concise name.

Performance maintained at 10s. All tests pass.

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

* Add GetCellMapWithRegion optimization for single-pass iteration

Implemented optimized method that builds both cell map and Region in a
single pass through the canvas bounds, eliminating the need for separate
GetCellMap() and GetRegion() calls.

Benefits:
- Reduces from 2 iterations to 1 (GetCellMap then GetRegion -> single pass)
- Eliminates sorting overhead (O(n log n) -> O(n))
- X values already sorted due to inner loop order
- Builds Region incrementally per row as cells are discovered

Performance maintained at 10s. All tests pass:
- AllViews_Draw_Does_Not_Layout: 10s
- 5695 drawing tests passed
- 200 LineCanvas tests passed
- 33 transparency tests passed

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

* Add comprehensive unit tests for GetRegion and GetCellMapWithRegion

Added 15 new unit tests covering:

GetRegion tests:
- Empty cell map handling
- Single cell regions
- Horizontal and vertical lines
- L-shaped regions
- Discontiguous cells creating separate spans
- Intersecting lines

GetCellMapWithRegion tests:
- Empty canvas handling
- Single horizontal/vertical lines
- Intersecting lines with proper intersection handling
- Complex shapes (boxes)
- Consistency with separate GetCellMap + GetRegion calls
- Negative coordinate handling
- Exclusion region support

All 215 LineCanvas tests pass. Performance maintained at 9s.

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

* Fix code style violations per CONTRIBUTING.md

- Replace var with explicit types (Dictionary<Point, Cell?>, LineCanvas, Region, etc.)
- Replace new TypeName() with target-typed new () where type is declared
- Fix foreach loop to use explicit IGrouping<int, Point> type
- Use StraightLine instead of var in foreach

All style violations fixed per CONTRIBUTING.md coding conventions.
Tests still pass: 215 LineCanvas tests, 9s performance maintained.

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

* Code cleanup.

* Upgrades Transparent Scenario to demonstrate LineCanvas transparency. "dotnet" is drawn using LineCanvas.

* Comment out debug assertions in View drawing logic

The debug assertions in the `View` class, which validated the relationships between `Margin`, `Border`, `Padding`, and their parent objects, as well as their `SubViewNeedsDraw` and `NeedsDraw` states, have been commented out. These assertions were conditionally executed when the current object and its `SuperView` were not of type `Adornment`.

The code has been retained as comments for potential future reference or debugging purposes, but the assertions are no longer active in the current implementation.

---------

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>
2025-12-08 17:13:58 -07:00
Tig
3ae28bbf5a Makes timeout tests more robust to slow GH runners (#4461)
* Fixed MouseGrabView bug.

Added extensive test coverage for `Keyboard`, `Mouse`, `Timeout`, and `Popover` functionalities, including edge cases and concurrent access. Introduced parameterized and data-driven tests to reduce redundancy and improve clarity.

Refactored codebase for modularity and maintainability,
introducing new namespaces and reorganizing classes. Enhanced `MouseImpl`, `KeyboardImpl`, and `Runnable` implementations with improved event handling, thread safety, and support for the Terminal.Gui Cancellable Work Pattern (CWP).

Removed deprecated code and legacy tests, such as `LogarithmicTimeout` and `SmoothAcceleratingTimeout`. Fixed bugs related to mouse grabbing during drag operations and unbalanced `ApplicationImpl.Begin/End` calls. Improved documentation and code readability with modern C# features.

* Modified assertion logic to conditionally skip checks when the safety timeout fires, preventing false negatives. Improved comments to clarify the purpose of the safety timeout and assertion changes.
2025-12-08 12:52:13 -07:00
Tig
f548059a27 Fixes #4258 - Glyphs drawn at mid-point of wide glyphs don't get drawn with clipping (#4462)
* Enhanced `View.Drawing.cs` with improved comments, a new
`DoDrawComplete` method for clip region updates, and
clarified terminology. Added detailed remarks for the
`OnDrawComplete` method and `DrawComplete` event.

Refactored `ViewDrawingClippingTests` to simplify driver
setup, use target-typed `new`, and add a new test for wide
glyph clipping with bordered subviews. Improved handling of
edge cases like empty viewports and nested clips.

Added `WideGlyphs.DrawFlow.md` and
`ViewDrawingClippingTests.DrawFlow.md` to document the draw
flow, clipping behavior, and coordinate systems for both the
scenario and the test.

Commented out redundant `Driver.Clip` initialization in
`ApplicationImpl`. Added a `BUGBUG` comment in `Border` to
highlight missing redraw logic for `LineStyle` changes.

* Uncomment Driver.Clip initialization in Screen redraw

* Fixed it!

* Fixes #4258 - Correct wide glyph and border rendering

Refactored `OutputBufferImpl.AddStr` to improve handling of wide glyphs:
- Wide glyphs now modify only the first column they occupy, leaving the second column untouched.
- Removed redundant code that set replacement characters and marked cells as not dirty.
- Synchronized cursor updates (`Col` and `Row`) with the buffer lock to prevent race conditions.
- Modularized logic with helper methods for better readability and maintainability.

Updated `WideGlyphs.cs`:
- Removed dashed `BorderStyle` and added border thickness and subview for `arrangeableViewAtEven`.
- Removed unused `superView` initialization.

Enhanced tests:
- Added unit tests to verify correct rendering of borders and content at odd columns overlapping wide glyphs.
- Updated existing tests to reflect the new behavior of wide glyph handling.
- Introduced `DriverAssert.AssertDriverOutputIs` to validate raw ANSI output.

Improved documentation:
- Expanded problem description and root cause analysis in `WideGlyphBorderBugFix.md`.
- Detailed the fix and its impact, ensuring proper layering of content at any column position.

General cleanup:
- Removed unused imports and redundant code.
- Improved code readability and maintainability.

* Code cleanup

* Update Tests/UnitTestsParallelizable/ViewBase/Draw/ViewDrawingClippingTests.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 Tests/UnitTestsParallelizable/ViewBase/Draw/ViewDrawingClippingTests.cs

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

* Update Tests/UnitTestsParallelizable/ViewBase/Draw/ViewDrawingClippingTests.cs

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

* Fixed test slowness problem

* Simplified

* Rmoved temp .md files

* Refactor I/O handling and improve testability

Refactored `InputProcessor` and `Output` access by replacing direct property usage with `GetInputProcessor()` and `GetOutput()` methods to enhance encapsulation. Introduced `GetLastOutput()` and `GetLastBuffer()` methods for better debugging and testability.

Centralized `StringBuilder` usage in `OutputBase` implementations to ensure consistency. Improved exception handling with clearer messages. Updated tests to align with the refactored structure and added a new test for wide glyph handling.

Enhanced ANSI sequence handling and simplified cursor visibility logic to prevent flickering. Standardized method naming for consistency. Cleaned up redundant code and improved documentation for better developer clarity.

* Refactored `NetOutput`, `FakeOutput`, `UnixOutput`, and `WindowsOutput` classes to support access to `Output` and added a `IDriver.GetOutput` to acess the `IOutput`. `IOutput` now has a `GetLastOutput` method.

Simplified `DriverAssert` logic and enhanced `DriverTests` with a new test for wide glyph clipping across drivers.

Performed general cleanup, including removal of unused code, improved formatting, and adoption of modern C# practices. Added `using System.Diagnostics` in `OutputBufferImpl` for debugging.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-12-08 12:28:32 -07:00
Tig
5da7e59aa2 Fixes #4456 - Clear MouseGrabView in App.End (#4460)
* Fixed MouseGrabView bug.

Added extensive test coverage for `Keyboard`, `Mouse`, `Timeout`, and `Popover` functionalities, including edge cases and concurrent access. Introduced parameterized and data-driven tests to reduce redundancy and improve clarity.

Refactored codebase for modularity and maintainability,
introducing new namespaces and reorganizing classes. Enhanced `MouseImpl`, `KeyboardImpl`, and `Runnable` implementations with improved event handling, thread safety, and support for the Terminal.Gui Cancellable Work Pattern (CWP).

Removed deprecated code and legacy tests, such as `LogarithmicTimeout` and `SmoothAcceleratingTimeout`. Fixed bugs related to mouse grabbing during drag operations and unbalanced `ApplicationImpl.Begin/End` calls. Improved documentation and code readability with modern C# features.

* Code cleanup.

* Update Tests/UnitTestsParallelizable/Application/Runnable/RunnableIntegrationTests.cs

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

* Improve null handling and simplify test setup

In `MouseImpl.cs`, added an early `return` after the `UngrabMouse()`
call within the `if (view is null)` block to prevent further execution
when `view` is `null`, improving null reference handling.

In `RunnableIntegrationTests.cs`, removed the initialization of the
`IApplication` object (`app`) from the `MultipleRunnables_IndependentResults`
test method, simplifying the test setup and focusing on runnable behavior.

* Code cleanup

* API doc link cleanup

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-12-07 13:01:19 -07:00
BDisp
0270183686 Fixes #4453. Regression in wide glyph rendering on all drivers (#4458) 2025-12-07 11:40:43 -07:00
Copilot
dd12df7fb7 Fixes #4176. Removes View.MouseClick (#4450)
* Initial plan

* Add comprehensive MouseClick removal analysis

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

* Fix code review feedback on analysis document

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

* Add actual line numbers to analysis document

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

* Final polish on analysis document - clarify TextView

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

* Phase 3: Port 6 simple Views from MouseClick to Selecting/MouseBindings

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

* Phase 2: Port 10 Scenarios from MouseClick to Selecting/remove

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

* Update analysis document - Phases 2 & 3 complete

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

* Fix failing tests - Button multi-button support and Label focus handling

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

* Phase 4: Port ScrollBar from OnMouseClick to OnSelecting; remove analysis doc

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

* Phase 5: Update/remove tests that explicitly test MouseClick API

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

* Code cleanup

* Remove MouseClick event

Consolidated mouse event handling by removing the `MouseClick`
event and integrating its functionality into the `MouseEvent`
event. Simplified `MouseEventArgs` documentation and added
support for invoking commands bound to mouse events.

Reorganized code by removing `Mouse Pressed Events` and
`Mouse Click Events` regions, introducing a new `WhenGrabbed
Handlers` region. Updated tests to replace `MouseClick` with
`MouseEvent`, adjusted test logic, and improved variable
naming for clarity.

Removed redundant assertions and unused code related to
`MouseClick`. Improved event propagation logic to ensure
proper handling of unhandled events. Performed general code
cleanup to enhance readability and maintainability.

* Updated deep dives.

---------

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>
2025-12-06 14:41:20 -07:00
Copilot
0eafb5947e Move parallel test repeat logic to stress tests (#4455)
* Initial plan

* Move parallel test repeat logic to stress tests

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

* Simplify unit tests workflow and improve comments

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

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tig <585482+tig@users.noreply.github.com>
2025-12-06 11:58:13 -07:00
Copilot
7a8b6e4465 Fixes #4167. Add Accepted event to View (#4452)
* Initial plan

* Add Accepted event to View and remove duplicate implementations

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

* Update RaiseAccepting to call RaiseAccepted and add comprehensive tests

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

* Fix code style violations - use explicit types and target-typed new

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

---------

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>
2025-12-06 09:36:32 -07:00
BDisp
5e3175cd9d Fixes #4449. Regression in IsLegacyConsole mode where dirty cells are not handled correctly (#4451)
* Fixes #4449. Regression in IsLegacyConsole mode where dirty cells are not handled correctly

* Cursor position is always set in the beginning a new row or on non-dirty flags
2025-12-06 09:09:52 -07:00
Tig
d303943809 Fixes #4004 & #4445 - Merge of Application.ForceDriver and Driver.Force16Colors and windows" broken in conhost and cmd (#4448)
* Fixes #4004. Driver "windows" broken in conhost and cmd

* Fix unit tests

* Remove IsVirtualTerminal from IApplication. Add IDriverInternal and IOutputInternal interfaces

* Fix result.IsSupported

* Remove internal interfaces and add them in the implementations classes

* Move Sixel from IApplication to IDriver interface it's a characteristic of the driver

* Only if IOutput is OutputBase then set the internal properties

* Prevents driver windows error on Unix system

* Fix scenario sixel error

* Comment some tests because is keyboard layout dependent and shifted key is needed to produce them (Pt)

* Add 🇵🇹 regional indicators test proving they ca be joined as only one grapheme

* SetConsoleActiveScreenBuffer is already called by the constructor and is only needed once

* Finally fixed non virtual terminal in windows driver

* Add more Sixel unit tests

* Add unit tests for OutputBase class

* Avoid emit escape sequence

* Fix assertion failure in UICatalog

* Let each driver to deal with the Sixel write

* When Shutdown is called by the static Application then the ApplicationImpl.ResetStateStatic should be also called

* Add more OutputBase with Sixel unit tests

* Fix some issues with IsVirtualTerminal and Force16Colors with unit tests improvement

* Add Sixel Detect method unit test

* Make Sixel IsSupported and SupportsTransparency consistent with more unit tests

* Fix namespaces and unit test

* Covering more ApplicationImpl Sixel unit test

* Remove DriverImplProxy because sometimes fails in parallel unit tests

* Fix Init_KeyBindings_Are_Not_Reset unit test failing

* Revert "Fix Init_KeyBindings_Are_Not_Reset unit test failing"

This reverts commit 0ab298bc56.

* Fix Force16Colors but still use Application.Force16Colors because of CM

* Enforce conditional

* Revert change

* Moving to a new file

* Add the same workaround as the All_Scenarios_Benchmark unit test

* Fixes #4440. TextView with ReadOnly as true, MoveRight doesn't select text up to the end of the line

* Fixes #4442. TextField PositionCursor doesn't treat zero width as one column

* Each character must return at least one column, with the exception of Tab.

* Add unit test for the ScrollOffset

* Each character must return at least one column, with the exception of Tab.

* Add unit test for the LeftColumn

* WIP

* Refactor DriverImpl and OutputBase for maintainability

Refactored `DriverImpl` to remove `IDisposable` and streamline event
handling, including replacing `OnSizeMonitorOnSizeChanged` with an
inline lambda. Reintroduced `SizeChanged` and updated `SetScreenSize`
to invoke it. Moved `SupportsTrueColor` from `OutputBase` to
`DriverImpl` and reintroduced `Force16Colors` with updated logic.

Reintroduced and updated several `OutputBuffer`-related properties
and methods in `DriverImpl`, including `Screen`, `Clip`, `Cols`, and
`Contents`. Moved `Clipboard` from `OutputBase` to `DriverImpl` and
initialized it with `FakeClipboard`. Simplified `Refresh` and `ToAnsi`
methods in `DriverImpl`.

Removed `Force16Colors` from `OutputBase` and simplified method
signatures, including `ToAnsi` and `BuildAnsiForRegion`. Fixed a
parameter name typo in `AppendOrWriteAttribute`. Made minor code
formatting adjustments.

These changes improve code maintainability, reduce redundancy, and
align the implementation with updated design requirements.

* Refactor Force16Colors handling and improve UICatalog

Refactored the `Force16Colors` property:
- Moved it from `DriverImpl` to `IOutput` and `OutputBase`.
- Simplified its management by removing redundant logic.
- Added `OnDriverOnForce16ColorsChanged` to handle updates.

Updated `UICatalogRunnable`:
- Replaced `Driver.Force16Colors` with `Application.Driver.Force16Colors`.
- Added an `F7` shortcut to toggle `Force16Colors`.
- Removed redundant event handlers and improved formatting.

Updated `config.json`:
- Replaced `Application.Force16Colors` with `Driver.Force16Colors`.
- Improved theme configuration formatting for readability.

Other changes:
- Removed the `force16Colors` parameter from `IOutput.ToAnsi`.
- Improved diagnostics handling in `UICatalogRunnable`.
- General code cleanup for readability and maintainability.

* Refactor `Force16Colors` access and improve null safety

Refactored `Force16Colors` property access to use `Application.Driver!`
for null safety and consistency. Updated event handlers to align with
this pattern. Replaced nullable `DrawContext?` parameters with
non-nullable `DrawContext` in `OnDrawingContent` overrides across
multiple classes to enforce stricter nullability checks.

Removed unused `_cachedCursorVisibility` field in `OutputBase.cs` and
cleaned up commented-out legacy code in `UICatalogRunnable.cs`. Updated
XML documentation to reflect method signature changes and property
references. Refactored `Shortcut` example in documentation for
consistency.

Replaced `Application.LayoutAndDraw` with `SetNeedsDraw` for marking
views as needing redraw. Performed general code cleanup to remove
redundant code and improve consistency.

* Refactor ForceDriver and Force16Colors properties

Removed `[Obsolete]` from `Application.ForceDriver`, making it a stable API. Added comments to clarify its role as a configuration property and its synchronization with `IApplication.ForceDriver`. Introduced `_forceDriver` as a private backing field.

Removed `Force16Colors` from `ApplicationImpl` and eliminated reset logic for `ForceDriver` and `Force16Colors` during shutdown, shifting state management responsibility to the library user.

Updated comments in `Driver.cs` to document `Force16Colors` as a configuration property and its synchronization with `IDriver.Force16Colors`. Retained `_force16Colors` as a private backing field for configuration overrides.

* Updated docs

* There is no way to detect Sixel transparency and so relying in VTS or Xterm with transparency

* Fix detect Sixel unit tests with the adjusting code

* Refactored Output.

* MErging

* - Added `OnDriverOnForce16ColorsChanged` method to handle `Driver.Force16ColorsChanged` events and update the `Force16Colors` property.

- Implemented `IDisposable` to ensure proper cleanup of resources, including unsubscribing from `SizeMonitor.SizeChanged` and `Driver.Force16ColorsChanged` events, and disposing of `_output`.
- Replaced inline `SizeMonitor.SizeChanged` event handler with a dedicated method, `OnSizeMonitorOnSizeChanged`, for better readability and maintainability.

- Simplified the `Screen` property by removing commented-out code and directly returning a `Rectangle` based on `OutputBuffer` dimensions.
- Updated the `Force16Colors` property to use `_output` for both getting and setting its value.
- Performed general cleanup, including removing unused code and improving code structure.

* merged

* Refactor Sixel handling with ConcurrentQueue

Replaced `List<SixelToRender>` with `ConcurrentQueue<SixelToRender>`
to improve thread safety and performance in sixel management.
Updated the `Images` class to avoid unnecessary removal and
re-creation of sixel objects by updating existing ones in place.

Refactored `Application.Sixel` to return a `ConcurrentQueue` and
introduced `GetSixels` in `IDriver` and `IOutput` for consistent
access. Updated `OutputBase` to use a private `ConcurrentQueue`
and adjusted rendering logic accordingly.

Removed legacy and redundant code, including `Application.Driver?.Sixel.Clear()`
and unused properties in `DriverImpl` and `ApplicationImpl`. Updated
tests in `OutputBaseTests` to align with the new implementation.

Added `using System.Collections.Concurrent` where necessary and
improved documentation to reflect the changes. These updates
enhance thread safety, simplify the codebase, and align with
modern concurrent programming practices.

* Tweak

* Refactor DriverImpl to use Dispose and improve modularity

Replaced `Driver.End()` with `Driver.Dispose()` across the codebase, aligning with the `IDisposable` pattern for proper resource cleanup. Updated `DriverImpl` to implement `Dispose`, ensuring event unsubscriptions and resource disposal.

Enhanced `DriverImpl` structure by organizing code into logical regions, improving modularity and readability. Refactored and reintroduced methods and properties like `Clipboard`, `Screen`, `SetScreenSize`, `Cols`, `Rows`, and others for better encapsulation.

Updated the `IDriver` interface to include `IDisposable` and reorganized it into regions. Added new methods and properties such as `Init`, `Refresh`, `Suspend`, `QueueAnsiRequest`, and `ToAnsi`.

Refactored unit tests to replace `driver.End()` with `driver.Dispose()` and ensured proper resource cleanup. Improved code comments and documentation for better clarity.

Aligned with modern C# practices, adopting features like null-coalescing operators and pattern matching. Removed redundant code, addressed some TODOs, and modularized the codebase for maintainability and extensibility.

* Refactor driver docs and update View.Driver usage

Updated `application.md` to clarify the purpose of the `View.Driver` property, replacing the obsolete `Application.Driver`. Added a reference to the "Drivers Deep Dive" documentation for further details.

Refactored the `OnDrawContent` method to use the `Driver` property, ensuring compatibility with the new driver architecture.

Added a new section, "Testing with the New Architecture," to `application.md`, highlighting the improved testability of the instance-based architecture.

Expanded and reorganized `drivers.md` to provide a detailed breakdown of the `IDriver` interface, including lifecycle, components, screen and display, color support, content buffer, drawing, cursor, input events, and ANSI escape sequences. Introduced new subsections for clarity and emphasized the modular design for maintainability.

Added a note in `drivers.md` discouraging direct access to the `Driver` and recommending higher-level abstractions like `Terminal.Gui.App.Application.Screen` and `Terminal.Gui.ViewBase.View` methods for positioning and drawing.

* Refactor IsVirtualTerminal to IsLegacyConsole

Replaced the `IsVirtualTerminal` property with `IsLegacyConsole` across the codebase to better represent legacy versus modern terminal environments. Updated logic in `SixelSupportDetector`, `DriverImpl`, and `OutputBase` to use the new property.

Refactored tests to align with the updated property, including renaming test methods, adjusting mock setups, and replacing `VirtualTerminalTests` with `LegacyConsoleTests`.

Simplified `WindowsOutput` implementation to handle console modes and sixel rendering based on `IsLegacyConsole`. Removed redundant code related to `IsVirtualTerminal`.

Improved code readability and maintainability by using more descriptive property names and ensuring consistency across the codebase. Updated `.DotSettings` with new entries.

* Update Examples/UICatalog/Scenarios/LineDrawing.cs

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

* Update Examples/UICatalog/Scenarios/Images.cs

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

* Update Examples/UICatalog/Scenarios/Images.cs

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

* Update Terminal.Gui/App/IApplication.cs

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

* Update Terminal.Gui/App/ApplicationImpl.Lifecycle.cs

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

* Update Examples/UICatalog/Scenarios/ColorPicker.cs

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

* Update Examples/UICatalog/Scenarios/ColorPicker.cs

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

* Fix formatting and typo in code and documentation

Improved code readability in `LineDrawing.cs` by fixing spacing
around the ternary operator in `Width` and `Y` property assignments.
Corrected a typo in `drivers.md` by changing "Configuraiton Manager"
to "Configuration Manager" for accurate documentation.

* Test failure casued by assert left in by accident.

* Added a workaround in `OutputBase.cs` to address dirty cell handling in legacy console mode by marking all buffer cells as dirty.

Refactored `_disableMouseCb` event handling in `UICatalogRunnable.cs` to use the `Selecting` event for toggling `Application.IsMouseDisabled`. Simplified `MouseImpl.cs` by converting `App` to an auto-implemented property and removing redundant namespace usage.

Streamlined logging in `WindowsOutput.cs` by replacing verbose `Logging.Logger` calls with shorter alternatives (`Logging.Information`, `Logging.Error`, etc.).

* Update theme and remove unused ListView component

The application's default theme configuration was updated from "Light" to "Amber Phosphor" by modifying the `ConfigurationManager.RuntimeConfig` value.

Additionally, the `ListView` component in the `ExampleWindow` class was removed. This included its initialization, layout properties (`Y`, `Height`, `Width`), and its data source (["One", "Two", "Three", "Four"]).

* Increase safety timeout in NestedRunTimeoutTests to 10s

The timeout duration for the safety mechanism in the
`NestedRunTimeoutTests` class was increased from 5000ms (5s)
to 10000ms (10s). This change allows the app more time to
complete before triggering the safety timeout, reducing the
likelihood of premature termination during long-running tests.

Refactor and enhance test coverage

Refactored `Load_WithInvalidJson_AddsJsonError` test in `SourcesManagerTests.cs` to improve organization and added a note about its impact on parallel execution. Increased the safety timeout in `NestedRunTimeoutTests.cs` from 5 seconds to 10 seconds to address potential premature test timeouts.

* Handle null Driver gracefully in event subscription

Replaced `ArgumentNullException.ThrowIfNull(Driver)` with a null-check conditional in `SubscribeDriverEvents` and `UnsubscribeDriverEvents`. If `Driver` is `null`, the methods now log an error using `Logging.Error` and return early. This prevents potential exceptions and improves error handling.

---------

Co-authored-by: BDisp <bd.bdisp@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-12-05 17:40:48 -07:00
Tig
f0343e4c3c Merge pull request #4439 from tig/v2_4431-MainLoop 2025-12-04 18:50:19 -07:00
BDisp
241aec0e3d Fixes #4442. TextField PositionCursor doesn't treat zero width as one column (#4443)
* Fixes #4442. TextField PositionCursor doesn't treat zero width as one column

* Each character must return at least one column, with the exception of Tab.

* Add unit test for the ScrollOffset
2025-12-04 17:12:52 -07:00
BDisp
06767193fb Fixes #4440. TextView with ReadOnly as true, MoveRight doesn't select text up to the end of the line (#4441)
* Fixes #4440. TextView with ReadOnly as true, MoveRight doesn't select text up to the end of the line

* Each character must return at least one column, with the exception of Tab.

* Add unit test for the LeftColumn
2025-12-04 17:11:59 -07:00
Tig
32fbcdd7ad Merge branch 'v2_develop' into v2_4431-MainLoop 2025-12-04 17:10:46 -07:00
Tig
25223ce7ec Update Examples/UICatalog/UICatalogRunnable.cs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-12-04 17:08:44 -07:00
Tig
b4719e1809 Update Terminal.Gui/ViewBase/View.Drawing.cs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-12-04 17:08:18 -07:00
Tig
491229b446 Update Examples/UICatalog/Scenarios/Transparent.cs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-12-04 17:07:46 -07:00
Tig
c8fafbcb1a Update Terminal.Gui/ViewBase/View.NeedsDraw.cs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-12-04 17:06:31 -07:00
Tig
063a6d7e98 Fixes #945 - Adds simple PowerShell example (#4438)
* 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

* Add Terminal.Gui integration in PowerShell script

Integrated Terminal.Gui into a PowerShell script by:
- Adding necessary `using namespace` statements.
- Loading DLLs dynamically from a specified `$dllFolder`.
- Creating a Terminal.Gui application with a window and label.
- Providing instructions for building and preparing dependencies.
- Ensuring proper disposal of application resources.
2025-12-04 17:02:58 -07:00