[Init] Initial commit - NetMesh terminal manager
Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
This commit is contained in:
138
components/terminal/runtime/kittyKeyboardRuntime.ts
Normal file
138
components/terminal/runtime/kittyKeyboardRuntime.ts
Normal file
@@ -0,0 +1,138 @@
|
||||
import type { IDisposable } from "@xterm/xterm";
|
||||
|
||||
import {
|
||||
buildKittyKeyboardModeQueryResponse,
|
||||
popKittyKeyboardModeFlags,
|
||||
pushKittyKeyboardModeFlags,
|
||||
setKittyKeyboardAlternateScreenActive,
|
||||
setKittyKeyboardModeFlags,
|
||||
resetKittyKeyboardModeState,
|
||||
type KittyKeyboardModeApplyMode,
|
||||
type KittyKeyboardModeState,
|
||||
} from "./kittyKeyboardProtocol";
|
||||
|
||||
export type KittyKeyboardCsiParams = readonly (number | number[])[];
|
||||
|
||||
type CsiHandlerId = {
|
||||
prefix?: string;
|
||||
intermediates?: string;
|
||||
final: string;
|
||||
};
|
||||
|
||||
type KittyKeyboardParser = {
|
||||
registerCsiHandler: (
|
||||
id: CsiHandlerId,
|
||||
callback: (params: KittyKeyboardCsiParams) => boolean,
|
||||
) => IDisposable;
|
||||
registerEscHandler: (
|
||||
id: { intermediates?: string; final: string },
|
||||
callback: () => boolean,
|
||||
) => IDisposable;
|
||||
};
|
||||
|
||||
export const readKittyKeyboardCsiParam = (
|
||||
params: KittyKeyboardCsiParams,
|
||||
index: number,
|
||||
fallback: number,
|
||||
): number => {
|
||||
const value = params[index];
|
||||
if (Array.isArray(value)) return typeof value[0] === "number" ? value[0] : fallback;
|
||||
return typeof value === "number" && value > 0 ? value : fallback;
|
||||
};
|
||||
|
||||
const normalizeKittyKeyboardApplyMode = (mode: number): KittyKeyboardModeApplyMode => {
|
||||
return mode === 2 || mode === 3 ? mode : 1;
|
||||
};
|
||||
|
||||
const paramsIncludeAny = (
|
||||
params: KittyKeyboardCsiParams,
|
||||
targets: readonly number[],
|
||||
): boolean => {
|
||||
return params.some((param) => (
|
||||
Array.isArray(param)
|
||||
? param.some((value) => targets.includes(value))
|
||||
: targets.includes(param)
|
||||
));
|
||||
};
|
||||
|
||||
export const installKittyKeyboardProtocolHandlers = (
|
||||
parser: KittyKeyboardParser,
|
||||
state: KittyKeyboardModeState,
|
||||
writeReply: (payload: string) => void,
|
||||
): IDisposable => {
|
||||
const disposables = [
|
||||
parser.registerCsiHandler(
|
||||
{ prefix: "?", final: "u" },
|
||||
() => {
|
||||
writeReply(buildKittyKeyboardModeQueryResponse(state));
|
||||
return true;
|
||||
},
|
||||
),
|
||||
parser.registerEscHandler(
|
||||
{ final: "c" },
|
||||
() => {
|
||||
resetKittyKeyboardModeState(state);
|
||||
return false;
|
||||
},
|
||||
),
|
||||
parser.registerCsiHandler(
|
||||
{ prefix: "=", final: "u" },
|
||||
(params) => {
|
||||
const flags = readKittyKeyboardCsiParam(params, 0, 0);
|
||||
const mode = normalizeKittyKeyboardApplyMode(readKittyKeyboardCsiParam(params, 1, 1));
|
||||
setKittyKeyboardModeFlags(state, flags, mode);
|
||||
return true;
|
||||
},
|
||||
),
|
||||
parser.registerCsiHandler(
|
||||
{ prefix: ">", final: "u" },
|
||||
(params) => {
|
||||
pushKittyKeyboardModeFlags(state, readKittyKeyboardCsiParam(params, 0, 0));
|
||||
return true;
|
||||
},
|
||||
),
|
||||
parser.registerCsiHandler(
|
||||
{ prefix: "<", final: "u" },
|
||||
(params) => {
|
||||
popKittyKeyboardModeFlags(state, readKittyKeyboardCsiParam(params, 0, 1));
|
||||
return true;
|
||||
},
|
||||
),
|
||||
parser.registerCsiHandler(
|
||||
{ prefix: "?", final: "h" },
|
||||
(params) => {
|
||||
if (paramsIncludeAny(params, [47, 1047, 1049])) {
|
||||
setKittyKeyboardAlternateScreenActive(state, true);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
),
|
||||
parser.registerCsiHandler(
|
||||
{ prefix: "?", final: "l" },
|
||||
(params) => {
|
||||
if (paramsIncludeAny(params, [47, 1047, 1049])) {
|
||||
setKittyKeyboardAlternateScreenActive(state, false);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
),
|
||||
];
|
||||
|
||||
return {
|
||||
dispose: () => {
|
||||
for (const disposable of disposables) {
|
||||
disposable.dispose();
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export const installKittyKeyboardProtocolHandlersIfEnabled = (
|
||||
enabled: boolean | undefined,
|
||||
parser: KittyKeyboardParser,
|
||||
state: KittyKeyboardModeState,
|
||||
writeReply: (payload: string) => void,
|
||||
): IDisposable | undefined => {
|
||||
if (enabled !== true) return undefined;
|
||||
return installKittyKeyboardProtocolHandlers(parser, state, writeReply);
|
||||
};
|
||||
Reference in New Issue
Block a user