Skip to content

Implement the Kitty Keyboard Protocol (#19817)#7

Merged
Dargon789 merged 1 commit intoDargon789:ci-main-clean-shellfrom
microsoft:main
Feb 17, 2026
Merged

Implement the Kitty Keyboard Protocol (#19817)#7
Dargon789 merged 1 commit intoDargon789:ci-main-clean-shellfrom
microsoft:main

Conversation

@Dargon789
Copy link
Owner

@Dargon789 Dargon789 commented Feb 17, 2026

This essentially rewrites TerminalInput from scratch. There's significant overlap between what kind of information the Kitty protocol needs from the OS and our existing code. The rewrite allows us to share large parts of the implementation.

Closes microsoft#11509

Validation Steps Performed

  • kitten show-key -m kitty
  • US Intern. " + ' produces \'
  • Hebrew base keys produce Unicode ✅
  • Hebrew AltGr combinations produce Unicode ✅
  • French AltGr+Space produces U+00A0 ✅
  • German AltGr+Decimals produce []{}... ✅

Summary of the Pull Request

References and Relevant Issues

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

PR Checklist

  • Closes #xxx
  • Tests added/passed
  • Documentation updated
    • If checked, please file a pull request on our docs repo and link it here: #xxx
  • Schema updated (if necessary)

Summary by Sourcery

Add support for the Kitty Keyboard Protocol with configurable flags, refactor terminal keyboard input encoding, and wire protocol control through escape sequences and profile settings.

New Features:

  • Introduce Kitty Keyboard Protocol handling in terminal input, including flag management, stack operations, and CSI u key encoding.
  • Expose Kitty Keyboard Protocol control via new CSI sequences and dispatch methods to set, query, push, and pop protocol flags.
  • Add a profile/terminal setting to enable or disable Kitty Keyboard Protocol usage and honor it in Terminal core and conpty.

Enhancements:

  • Refactor keyboard input processing to use structured helpers instead of a static key map, improving surrogate handling, modifier interpretation, and VT/ANSI sequence generation.
  • Unify focus and alternate scroll key sequence generation to use the new encoding path and internal state, and simplify mouse input state management by tracking the active buffer directly.
  • Share a generic TAEF array-index data source adapter across tests to reduce duplication and simplify parameterized test wiring.

Tests:

  • Add comprehensive unit tests covering Kitty Keyboard Protocol encoding behavior, including modifiers, event types, alternate keys, associated text, and repeat/release handling.

This essentially rewrites `TerminalInput` from scratch.
There's significant overlap between what kind of information
the Kitty protocol needs from the OS and our existing code.
The rewrite allows us to share large parts of the implementation.

Closes #11509

## Validation Steps Performed
* `kitten show-key -m kitty` ✅
* US Intern. " + ' produces `\'` ✅
* Hebrew base keys produce Unicode ✅
* Hebrew AltGr combinations produce Unicode ✅
* French AltGr+Space produces U+00A0 ✅
* German AltGr+Decimals produce []{}... ✅
@snyk-io
Copy link

snyk-io bot commented Feb 17, 2026

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@sourcery-ai
Copy link

sourcery-ai bot commented Feb 17, 2026

Reviewer's Guide

Rewrites TerminalInput’s key handling to implement the Kitty Keyboard Protocol (KKP) on top of a new, shared encoding pipeline, wires new CSI u KKP control sequences through the VT parser/dispatch, adds settings and toggles in Terminal/ConPTY, and centralizes TAEF data-source helpers, with comprehensive unit tests verifying KKP behavior.

Updated class diagram for TerminalInput and Kitty keyboard protocol

classDiagram
    class TerminalInput {
        +TerminalInput()
        +UseAlternateScreenBuffer() void
        +UseMainScreenBuffer() void
        +SetInputMode(Mode mode, bool enabled) void
        +GetInputMode(Mode mode) bool
        +ResetInputModes() void
        +ForceDisableWin32InputMode(bool win32InputMode) void
        +ForceDisableKittyKeyboardProtocol(bool disable) void
        +SetKittyKeyboardProtocol(uint8_t flags, KittyKeyboardProtocolMode mode) void
        +GetKittyFlags() uint8_t
        +PushKittyFlags(uint8_t flags) void
        +PopKittyFlags(size_t count) void
        +ResetKittyKeyboardProtocols() void
        +HandleKey(INPUT_RECORD event) OutputType
        +HandleFocus(bool focused) OutputType
        +_makeWin32Output(KEY_EVENT_RECORD key) OutputType
        -_encodeKitty(KeyboardHelper kbd, EncodingHelper enc, SanitizedKeyEvent key) bool
        -_encodeRegular(EncodingHelper enc, SanitizedKeyEvent key) void
        -_formatEncodingHelper(EncodingHelper enc, wstring seq) bool
        -_formatFallback(KeyboardHelper kbd, EncodingHelper enc, SanitizedKeyEvent key, wstring seq) void
        -_stringPushCodepoint(wstring str, uint32_t cp) void
        -_codepointToLower(uint32_t cp) uint32_t
        -_trackControlKeyState(KEY_EVENT_RECORD key) DWORD
        -_initKeyboardMap() void
        -_leadingSurrogate wchar_t
        -_lastVirtualKeyCode optional~WORD~
        -_lastControlKeyState DWORD
        -_lastLeftCtrlTime uint64_t
        -_lastRightAltTime uint64_t
        -_inputMode enumset~Mode~
        -_forceDisableWin32InputMode bool
        -_inAlternateBuffer bool
        -KittyStackMaxSize size_t
        -_forceDisableKittyKeyboardProtocol bool
        -_kittyFlags uint8_t
        -_kittyMainStack vector~uint8_t~
        -_kittyAltStack vector~uint8_t~
        -_csi wstring_view
        -_ss3 wstring_view
        -_focusInSequence wstring_view
        -_focusOutSequence wstring_view
    }

    class KittyKeyboardProtocolFlags {
        <<struct>>
        +None uint8_t
        +DisambiguateEscapeCodes uint8_t
        +ReportEventTypes uint8_t
        +ReportAlternateKeys uint8_t
        +ReportAllKeysAsEscapeCodes uint8_t
        +ReportAssociatedText uint8_t
        +All uint8_t
    }

    class KittyKeyboardProtocolMode {
        <<enum>>
        Replace
        Set
        Reset
    }

    class SanitizedKeyEvent {
        <<struct>>
        +virtualKey uint16_t
        +scanCode uint16_t
        +codepoint uint32_t
        +controlKeyState uint32_t
        +leftCtrlIsReallyPressed bool
        +keyDown bool
        +keyRepeat bool
        +anyAltPressed() bool
        +bothAltPressed() bool
        +rightAltPressed() bool
        +bothCtrlPressed() bool
        +altGrPressed() bool
    }

    class KeyboardHelper {
        <<struct>>
        +KeyboardHelper()
        +getUnmodifiedKeyboardKey(SanitizedKeyEvent key) uint32_t
        +getKittyBaseKey(SanitizedKeyEvent key) uint32_t
        +getKittyShiftedKey(SanitizedKeyEvent key) uint32_t
        +getKittyUSBaseKey(SanitizedKeyEvent key) uint32_t
        -getKeyboardKey(UINT vkey, DWORD controlKeyState, HKL hkl) uint32_t
        -init() void
        -initSlow() void
        -_initialized bool
        -_keyboardLayout HKL
        -_keyboardState uint8_t[256]
    }

    class EncodingHelper {
        <<struct>>
        +EncodingHelper()
        +shiftPressed() bool
        +altPressed() bool
        +ctrlPressed() bool
        +csiUnicodeKeyCode uint32_t
        +csiAltKeyCodeShifted uint32_t
        +csiAltKeyCodeBase uint32_t
        +csiModifier uint32_t
        +csiEventType uint32_t
        +csiTextAsCodepoint uint32_t
        +csiFinal wchar_t
        +ss3Final wchar_t
        +altPrefix bool
        +plain wstring_view
    }

    class CodepointBuffer {
        <<struct>>
        +CodepointBuffer()
        +CodepointBuffer(uint32_t cp)
        +convertLowercase() void
        +asSingleCodepoint() uint32_t
        +buf wchar_t[4]
        +len int
    }

    class ITermDispatch {
        <<interface>>
        +SetKittyKeyboardProtocol(VTParameter flags, VTParameter mode) void
        +QueryKittyKeyboardProtocol() void
        +PushKittyKeyboardProtocol(VTParameter flags) void
        +PopKittyKeyboardProtocol(VTParameter count) void
    }

    class AdaptDispatch {
        +SetKittyKeyboardProtocol(VTParameter flags, VTParameter mode) void
        +QueryKittyKeyboardProtocol() void
        +PushKittyKeyboardProtocol(VTParameter flags) void
        +PopKittyKeyboardProtocol(VTParameter count) void
        -_terminalInput TerminalInput
    }

    TerminalInput *-- KittyKeyboardProtocolFlags
    TerminalInput *-- KittyKeyboardProtocolMode
    TerminalInput *-- SanitizedKeyEvent
    TerminalInput *-- KeyboardHelper
    TerminalInput *-- EncodingHelper
    TerminalInput *-- CodepointBuffer

    AdaptDispatch ..|> ITermDispatch
    AdaptDispatch o--> TerminalInput
Loading

File-Level Changes

Change Details Files
Rewrite TerminalInput key handling around a new Kitty-aware encoding pipeline that prefers KKP over Win32/legacy VT and unifies surrogate, modifier, and keypad handling.
  • Introduce SanitizedKeyEvent, KeyboardHelper, EncodingHelper, and several helper methods to normalize KEY_EVENT_RECORDs, query layout text via ToUnicodeEx, and build CSI/SS3/plain sequences.
  • Add Kitty keyboard protocol flags and stack state to TerminalInput, including enabling/disabling KKP, pushing/popping flag stacks per main/alternate buffer, and integrating buffer switches into that state.
  • Replace the keymap-based _initKeyboardMap and legacy key->sequence lookup with logic that encodes Kitty CSI u sequences when enabled and otherwise falls back to a regular VT/VT52 encoder plus a keyboard-layout-based fallback mapper.
  • Update HandleKey to prioritize KKP (when flags are non-zero), support event-type reporting, repeat detection, Alt-Numpad composition, surrogate pairing, and to emit correct sequences for Enter/Tab/Backspace, modifiers, and keypad keys.
  • Refactor _makeCtrlChar, character output, and Ctrl/Alt handling to operate on Unicode codepoints and centralized helpers instead of scattered logic.
src/terminal/input/terminalInput.cpp
src/terminal/input/terminalInput.hpp
src/terminal/input/sources.inc
src/terminal/input/lib/terminalinput.vcxproj
src/terminal/input/mouseInput.cpp
Add full VT parser/dispatch support for Kitty Keyboard Protocol CSI u control sequences and integrate them with AdaptDispatch and TermDispatch.
  • Extend CsiActionCodes with new KKP_* entries for setting, querying, pushing, and popping Kitty keyboard flags.
  • Wire OutputStateMachineEngine::ActionCsiDispatch to call new ITermDispatch KKP methods.
  • Extend ITermDispatch, AdaptDispatch, and TermDispatch with SetKittyKeyboardProtocol, QueryKittyKeyboardProtocol, PushKittyKeyboardProtocol, and PopKittyKeyboardProtocol implementations, including DECANM refactor placement.
  • Ensure AdaptDispatch manipulates TerminalInput’s KKP state via the new APIs and returns appropriate CSI responses from QueryKittyKeyboardProtocol.
src/terminal/parser/OutputStateMachineEngine.hpp
src/terminal/parser/OutputStateMachineEngine.cpp
src/terminal/adapter/ITermDispatch.hpp
src/terminal/adapter/adaptDispatch.hpp
src/terminal/adapter/adaptDispatch.cpp
src/terminal/adapter/termDispatch.hpp
Expose configuration and host toggles for Kitty Keyboard Protocol in Terminal and ConPTY, and temporarily disable KKP behind ConPTY to avoid double-translation.
  • Add AllowKittyKeyboardMode profile/ICoreSettings property, wire it through Terminal settings model, view model, and XAML editor, with default enabled and compatibility namespace wiring.
  • Update Terminal::UpdateSettings to disable Kitty Keyboard Protocol in TerminalInput when the profile disallows it.
  • Modify VtIo initialization to forcibly disable Kitty Keyboard Protocol on the server side input buffer to prevent ConPTY from translating Win32 input to KKP while Terminal is still stabilizing the feature (GH#19847).
src/cascadia/TerminalCore/Terminal.cpp
src/cascadia/TerminalCore/ICoreSettings.idl
src/cascadia/TerminalSettingsModel/MTSMSettings.h
src/cascadia/TerminalSettingsModel/Profile.idl
src/cascadia/TerminalSettingsAppAdapterLib/TerminalSettings.cpp
src/cascadia/TerminalSettingsEditor/ProfileViewModel.h
src/cascadia/TerminalSettingsEditor/ProfileViewModel.idl
src/cascadia/TerminalSettingsEditor/Profiles_Terminal.xaml
src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw
src/cascadia/inc/ControlProperties.h
src/host/VtIo.cpp
Refactor TAEF data source boilerplate into a shared helper and reuse it in existing test suites.
  • Introduce shared ArrayIndexTaefAdapterRow and ArrayIndexTaefAdapterSource implementations in consoletaeftemplates.hpp to adapt index-based test arrays into IDataSource/IDataRow.
  • Replace duplicated anonymous namespace adapter implementations in UiaTextRangeTests and ReflowTests with uses of the shared helpers.
  • Include IDataSource.h in consoletaeftemplates.hpp and adjust test data source exports to construct ArrayIndexTaefAdapterSource with the correct size.
src/inc/consoletaeftemplates.hpp
src/interactivity/win32/ut_interactivity_win32/UiaTextRangeTests.cpp
src/buffer/out/ut_textbuffer/ReflowTests.cpp
Add a comprehensive KKP unit test suite to validate Kitty Keyboard Protocol encoding of keys, modifiers, event types, keypad behavior, and alternate/associated text.
  • Create kittyKeyboardProtocol.cpp test file that constructs TerminalInput with various KKP flag combinations and feeds synthetic KEY_EVENT_RECORDs through HandleKey.
  • Define a large parameterized test table of expected CSI u sequences for common and edge-case key combinations (text keys, modifiers, Enter/Tab/Backspace, keypad, navigation, media, and lock keys).
  • Add additional tests that specifically exercise key repeat semantics, repeat reset behavior, and repeat under modifiers.
  • Wire the new test file into the adapter unit test project and filters, and add a TAEF data source export (KittyKeyTestDataSource) using the shared ArrayIndexTaefAdapterSource helper.
src/terminal/adapter/ut_adapter/kittyKeyboardProtocol.cpp
src/terminal/adapter/ut_adapter/Adapter.UnitTests.vcxproj
src/terminal/adapter/ut_adapter/Adapter.UnitTests.vcxproj.filters
src/terminal/adapter/ut_adapter/sources

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@gemini-code-assist
Copy link

Summary of Changes

Hello @Dargon789, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces the implementation of the Kitty Keyboard Protocol, significantly enhancing the terminal's ability to report detailed keyboard input. The core TerminalInput class has been refactored to support this new protocol, moving from a static keymap to a more flexible and robust encoding system. This change also includes new user-facing settings to control the protocol's behavior and consolidates mouse input state management directly within the TerminalInput class for improved code organization.

Highlights

  • Kitty Keyboard Protocol Implementation: The Kitty Keyboard Protocol has been fully implemented, allowing for advanced keyboard input reporting in the terminal. This includes support for disambiguating escape codes, reporting event types (press, repeat, release), alternate key values, and associated text.
  • TerminalInput Class Refactoring: The TerminalInput class has undergone a significant rewrite to integrate the new Kitty Keyboard Protocol logic. This refactoring streamlines key handling, moving away from a static keymap to a more dynamic encoding helper system.
  • New Configuration Options: A new setting, AllowKittyKeyboardMode, has been introduced across various settings models and UI components, providing users with the ability to enable or disable the Kitty Keyboard Protocol.
  • Consolidated Mouse Input State: The mouseInputState.cpp file has been removed, and its functionality for tracking mouse input state has been integrated directly into the TerminalInput class, simplifying the codebase.
  • Enhanced Unit Testing: New unit tests specifically for the Kitty Keyboard Protocol have been added, ensuring the correct behavior and output of the new input handling logic under various conditions and flag combinations.
Changelog
  • .github/actions/spelling/expect/expect.txt
    • Removed coordnew and fwlink from the spelling exception list.
    • Added KKP and LCMAP to the spelling exception list.
  • src/buffer/out/ut_textbuffer/ReflowTests.cpp
    • Removed TAEF adapter classes (ArrayIndexTaefAdapterRow, ArrayIndexTaefAdapterSource) that were moved to a common header.
  • src/cascadia/TerminalCore/ICoreSettings.idl
    • Added AllowKittyKeyboardMode boolean property to the ICoreSettings interface.
  • src/cascadia/TerminalCore/Terminal.cpp
    • Added a call to ForceDisableKittyKeyboardProtocol based on the new AllowKittyKeyboardMode setting.
  • src/cascadia/TerminalSettingsAppAdapterLib/TerminalSettings.cpp
    • Added _AllowKittyKeyboardMode to the TerminalSettings class, reflecting the new profile setting.
  • src/cascadia/TerminalSettingsEditor/ProfileViewModel.h
    • Added AllowKittyKeyboardMode as an observable projected setting for the profile view model.
  • src/cascadia/TerminalSettingsEditor/ProfileViewModel.idl
    • Added AllowKittyKeyboardMode as an inheritable profile setting in the IDL definition.
  • src/cascadia/TerminalSettingsEditor/Profiles_Terminal.xaml
    • Added a ToggleSwitch UI element for the AllowKittyKeyboardMode setting in the terminal profiles editor.
  • src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw
    • Added string resources for the Profile_AllowKittyKeyboardMode header and comment.
    • Updated path translation style values to use HTML entity for greater than sign.
  • src/cascadia/TerminalSettingsModel/MTSMSettings.h
    • Defined AllowKittyKeyboardMode as a boolean setting with a default value of true.
  • src/cascadia/TerminalSettingsModel/Profile.idl
    • Added AllowKittyKeyboardMode as an inheritable profile setting in the IDL definition.
  • src/cascadia/inc/ControlProperties.h
    • Added AllowKittyKeyboardMode as a control property with a default value of true.
  • src/host/VtIo.cpp
    • Added temporary logic to force disable the Kitty Keyboard Protocol in ConPTY to prevent conflicts during initial rollout.
  • src/inc/consoletaeftemplates.hpp
    • Included IDataSource.h for TAEF test data sources.
    • Moved and refactored ArrayIndexTaefAdapterRow and ArrayIndexTaefAdapterSource structs to this common header.
  • src/interactivity/win32/ut_interactivity_win32/UiaTextRangeTests.cpp
    • Removed TAEF adapter classes (ArrayIndexTaefAdapterRow, ArrayIndexTaefAdapterSource) that were moved to a common header.
  • src/terminal/adapter/ITermDispatch.hpp
    • Added virtual methods for SetKittyKeyboardProtocol, QueryKittyKeyboardProtocol, PushKittyKeyboardProtocol, and PopKittyKeyboardProtocol.
  • src/terminal/adapter/adaptDispatch.cpp
    • Implemented SetKittyKeyboardProtocol, QueryKittyKeyboardProtocol, PushKittyKeyboardProtocol, and PopKittyKeyboardProtocol methods.
    • Refactored the SetAnsiMode implementation, moving its definition.
  • src/terminal/adapter/adaptDispatch.hpp
    • Added declarations for SetKittyKeyboardProtocol, QueryKittyKeyboardProtocol, PushKittyKeyboardProtocol, and PopKittyKeyboardProtocol.
  • src/terminal/adapter/termDispatch.hpp
    • Added empty override implementations for the new Kitty Keyboard Protocol dispatch methods.
  • src/terminal/adapter/ut_adapter/Adapter.UnitTests.vcxproj
    • Added kittyKeyboardProtocol.cpp to the project's compilation items.
  • src/terminal/adapter/ut_adapter/Adapter.UnitTests.vcxproj.filters
    • Added kittyKeyboardProtocol.cpp to the 'Source Files' filter.
    • Added Natvis debugger visualization files to the project filters.
  • src/terminal/adapter/ut_adapter/kittyKeyboardProtocol.cpp
    • Added a new unit test file containing comprehensive tests for the Kitty Keyboard Protocol implementation.
  • src/terminal/adapter/ut_adapter/sources
    • Added kittyKeyboardProtocol.cpp to the list of source files.
  • src/terminal/input/lib/terminalinput.vcxproj
    • Removed mouseInputState.cpp from the project's compilation items.
  • src/terminal/input/mouseInput.cpp
    • Updated ShouldSendAlternateScroll to directly use the _inAlternateBuffer member.
    • Refactored _makeAlternateScrollOutput to use the new SanitizedKeyEvent and encoding helpers.
  • src/terminal/input/mouseInputState.cpp
    • Removed the mouseInputState.cpp file, as its functionality was integrated into terminalInput.cpp.
  • src/terminal/input/sources.inc
    • Removed mouseInputState.cpp from the list of source files.
  • src/terminal/input/terminalInput.cpp
    • Rewrote the key handling logic to support the Kitty Keyboard Protocol, introducing SanitizedKeyEvent, KeyboardHelper, and EncodingHelper structs.
    • Removed the old _keyMap and associated key definition functions.
    • Implemented Kitty Keyboard Protocol state management, including flag setting, querying, pushing, and popping.
    • Refactored _initKeyboardMap to initialize CSI/SS3 sequences and focus sequences dynamically.
    • Updated _makeCtrlChar to handle uint32_t codepoints.
    • Removed _getKeyboardState and _escapeOutput functions.
    • Introduced _encodeKitty, _getKittyFunctionalKeyCode, _encodeRegular, _formatEncodingHelper, _formatFallback, _stringPushCodepoint, and _codepointToLower helper methods for new key encoding.
  • src/terminal/input/terminalInput.hpp
    • Added KittyKeyboardProtocolFlags and KittyKeyboardProtocolMode enums.
    • Added methods for managing Kitty Keyboard Protocol state (SetKittyKeyboardProtocol, GetKittyFlags, PushKittyFlags, PopKittyFlags, ResetKittyKeyboardProtocols).
    • Introduced new internal helper structs: CodepointBuffer, SanitizedKeyEvent, KeyboardHelper, and EncodingHelper.
    • Removed the _keyMap member and related helper functions.
    • Updated _csi, _ss3, _focusInSequence, _focusOutSequence to be std::wstring_view.
    • Added _inAlternateBuffer member to track alternate buffer state.
    • Updated _makeCtrlChar and _makeCharOutput to use uint32_t.
  • src/terminal/parser/OutputStateMachineEngine.cpp
    • Added cases to ActionCsiDispatch to handle new Kitty Keyboard Protocol CSI actions (KKP_KittyKeyboardSet, KKP_KittyKeyboardQuery, KKP_KittyKeyboardPush, KKP_KittyKeyboardPop).
  • src/terminal/parser/OutputStateMachineEngine.hpp
    • Added new CsiActionCodes for the Kitty Keyboard Protocol (KKP_KittyKeyboardSet, KKP_KittyKeyboardQuery, KKP_KittyKeyboardPush, KKP_KittyKeyboardPop).
Activity
  • The pull request was created to implement the Kitty Keyboard Protocol.
  • The TerminalInput class was rewritten to support the new protocol.
  • New settings and UI elements were added to control the Kitty Keyboard Protocol.
  • Unit tests were added to validate the new keyboard input handling.
  • The mouseInputState.cpp file was removed, and its logic was integrated into terminalInput.cpp.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link

@check-spelling-bot Report

🔴 Please review

See the 📂 files view, the 📜action log, or 📝 job summary for details.

Unrecognized words (2)

cimg
circleci

To accept these unrecognized words as correct, you could run the following commands

... in a clone of the git@github.com:microsoft/terminal.git repository
on the main branch (ℹ️ how do I use this?):

curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/v0.0.25/apply.pl' |
perl - 'https://github.com/Dargon789/terminal/actions/runs/22083313803/attempts/1' &&
git commit -m 'Update check-spelling metadata'
Pattern suggestions ✂️ (1)

You could add these patterns to .github/actions/spelling/patterns/83b9569ce0393f2de99ffa5ea17fdc869e699090.txt:

# Automatically suggested patterns

# hit-count: 1 file-count: 1
# container images
image: [-\w./:@]+

Alternatively, if a pattern suggestion doesn't make sense for this project, add a #
to the beginning of the line in the candidates file with the pattern to stop suggesting it.

Errors, Warnings, and Notices ❌ (3)

See the 📂 files view, the 📜action log, or 📝 job summary for details.

❌ Errors, Warnings, and Notices Count
ℹ️ candidate-pattern 1
❌ check-file-path 1
⚠️ ignored-expect-variant 1

See ❌ Event descriptions for more information.

✏️ Contributor please read this

By default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.

If the listed items are:

  • ... misspelled, then please correct them instead of using the command.
  • ... names, please add them to .github/actions/spelling/allow/names.txt.
  • ... APIs, you can add them to a file in .github/actions/spelling/allow/.
  • ... just things you're using, please add them to an appropriate file in .github/actions/spelling/expect/.
  • ... tokens you only need in one place and shouldn't generally be used, you can add an item in an appropriate file in .github/actions/spelling/patterns/.

See the README.md in each directory for more information.

🔬 You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. 😉

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • The new Kitty keyboard protocol and encoding logic makes terminalInput.cpp quite large and dense; consider moving Kitty-specific helpers (_encodeKitty, _getKittyFunctionalKeyCode, KeyboardHelper, EncodingHelper, etc.) into a separate translation unit or namespace to keep TerminalInput more focused and maintainable.
  • In EncodingHelper::EncodingHelper() you use memset(this, 0, sizeof(*this)); this is fragile since the struct contains non-trivial types (std::wstring_view) and may gain more over time—prefer using in-class member initializers or an explicit member-wise constructor instead of zeroing the whole object memory.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new Kitty keyboard protocol and encoding logic makes `terminalInput.cpp` quite large and dense; consider moving Kitty-specific helpers (`_encodeKitty`, `_getKittyFunctionalKeyCode`, `KeyboardHelper`, `EncodingHelper`, etc.) into a separate translation unit or namespace to keep `TerminalInput` more focused and maintainable.
- In `EncodingHelper::EncodingHelper()` you use `memset(this, 0, sizeof(*this))`; this is fragile since the struct contains non-trivial types (`std::wstring_view`) and may gain more over time—prefer using in-class member initializers or an explicit member-wise constructor instead of zeroing the whole object memory.

## Individual Comments

### Comment 1
<location> `src/terminal/input/terminalInput.cpp:680-689` </location>
<code_context>
+    static constexpr auto lut = [] {
</code_context>

<issue_to_address>
**issue (bug_risk):** Functional-key LUT truncates high values to uint8_t, producing incorrect Kitty PUA key codes.

`lut` is `std::array<uint8_t, 256>`, but many `SET(...)` values exceed 255 (e.g. 57358/0xE03E, 57376/0xE040). They’re truncated to a single byte, so `_getKittyFunctionalKeyCode` does:

```cpp
const auto v = til::at(lut, vkey & 0xff);
return v <= KittyKeyCodeLegacySentinel ? v : 0xE000 + v;
```

For entries where you intended to store a full PUA code (as the comments like `// CAPS_LOCK`, `// F13` suggest), this becomes `0xE000 + (code & 0xff)`, which shifts the actual code point (e.g. 0xE040 becomes `0xE000 + 0x40`). Either store full PUA values in a `uint16_t`/`uint32_t` array and return them directly, or store 0–255 offsets and keep the current `0xE000 + v` calculation. As written, many mappings are incorrect due to truncation.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for the Kitty Keyboard Protocol by rewriting TerminalInput. The new implementation is well-structured and includes a comprehensive set of unit tests, which is excellent. The refactoring of the TAEF data source adapter is a good cleanup, but it appears to have introduced a couple of memory leaks that need to be addressed. Overall, this is a high-quality contribution that adds a significant feature.

Copy link
Owner Author

@Dargon789 Dargon789 left a comment

Choose a reason for hiding this comment

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

#7

@Dargon789 Dargon789 merged commit 34ccabc into Dargon789:ci-main-clean-shell Feb 17, 2026
8 of 10 checks passed
@Dargon789 Dargon789 linked an issue Feb 17, 2026 that may be closed by this pull request
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.

Updated class diagram for TerminalInput and Kitty keyboard protocol

2 participants