@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 34 lines 1 KB
Raw
1 import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
2
3 export interface TerminalGridSize {
4 readonly cols: number;
5 readonly rows: number;
6 }
7
8 export interface TerminalUiStateTarget {
9 readonly environmentId: EnvironmentId;
10 readonly threadId: ThreadId;
11 readonly terminalId: string;
12 }
13
14 const terminalGridSizeCache = new Map<string, TerminalGridSize>();
15
16 function terminalUiStateKey(target: TerminalUiStateTarget): string {
17 return `${target.environmentId}:${target.threadId}:${target.terminalId}`;
18 }
19
20 export function getCachedTerminalGridSize(target: TerminalUiStateTarget): TerminalGridSize | null {
21 return terminalGridSizeCache.get(terminalUiStateKey(target)) ?? null;
22 }
23
24 export function cacheTerminalGridSize(
25 target: TerminalUiStateTarget,
26 size: TerminalGridSize,
27 ): TerminalGridSize {
28 const normalized = {
29 cols: Math.max(1, Math.floor(size.cols)),
30 rows: Math.max(1, Math.floor(size.rows)),
31 };
32 terminalGridSizeCache.set(terminalUiStateKey(target), normalized);
33 return normalized;
34 }