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

main
tsx 77 lines 2.65 KB
Raw
1 import { useGT } from "gt-react";
2 import { TerminalIcon } from "lucide-react";
3
4 import type { ContextPresentationCapability } from "../contextPresentationRegistry";
5 import { ContextChipPopover, ContextChipShell } from "../contextChipParts";
6
7 interface TerminalContextInlineChipProps {
8 label: string;
9 terminalLabel: string;
10 lineStart: number;
11 lineEnd: number;
12 text: string;
13 detailsMode: ContextPresentationCapability["details"];
14 expired?: boolean;
15 }
16
17 export function TerminalContextInlineChip(props: TerminalContextInlineChipProps) {
18 const { label, terminalLabel, lineStart, lineEnd, text, detailsMode, expired = false } = props;
19 const gt = useGT();
20
21 if (!expired && text.length > 0 && detailsMode === "popover") {
22 return (
23 <ContextChipPopover
24 kind="terminal"
25 icon={<TerminalIcon />}
26 label={label}
27 accessibleLabel={gt("Terminal excerpt, {label}", { label })}
28 >
29 <div className="overflow-hidden rounded-md border border-border/70 bg-background/80">
30 <div className="flex items-center gap-2 border-b border-border/70 px-3 py-2">
31 <TerminalIcon className="size-4 shrink-0 text-success" aria-hidden />
32 <span className="min-w-0 truncate text-sm font-medium text-foreground">
33 {terminalLabel}
34 </span>
35 <span className="ml-auto shrink-0 text-secondary-label text-xs">
36 {lineStart === lineEnd
37 ? gt("Line {lineStart}", { lineStart })
38 : gt("Lines {lineStart}–{lineEnd}", { lineStart, lineEnd })}
39 </span>
40 </div>
41 <pre
42 className="max-h-80 overflow-auto whitespace-pre bg-muted p-3 font-mono text-foreground text-xs leading-relaxed outline-none [tab-size:4] focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"
43 aria-label={gt("Captured terminal output")}
44 tabIndex={0}
45 >
46 {text}
47 </pre>
48 </div>
49 </ContextChipPopover>
50 );
51 }
52
53 return (
54 <ContextChipShell
55 kind="terminal"
56 {...(expired ? { state: "invalid" as const } : {})}
57 icon={<TerminalIcon />}
58 label={label}
59 aria-label={
60 expired
61 ? gt("Terminal excerpt, {label}, expired", { label })
62 : gt("Terminal excerpt, {label}", { label })
63 }
64 data-terminal-context-expired={expired ? "true" : undefined}
65 tooltip={
66 expired
67 ? gt(
68 "Terminal context expired. Remove and re-add {label} to include it in your message.",
69 { label },
70 )
71 : detailsMode === "none"
72 ? undefined
73 : text
74 }
75 />
76 );
77 }