Add global debug key (Shift+Ctrl+D), iterative tree sorting to avoid stack overflow

This commit is contained in:
Mario Zechner 2025-12-29 04:50:15 +01:00
parent 1f4594598b
commit 544814875e
5 changed files with 30 additions and 6 deletions

View file

@ -50,6 +50,7 @@ export {
isEnter,
isEscape,
isHome,
isShiftCtrlD,
isShiftCtrlP,
isShiftEnter,
isShiftTab,

View file

@ -320,6 +320,14 @@ export function isShiftCtrlP(data: string): boolean {
return matchesKittySequence(data, CODEPOINTS.p, MODIFIERS.shift + MODIFIERS.ctrl);
}
/**
* Check if input matches Shift+Ctrl+D (Kitty protocol only, for debug).
* Ignores lock key bits.
*/
export function isShiftCtrlD(data: string): boolean {
return matchesKittySequence(data, CODEPOINTS.d, MODIFIERS.shift + MODIFIERS.ctrl);
}
/**
* Check if input matches Ctrl+T (raw byte or Kitty protocol).
* Ignores lock key bits.

View file

@ -5,6 +5,7 @@
import * as fs from "node:fs";
import * as os from "node:os";
import * as path from "node:path";
import { isShiftCtrlD } from "./keys.js";
import type { Terminal } from "./terminal.js";
import { getCapabilities, setCellDimensions } from "./terminal-image.js";
import { visibleWidth } from "./utils.js";
@ -78,6 +79,9 @@ export class TUI extends Container {
private previousLines: string[] = [];
private previousWidth = 0;
private focusedComponent: Component | null = null;
/** Global callback for debug key (Shift+Ctrl+D). Called before input is forwarded to focused component. */
public onDebug?: () => void;
private renderRequested = false;
private cursorRow = 0; // Track where cursor is (0-indexed, relative to our first line)
private inputBuffer = ""; // Buffer for parsing terminal responses
@ -141,6 +145,12 @@ export class TUI extends Container {
data = filtered;
}
// Global debug key handler (Shift+Ctrl+D)
if (isShiftCtrlD(data) && this.onDebug) {
this.onDebug();
return;
}
// Pass input to focused component (including Ctrl+C)
// The focused component can decide how to handle Ctrl+C
if (this.focusedComponent?.handleInput) {