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

main
ts 17 lines 614 Bytes
Raw
1 import { useState } from "react";
2
3 /** A null buffer means the attachment is waiting for its first snapshot. */
4 export function useTerminalSurfaceBuffer({
5 terminalKey,
6 buffer,
7 }: {
8 readonly terminalKey: string;
9 readonly buffer: string | null;
10 }): string {
11 const [snapshot, setSnapshot] = useState({ terminalKey, buffer: buffer ?? "" });
12 const currentBuffer = buffer ?? (snapshot.terminalKey === terminalKey ? snapshot.buffer : "");
13 if (snapshot.terminalKey !== terminalKey || snapshot.buffer !== currentBuffer) {
14 setSnapshot({ terminalKey, buffer: currentBuffer });
15 }
16 return currentBuffer;
17 }