Skip to content

Fixes #4809 - Kitty Keyboard Protocol Phase 2: Rich keyboard event model#4816

Merged
tig merged 13 commits intogui-cs:v2_developfrom
tig:feature/kitty-phase2
Mar 10, 2026
Merged

Fixes #4809 - Kitty Keyboard Protocol Phase 2: Rich keyboard event model#4816
tig merged 13 commits intogui-cs:v2_developfrom
tig:feature/kitty-phase2

Conversation

@tig
Copy link
Copy Markdown
Collaborator

@tig tig commented Mar 9, 2026

Fixes

Summary

Phase 2 of the Kitty Keyboard Protocol implementation (#4809). Builds on Phase 1 (merged in #4810) to extend Key and the keyboard event pipeline with richer semantics.

Planned work

  1. Key.EventType — Add Press/Release/Repeat event type to Key
  2. KeyUp pipeline — Add KeyUp event through driver → keyboard → application → view
  3. Driver integration — Surface key-up/repeat from Windows driver and kitty parser
  4. Standalone modifier events — Support standalone Shift/Ctrl/Alt press/release
  5. View-level KeyUpView.OnKeyUp / View.KeyUp event routing
  6. Tests — Full coverage for all new features + backward compatibility

See plans/kitty-keyboard-protocol-plan.md for detailed implementation steps.

Test plan

  • dotnet build --no-restore passes
  • dotnet test --project Tests/UnitTestsParallelizable --no-build — all pass
  • dotnet test --project Tests/UnitTests --no-build — all pass
  • Existing KeyDown-based code continues to work without modification
  • Manual testing with kitty-capable terminal

🤖 Generated with Claude Code

tig and others added 4 commits March 9, 2026 09:18
Mark Phase 2 as in-progress in the kitty keyboard protocol plan.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…d ModifierKey

- Add KeyEventType enum (Press/Repeat/Release) and ModifierKey enum for standalone modifier identity
- Extend Key with EventType, ModifierKey, and IsModifierOnly properties (additive, non-breaking)
- Add KeyUp event pipeline: IInputProcessor → IDriver → IKeyboard → Application → View
- Enable kitty flag 2 (report event types) alongside flag 1 (disambiguate escape codes)
- Extract shared ApplyModifiersAndEventType helper in AnsiKeyboardParserPattern base class
- Update CsiKeyPattern and CsiCursorPattern regexes to accept kitty modifiers:event_type format
- Map kitty modifier key codepoints (57358-57451) to ModifierKey enum in KittyKeyboardPattern
- Rename KittyKeyboardPhase1Flags → KittyKeyboardRequestedFlags
- Update Keys scenario to display event type, modifier key identity, and KeyUp events
- Update keyboard.md and drivers.md documentation
- Add 44 new tests (KeyEventTypeTests + KittyKeyboardPhase2Tests)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fix two bugs that broke InputInjectionMode.Pipeline:
1. InputProcessorImpl used DateTime.Now instead of _timeProvider.Now for
   stale escape detection, causing immediate release with VirtualTimeProvider
2. AnsiInputProcessor.InjectKeyDownEvent/InjectMouseEvent routed through
   the background input thread; now enqueues directly to InputQueue

Simplify InputInjector.ProcessQueue() by removing the VirtualTimeProvider
60ms-advance workaround (no longer needed with bug #1 fixed).

Un-skip two Pipeline tests and add 27 kitty protocol pipeline tests
covering event types, modifiers, functional keys, standalone modifier
keys, CSI ~/cursor variants, full press-repeat-release cycles, and
negative cases (invalid event types, malformed sequences, recovery).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Comment thread Tests/UnitTestsParallelizable/Input/InputInjectorTests.cs
Comment thread Tests/UnitTestsParallelizable/Input/InputInjectorTests.cs
Previously, input bytes from the Windows console were always decoded as UTF-8, but ReadFile returns bytes in the console's input code page (e.g., Windows-1252). This caused accented and non-ASCII characters to be misread. This commit introduces a ConsoleInputEncoding property in WindowsVTInputHelper to dynamically use the correct encoding, and updates AnsiInput to use it. Adds unit tests to verify correct decoding of accented characters. Also includes minor test cleanups and improved naming.
@tig tig changed the title Kitty Keyboard Protocol — Phase 2: Rich keyboard event model Fixes #4809 - Kitty Keyboard Protocol Phase 2: Rich keyboard event model Mar 9, 2026
Comment thread Tests/UnitTestsParallelizable/Input/InputInjectorTests.cs Outdated
@tig tig marked this pull request as ready for review March 10, 2026 00:14
@tig tig requested a review from BDisp March 10, 2026 00:14
Include kitty flag 8 to enable reporting of standalone modifier key events (e.g., Shift, Ctrl, Alt) as escape codes. Update tests to verify correct handling of modifier-only key press and release events, and assert that the requested kitty flags include "report all keys as escape codes." This improves compatibility with terminals supporting the kitty keyboard protocol.
Copy link
Copy Markdown
Collaborator

@BDisp BDisp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fantastic. It provides a much wider range of key manipulation, allowing for complete control. Thank you for getting involved and committing to this.
I just asked a question.

Comment thread Terminal.Gui/Drivers/AnsiHandling/EscSeqUtils/EscSeqUtils.cs Outdated
tig and others added 4 commits March 10, 2026 09:09
… coding conventions

- Replaced .github/copilot-instructions.md stub with full reference covering
  build/test commands, architecture overview, code style, terminology, and
  testing conventions
- Added early return/guard clause convention across all AI instruction files
- Added one-type-per-file convention for public and internal types
- Updated CONTRIBUTING.md (source of truth), CLAUDE.md, and AGENTS.md

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replaces raw int usage with strongly-typed KittyKeyboardFlags enum for kitty keyboard protocol flags throughout the codebase. Adds KittyKeyboardFlags.cs and moves KittyKeyboardProtocolResult to its own file, updating it to use the new enum. Updates all related logic, methods, and tests for improved type safety, clarity, and maintainability.
Adds full support for kitty keyboard protocol "alternate key reporting" (flag 4) in Terminal.Gui. The Key model now exposes ShiftedKeyCode and BaseLayoutKeyCode, populated by the kitty parser for each key event. Updates the parser, documentation, and tests to cover alternate key fields, international layouts, and end-to-end propagation. Replaces old phase 2 tests with new, comprehensive suites for parsing, pipeline, and Key object behavior. Improves operator and parsing logic in Key, and updates docs to guide usage of new features.
Two threads (test + AppTestHelper background) could race into Dispose() →
ResetState() concurrently. Thread A nulls Driver between Thread B's null-check
and Driver.Dispose(), causing NullReferenceException.

Fix: capture Driver to local, null the property, then unsubscribe and dispose
using the captured local. Concurrent callers see null and skip cleanup.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@tig tig merged commit c117fec into gui-cs:v2_develop Mar 10, 2026
11 checks passed
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.

2 participants