Skip to content

feat: add generic modifier support via CSI u escape sequences#577

Open
menny wants to merge 1 commit into
butlerx:mainfrom
menny:generic-modifier-support
Open

feat: add generic modifier support via CSI u escape sequences#577
menny wants to merge 1 commit into
butlerx:mainfrom
menny:generic-modifier-support

Conversation

@menny

@menny menny commented Feb 18, 2026

Copy link
Copy Markdown

This PR adds support for modified special keys (Shift, Ctrl, Alt, Meta) by implementing the standard CSI u (Unicode keyboard input) protocol.

Specifically, it handles:

  • Shift+Enter (e.g. for newlines without submission in modern TUIs like gemini-cli)
  • Modified Tab, Backspace, and Escape.

The implementation hooks into attachCustomKeyEventHandler to intercept raw keyboard events and map them to standard escape sequences (e.g. \x1b[13;2u for Shift+Enter).

Includes unit tests for the modifier mapping logic.

@menny

menny commented Feb 18, 2026

Copy link
Copy Markdown
Author

This is useful for me as some of the CLIs I use over ssh have special handling for SHIFT + ENTER.

@butlerx

butlerx commented May 26, 2026

Copy link
Copy Markdown
Owner

Hey @menny - this PR has merge conflicts. Could you rebase it against main? The feature looks good.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adds client-side handling for modified “special keys” (Enter/Tab/Backspace/Escape) by converting them into CSI u escape sequences via attachCustomKeyEventHandler, aiming to improve interoperability with modern TUIs that rely on CSI u for modifier-aware input.

Changes:

  • Added modifierHandler to map modified special keys to CSI u sequences and intercept those key events.
  • Updated terminal configuration to apply both copy shortcut handling and modifier mapping in the custom key event handler.
  • Added unit tests for modifier mapping behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/client/wetty/term/confiruragtion.ts Adds CSI u modifier mapping handler and wires it into xterm custom key handling.
src/client/wetty/term/confiruragtion.spec.ts Adds unit tests for the modifier mapping logic.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +30 to +33
const code = specialKeys[e.key];
const mod = modifiers + 1; // CSI u uses 1-based modifier mapping
// Send the CSI u sequence: ESC [ code ; mod u
window.wetty_term?.input(`\x1b[${code};${mod}u`, false);
Comment on lines +21 to +27
// Key codes for special keys we want to support generically
const specialKeys: Record<string, number> = {
Enter: 13,
Tab: 9,
Backspace: 127,
Escape: 27,
};
Comment on lines +4 to +18
import { modifierHandler } from './confiruragtion';

describe('modifierHandler', () => {
let inputStub: sinon.SinonStub;

beforeEach(() => {
inputStub = sinon.stub();
(window as any).wetty_term = {
input: inputStub
};
});

afterEach(() => {
delete (window as any).wetty_term;
sinon.restore();
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.

3 participants