Skip to content

Conversation

@tig
Copy link
Collaborator

@tig tig commented Jan 21, 2026

Fixes

This pull request refactors Terminal.Gui's command and input binding system to simplify the API by removing generic type parameters from CommandContext and introducing polymorphic access to bindings through pattern matching. The refactoring eliminates the complex CommandContext<TBindingType> generic in favor of a simpler non-generic CommandContext with an IInputBinding? Binding property that can be pattern-matched.

Changes:

  • Replaces CommandContext<TBindingType> generic with non-generic CommandContext containing IInputBinding? Binding
  • Introduces InputBinding record struct for programmatic command invocations alongside existing KeyBinding and MouseBinding
  • Renames MouseBinding.MouseEventArgs to MouseBinding.MouseEvent for consistency
  • Updates all pattern matching from CommandContext<MouseBinding> to ctx?.Binding is MouseBinding
  • Adds comprehensive test coverage for all binding types and command context
  • Updates documentation and examples to reflect the new API

See #4595

Copilot AI and others added 14 commits January 9, 2026 16:19
Co-authored-by: tig <585482+tig@users.noreply.github.com>
  - Added `Source` to `KeyBinding` and `MouseBinding`
  - Renamed `MouseBinding.MouseEventArgs` → `MouseEvent`
  - Updated 15+ files with call site changes
  - Updated documentation (mouse.md, events.md)
…, Source, MouseEvent, pattern matching

  - `KeyBindingTests.cs` - 17 tests covering constructor, properties, Source, Target, Key, pattern matching
  - `CommandContextTests.cs` - 13 tests covering ICommandContext, pattern matching, Source propagation
- [x] Create `InputBinding` record struct
- [x] Add `Binding` property to `ICommandContext`
- [x] Rename `CommandContext<T>.Binding` → `TypedBinding` (strongly-typed access)
- [x] Add computed `Binding` property to `CommandContext<T>` for interface compliance
- [x] Update all call sites from `.Binding` to `.TypedBinding`
…inding.cs`

  - Added `IInputBinding? Binding { get; }` property to `ICommandContext` interface
  - Renamed `CommandContext<T>.Binding` to `TypedBinding` for strongly-typed access
  - Added computed `Binding` property: `IInputBinding? Binding => TypedBinding`
  - Updated 20+ files to use `.TypedBinding` instead of `.Binding`
  - Created `InputBindingTests.cs` - 19 tests covering constructor, properties, IInputBinding, pattern matching
  - Updated `CommandContextTests.cs` - added 6 tests for new `Binding` property
  - All 34 binding-related tests pass
@codecov

This comment was marked as outdated.

This comment was marked as outdated.

@tig tig requested review from BDisp and tznind January 21, 2026 00:55
@tig tig changed the title Fixes #4595 - Refactors View.Command, CommandContext, and InputBinding` to simplify Fixes #4595 - Refactors View.Command, CommandContext, and InputBinding to simplify Jan 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor View.Command, CommandContext, and InputBinding to simplify

1 participant