mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-10-07 07:59:42 +02:00
Extract Claudeman's local echo overlay into a reusable xterm.js addon at packages/xterm-zerolag-input/. Provides instant keystroke feedback via a DOM overlay, eliminating perceived input latency over high-RTT connections (SSH, mobile, cloud IDEs). - Zero dependencies, compatible with xterm v5.x and @xterm/xterm v5.4+ - Configurable prompt detection (character, regex, or custom function) - Flushed text tracking for tab-switch / deferred echo scenarios - Per-character grid-aligned rendering matching xterm's canvas output - 56 tests passing (prompt finder, overlay renderer, full addon lifecycle) - Dual CJS/ESM build with full TypeScript declarations Claudeman source is unchanged — migration to consume this lib is a separate follow-up. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
37 lines
1014 B
TypeScript
37 lines
1014 B
TypeScript
import type { XtermTerminal, CellDimensions } from './types.js';
|
|
|
|
/**
|
|
* Get cell dimensions from the terminal, handling xterm.js v5 (private API)
|
|
* and v7+ (public API).
|
|
*
|
|
* Returns `null` if the terminal is not yet rendered or dimensions are
|
|
* unavailable.
|
|
*/
|
|
export function getCellDimensions(terminal: XtermTerminal): CellDimensions | null {
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
const t = terminal as any;
|
|
|
|
// Try v7+ public API first
|
|
if (t.dimensions?.css?.cell) {
|
|
return {
|
|
width: t.dimensions.css.cell.width,
|
|
height: t.dimensions.css.cell.height,
|
|
};
|
|
}
|
|
|
|
// Fall back to v5 private API
|
|
try {
|
|
const dims = t._core?._renderService?.dimensions;
|
|
if (dims?.css?.cell) {
|
|
return {
|
|
width: dims.css.cell.width,
|
|
height: dims.css.cell.height,
|
|
};
|
|
}
|
|
} catch {
|
|
// Private API may throw in some environments
|
|
}
|
|
|
|
return null;
|
|
}
|