Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ThreadTerminalRouteScreen.tsx

1,389 lines47.1 KB

1import { DEFAULT_TERMINAL_ID, EnvironmentId, ThreadId } from "@t3tools/contracts";
2import { type KnownTerminalSession } from "@t3tools/client-runtime/state/terminal";
3import { SymbolView } from "../../components/AppSymbol";
4import { ScreenHeader } from "../../components/ScreenHeader";
5import { StackActions, useNavigation, type StaticScreenProps } from "@react-navigation/native";
6import { useCallback, useEffect, useMemo, useRef, useState } from "react";
7import { Alert, Platform, Pressable, View } from "react-native";
8import { useSafeAreaInsets } from "react-native-safe-area-context";
9import { AppText as Text } from "../../components/AppText";
10import { TerminalContextSheet } from "./TerminalContextSheet";
11import { hasNativeTerminalSurface } from "./nativeTerminalModule";
12import * as Clipboard from "expo-clipboard";
13import * as Schema from "effect/Schema";
14import {
15 KeyboardController,
16 KeyboardEvents,
17 KeyboardStickyView,
18 useKeyboardState,
19} from "react-native-keyboard-controller";
20​
21import {
22 ComposerToolbarButton,
23 ComposerToolbarRow,
24 ComposerToolbarScroller,
25} from "../../components/ComposerToolbar";
26import { EmptyState } from "../../components/EmptyState";
27import { GlassSurface } from "../../components/GlassSurface";
28import { LoadingScreen } from "../../components/LoadingScreen";
29import { MaterialScreenContent } from "../../components/MaterialScreenContent";
30import { MaterialButton } from "../../components/MaterialButton";
31import { MaterialIconButton } from "../../components/MaterialIconButton";
32import { environmentCatalog } from "../../connection/catalog";
33import { useEnvironmentPresentation } from "../../state/presentation";
34import { terminalEnvironment } from "../../state/terminal";
35import { useAtomCommand } from "../../state/use-atom-command";
36import { useServerConfigs } from "../../state/entities";
37import { useWorkspaceState } from "../../state/workspace";
38import {
39 MAX_TERMINAL_FONT_SIZE,
40 MIN_TERMINAL_FONT_SIZE,
41 TERMINAL_FONT_SIZE_STEP,
42 stepTerminalFontSize,
43} from "../../lib/appearancePreferences";
44import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
45import {
46 useAttachedTerminalSession,
47 useKnownTerminalSessions,
48} from "../../state/use-terminal-session";
49import { useThreadSelection } from "../../state/use-thread-selection";
50import { useSelectedThreadDetail } from "../../state/use-thread-detail";
51import { EnvironmentConnectionNotice } from "../connection/EnvironmentConnectionNotice";
52import { TerminalSurface } from "./NativeTerminalSurface";
53import { getMobileTerminalTheme } from "./terminalTheme";
54import { terminalDebugLog } from "./terminalDebugLog";
55import {
56 getTerminalBufferReplayKey,
57 getTerminalSurfaceReplayBuffer,
58 TERMINAL_BUFFER_REPLAY_STABILITY_DELAY_MS,
59} from "./terminalBufferReplay";
60import {
61 resolveTerminalOpenLocation,
62 takePendingTerminalLaunch,
63 type PendingTerminalLaunch,
64} from "./terminalLaunchContext";
65import {
66 basename,
67 buildTerminalMenuSessions,
68 getTerminalStatusLabel,
69 nextOpenTerminalId,
70 previousLiveTerminalId,
71 resolveTerminalSessionLabel,
72 type TerminalMenuSession,
73} from "./terminalMenu";
74import {
75 hostPlatformFromOs,
76 resolveModifiedTerminalInput,
77 type HostPlatform,
78 type PendingModifier,
79} from "./terminalInput";
80import { createTerminalPasteSession } from "./terminalPaste";
81import { cacheTerminalGridSize, getCachedTerminalGridSize } from "./terminalUiState";
82​
83function TerminalHeader(props: {
84 readonly subtitle: string;
85 readonly isEnvironmentReady: boolean;
86 readonly fontSize: number;
87 readonly terminalId: string;
88 readonly sessions: ReadonlyArray<TerminalMenuSession>;
89 readonly status: Parameters<typeof getTerminalStatusLabel>[0];
90 readonly workspaceRoot: string;
91 readonly onCloseTerminal: () => void;
92 readonly onDecreaseFontSize: () => void;
93 readonly onIncreaseFontSize: () => void;
94 readonly onOpenNewTerminal: () => void;
95 readonly onSelectTerminal: (terminalId: string) => void;
96}) {
97 return (
98 <ScreenHeader
99 title="Terminal"
100 subtitle={props.subtitle}
101 onBack={props.onCloseTerminal}
102 backInSplitView={{
103 accessibilityLabel: "Back to chat",
104 icon: "chevron.left",
105 }}
106 menus={
107 props.isEnvironmentReady
108 ? [
109 {
110 title: "Terminal options",
111 icon: "terminal",
112 status: getTerminalStatusLabel(props.status),
113 items: [
114 {
115 id: "text-size",
116 title: "Text size",
117 icon: "textformat.size",
118 inline: true,
119 items: [
120 {
121 id: "font-decrease",
122 title: `A- ${Math.max(MIN_TERMINAL_FONT_SIZE, props.fontSize - TERMINAL_FONT_SIZE_STEP).toFixed(1)} pt`,
123 disabled: props.fontSize <= MIN_TERMINAL_FONT_SIZE,
124 onPress: props.onDecreaseFontSize,
125 },
126 {
127 id: "font-increase",
128 title: `A+ ${Math.min(MAX_TERMINAL_FONT_SIZE, props.fontSize + TERMINAL_FONT_SIZE_STEP).toFixed(1)} pt`,
129 disabled: props.fontSize >= MAX_TERMINAL_FONT_SIZE,
130 onPress: props.onIncreaseFontSize,
131 },
132 ],
133 },
134 ...props.sessions.map((session) => ({
135 id: `terminal-session:${session.terminalId}`,
136 title: session.displayLabel,
137 icon: "terminal",
138 subtitle: [
139 getTerminalStatusLabel({
140 status: session.status,
141 hasRunningSubprocess: session.hasRunningSubprocess,
142 }),
143 basename(session.cwd),
144 ]
145 .filter(Boolean)
146 .join(" · "),
147 selected: session.terminalId === props.terminalId,
148 onPress: () => props.onSelectTerminal(session.terminalId),
149 })),
150 {
151 id: "terminal-new",
152 title: "Open new terminal",
153 icon: "plus",
154 subtitle: `Start another shell in ${basename(props.workspaceRoot) ?? "this workspace"}`,
155 onPress: props.onOpenNewTerminal,
156 },
157 ],
158 },
159 ]
160 : undefined
161 }
162 />
163 );
165​
166const DEFAULT_TERMINAL_COLS = 80;
167const DEFAULT_TERMINAL_ROWS = 24;
168const TERMINAL_ACCESSORY_HEIGHT = 52;
169const SHOWCASE_ENABLED = process.env.EXPO_PUBLIC_SHOWCASE === "1";
170​
171class TerminalClipboardReadError extends Schema.TaggedError<TerminalClipboardReadError>()(
172 "TerminalClipboardReadError",
173 { terminalId: Schema.String, cause: Schema.Defect() },
174) {
175 override get message(): string {
176 return `Failed to read the clipboard for a paste into terminal ${this.terminalId}.`;
177 }
179​
180type TerminalToolbarAction =
181 | { readonly kind: "send"; readonly key: string; readonly label: string; readonly data: string }
182 | { readonly kind: "clear"; readonly key: string; readonly label: string }
183 | { readonly kind: "paste"; readonly key: string; readonly label: string }
184 | {
185 readonly kind: "modifier";
186 readonly key: string;
187 readonly label: string;
188 readonly modifier: PendingModifier;
189 };
190​
191function firstRouteParam(value: string | string[] | undefined): string | null {
192 if (Array.isArray(value)) {
193 return value[0] ?? null;
194 }
195​
196 return value ?? null;
198​
199function inferHostPlatform(environmentLabel: string | null): HostPlatform {
200 const value = environmentLabel?.toLowerCase() ?? "";
201 if (
202 value.includes("mac") ||
203 value.includes("macbook") ||
204 value.includes("mac mini") ||
205 value.includes("imac") ||
206 value.includes("darwin")
207 ) {
208 return "mac";
209 }
210 if (value.includes("windows") || value.includes("win")) {
211 return "windows";
212 }
213 if (value.includes("linux") || value.includes("ubuntu") || value.includes("debian")) {
214 return "linux";
215 }
216​
217 return "unknown";
219​
220function pickRunningTerminalSessionForBootstrap(
221 sessions: ReadonlyArray<KnownTerminalSession>,
222): KnownTerminalSession | null {
223 const running = sessions.filter(
224 (session) => session.state.status === "running" || session.state.status === "starting",
225 );
226 if (running.length === 0) {
227 return null;
228 }
229 return (
230 running.find((session) => session.target.terminalId === DEFAULT_TERMINAL_ID) ??
231 running[0] ??
232 null
233 );
235​
236type ThreadTerminalRouteScreenProps = StaticScreenProps<{
237 readonly environmentId: string;
238 readonly threadId: string;
239 readonly terminalId?: string;
240}>;
241​
242export function ThreadTerminalRouteScreen(props: ThreadTerminalRouteScreenProps) {
243 const insets = useSafeAreaInsets();
244 const navigation = useNavigation();
245 const writeTerminal = useAtomCommand(terminalEnvironment.write, "terminal write");
246 const resizeTerminal = useAtomCommand(terminalEnvironment.resize, "terminal resize");
247 const clearTerminal = useAtomCommand(terminalEnvironment.clear, "terminal clear");
248 const closeTerminal = useAtomCommand(terminalEnvironment.close, "terminal close");
249 const openTerminal = useAtomCommand(terminalEnvironment.open, "terminal open");
250 const retryEnvironment = useAtomCommand(environmentCatalog.retryNow, "environment retry");
251 const { state: workspaceState } = useWorkspaceState();
252 const params = props.route.params;
253 const { selectedThread, selectedThreadProject, selectedEnvironmentConnection } =
254 useThreadSelection();
255 const selectedThreadDetail = useSelectedThreadDetail();
256 const routeEnvironmentIdRaw = firstRouteParam(params.environmentId);
257 const routeThreadIdRaw = firstRouteParam(params.threadId);
258 const routeEnvironmentId = routeEnvironmentIdRaw
259 ? EnvironmentId.make(routeEnvironmentIdRaw)
260 : null;
261 const routeThreadId = routeThreadIdRaw ? ThreadId.make(routeThreadIdRaw) : null;
262 const environment = useEnvironmentPresentation(routeEnvironmentId);
263 const isEnvironmentReady = environment.presentation?.connection.phase === "connected";
264 const requestedTerminalId = firstRouteParam(params.terminalId);
265 const terminalId = requestedTerminalId ?? DEFAULT_TERMINAL_ID;
266 const [captureRequest, setCaptureRequest] = useState(0);
267 const [capturedOutput, setCapturedOutput] = useState<string | null>(null);
268 const {
269 isReady: hasResolvedFontPreference,
270 appearance,
271 themeAppearance: appearanceScheme,
272 themeId,
273 setTerminalFontSize,
274 themeVariables,
275 } = useAppearancePreferences();
276 const fontSize = appearance.terminalFontSize;
277 const cachedRouteGridSize =
278 routeEnvironmentId && routeThreadId
279 ? getCachedTerminalGridSize({
280 environmentId: routeEnvironmentId,
281 threadId: routeThreadId,
282 terminalId,
283 })
284 : null;
285 const knownSessions = useKnownTerminalSessions({
286 environmentId: selectedThread?.environmentId ?? null,
287 threadId: selectedThread?.id ?? null,
288 });
289 const runningSession = useMemo(
290 () => pickRunningTerminalSessionForBootstrap(knownSessions),
291 [knownSessions],
292 );
293 const activeKnownSession = useMemo(
294 () => knownSessions.find((session) => session.target.terminalId === terminalId) ?? null,
295 [knownSessions, terminalId],
296 );
297 const launchTarget = useMemo(
298 () =>
299 selectedThread
300 ? {
301 environmentId: selectedThread.environmentId,
302 threadId: selectedThread.id,
303 terminalId,
304 }
305 : null,
306 [selectedThread, terminalId],
307 );
308 const launchTargetKey = launchTarget
309 ? `${launchTarget.environmentId}:${launchTarget.threadId}:${launchTarget.terminalId}`
310 : null;
311 const [pendingLaunchEntry, setPendingLaunchEntry] = useState<{
312 readonly key: string | null;
313 readonly launch: PendingTerminalLaunch | null;
314 }>(() => ({
315 key: launchTargetKey,
316 launch: launchTarget === null ? null : takePendingTerminalLaunch(launchTarget),
317 }));
318 const pendingLaunch =
319 pendingLaunchEntry.key === launchTargetKey ? pendingLaunchEntry.launch : null;
320 const hasResolvedPendingLaunch = pendingLaunchEntry.key === launchTargetKey;
321 const [initialAttachGridEntry, setInitialAttachGridEntry] = useState(() => ({
322 key: launchTargetKey,
323 size: cachedRouteGridSize ?? {
324 cols: DEFAULT_TERMINAL_COLS,
325 rows: DEFAULT_TERMINAL_ROWS,
326 },
327 }));
328 const initialAttachGridSize =
329 initialAttachGridEntry.key === launchTargetKey ? initialAttachGridEntry.size : null;
330 const [lastGridSize, setLastGridSize] = useState(
331 cachedRouteGridSize ?? {
332 cols: DEFAULT_TERMINAL_COLS,
333 rows: DEFAULT_TERMINAL_ROWS,
334 },
335 );
336 const [keyboardFocusRequest, setKeyboardFocusRequest] = useState(0);
337 const [isAccessoryDismissed, setIsAccessoryDismissed] = useState(false);
338 const bufferReplayTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
339 const firstNonEmptyBufferLoggedRef = useRef(false);
340 const lastBufferReplayKeyRef = useRef<string | null>(null);
341 const sentInitialInputKeyRef = useRef<string | null>(null);
342 const [readyBufferReplayKey, setReadyBufferReplayKey] = useState<string | null>(null);
343 /** Default grid is always valid for attach; onResize refines cols/rows. Requiring a cached size blocked bootstrap for new terminal routes. */
344 const [hasMeasuredSurface, setHasMeasuredSurface] = useState(true);
345 const [pendingModifierState, setPendingModifierState] = useState<{
346 readonly terminalId: string;
347 readonly value: PendingModifier | null;
348 }>({
349 terminalId,
350 value: null,
351 });
352 const shouldRedirectToRunningTerminal =
353 requestedTerminalId === null &&
354 runningSession !== null &&
355 runningSession.target.terminalId !== terminalId;
356 const launchLocationCandidate = useMemo(() => {
357 if (!selectedThread || !selectedThreadProject?.workspaceRoot) {
358 return null;
359 }
360 if (pendingLaunch) {
361 return {
362 cwd: pendingLaunch.cwd,
363 worktreePath: pendingLaunch.worktreePath,
364 };
365 }
366 return resolveTerminalOpenLocation({
367 terminalLocation: activeKnownSession?.state.summary ?? null,
368 activeSessionLocation: activeKnownSession?.state.summary ?? null,
369 workspaceRoot: selectedThreadProject.workspaceRoot,
370 threadShellWorktreePath: selectedThread.worktreePath ?? null,
371 threadDetailWorktreePath: selectedThreadDetail?.worktreePath ?? null,
372 });
373 }, [
374 activeKnownSession?.state.summary,
375 pendingLaunch,
376 selectedThread,
377 selectedThreadDetail?.worktreePath,
378 selectedThreadProject?.workspaceRoot,
379 ]);
380 const [initialLaunchLocationEntry, setInitialLaunchLocationEntry] = useState(() => ({
381 key: launchTargetKey,
382 location: launchLocationCandidate,
383 }));
384 const launchLocation =
385 initialLaunchLocationEntry.key === launchTargetKey ? initialLaunchLocationEntry.location : null;
386 const terminalAttachInput = useMemo(
387 () =>
388 selectedThread !== null &&
389 launchLocation !== null &&
390 hasResolvedPendingLaunch &&
391 initialAttachGridSize !== null &&
392 hasResolvedFontPreference &&
393 hasMeasuredSurface &&
394 isEnvironmentReady &&
395 !shouldRedirectToRunningTerminal
396 ? {
397 threadId: selectedThread.id,
398 terminalId,
399 cwd: launchLocation.cwd,
400 worktreePath: launchLocation.worktreePath,
401 cols: initialAttachGridSize.cols,
402 rows: initialAttachGridSize.rows,
403 ...(pendingLaunch?.env ? { env: pendingLaunch.env } : {}),
404 ...(pendingLaunch ? { restartIfNotRunning: true } : {}),
405 }
406 : null,
407 [
408 hasMeasuredSurface,
409 hasResolvedFontPreference,
410 hasResolvedPendingLaunch,
411 initialAttachGridSize,
412 isEnvironmentReady,
413 launchLocation,
414 pendingLaunch,
415 selectedThread,
416 shouldRedirectToRunningTerminal,
417 terminalId,
418 ],
419 );
420 const terminal = useAttachedTerminalSession({
421 environmentId: selectedThread?.environmentId ?? null,
422 terminal: terminalAttachInput,
423 });
424 const terminalKey = selectedThread
425 ? `${selectedThread.environmentId}:${selectedThread.id}:${terminalId}`
426 : terminalId;
427 const bufferReplayKey = useMemo(
428 () => getTerminalBufferReplayKey({ terminalKey, fontSize }),
429 [fontSize, terminalKey],
430 );
431 if (lastBufferReplayKeyRef.current === null) {
432 lastBufferReplayKeyRef.current = bufferReplayKey;
433 }
434 const terminalSurfaceBuffer = getTerminalSurfaceReplayBuffer({
435 buffer: terminal.buffer,
436 replayKey: bufferReplayKey,
437 readyReplayKey: readyBufferReplayKey,
438 });
439 const isRunning = terminal.status === "running" || terminal.status === "starting";
440​
441 // When the process ends while this screen is attached (e.g. typing `exit`),
442 // close the session and leave the screen, mirroring the web drawer's
443 // onSessionExited flow. Only react to a running -> exited transition
444 // observed on this screen so already-exited sessions can still be opened
445 // (they restart on attach).
446 const runningTerminalKeyRef = useRef<string | null>(null);
447 const reopenedStaleTerminalKeyRef = useRef<string | null>(null);
448 const pendingExitNavigationRef = useRef<string | null>(null);
449​
450 // Attach subscriptions are cached with an idle TTL, so revisiting a
451 // terminal whose session ended while unobserved reuses the stale stream
452 // without a new attach RPC — the server never respawns anything. Detect
453 // that (dead status with processed events, never seen running here) and
454 // issue an explicit open; its snapshot flows into the live subscription.
455 useEffect(() => {
456 if (isRunning) {
457 reopenedStaleTerminalKeyRef.current = null;
458 return;
459 }
460 if (
461 terminalAttachInput === null ||
462 !selectedThread ||
463 (terminal.status !== "closed" && terminal.status !== "exited") ||
464 terminal.version === 0 ||
465 runningTerminalKeyRef.current === terminalKey ||
466 reopenedStaleTerminalKeyRef.current === terminalKey
467 ) {
468 return;
469 }
470 reopenedStaleTerminalKeyRef.current = terminalKey;
471 void openTerminal({
472 environmentId: selectedThread.environmentId,
473 input: {
474 threadId: selectedThread.id,
475 terminalId,
476 cwd: terminalAttachInput.cwd,
477 worktreePath: terminalAttachInput.worktreePath,
478 cols: terminalAttachInput.cols,
479 rows: terminalAttachInput.rows,
480 ...(terminalAttachInput.env ? { env: terminalAttachInput.env } : {}),
481 },
482 }).then((result) => {
483 // Release the guard on failure so a later render can retry the respawn.
484 if (result._tag === "Failure" && reopenedStaleTerminalKeyRef.current === terminalKey) {
485 reopenedStaleTerminalKeyRef.current = null;
486 }
487 });
488 }, [
489 isRunning,
490 openTerminal,
491 selectedThread,
492 terminal.status,
493 terminal.version,
494 terminalAttachInput,
495 terminalId,
496 terminalKey,
497 ]);
498​
499 useEffect(() => {
500 terminalDebugLog("surface:props", {
501 terminalKey,
502 atomBufferLen: terminal.buffer.length,
503 surfaceBufferLen: terminalSurfaceBuffer.length,
504 replayKey: bufferReplayKey,
505 readyReplayKey: readyBufferReplayKey,
506 status: terminal.status,
507 version: terminal.version,
508 });
509 }, [
510 bufferReplayKey,
511 readyBufferReplayKey,
512 terminal.buffer.length,
513 terminal.status,
514 terminal.version,
515 terminalKey,
516 terminalSurfaceBuffer.length,
517 ]);
518​
519 useEffect(() => {
520 terminalDebugLog("session:status", {
521 terminalKey,
522 status: terminal.status,
523 error: terminal.error,
524 summary: terminal.summary?.cwd ?? null,
525 bufferLen: terminal.buffer.length,
526 version: terminal.version,
527 });
528 }, [
529 terminal.buffer.length,
530 terminal.error,
531 terminal.status,
532 terminal.summary?.cwd,
533 terminal.version,
534 terminalKey,
535 ]);
536​
537 useEffect(() => {
538 if (terminal.buffer.length === 0 || firstNonEmptyBufferLoggedRef.current) {
539 return;
540 }
541 firstNonEmptyBufferLoggedRef.current = true;
542 terminalDebugLog("session:first-nonempty-buffer", {
543 terminalKey,
544 length: terminal.buffer.length,
545 preview: terminal.buffer.slice(0, 160),
546 });
547 }, [terminal.buffer, terminal.buffer.length, terminalKey]);
548 const cwd = terminal.summary?.cwd ?? selectedThreadProject?.workspaceRoot ?? null;
549 const serverConfigs = useServerConfigs();
550 const hostOs =
551 routeEnvironmentId === null
552 ? null
553 : (serverConfigs.get(routeEnvironmentId)?.environment.platform.os ?? null);
554 // The descriptor is authoritative; the label is only a hint until it arrives.
555 const hostPlatform = useMemo(
556 () =>
557 hostPlatformFromOs(hostOs) ??
558 inferHostPlatform(selectedEnvironmentConnection?.environmentLabel ?? null),
559 [hostOs, selectedEnvironmentConnection?.environmentLabel],
560 );
561​
562 const terminalTheme = getMobileTerminalTheme(themeId, appearanceScheme);
563 const pendingModifier =
564 pendingModifierState.terminalId === terminalId ? pendingModifierState.value : null;
565 const headerSubtitle = selectedThreadProject?.title ?? "";
566 const terminalToolbarActions = useMemo<ReadonlyArray<TerminalToolbarAction>>(() => {
567 const modifierActions: ReadonlyArray<TerminalToolbarAction> =
568 hostPlatform === "mac"
569 ? [
570 { kind: "modifier", key: "cmd", label: "cmd", modifier: "meta" },
571 { kind: "modifier", key: "ctrl", label: "ctrl", modifier: "ctrl" },
572 ]
573 : [
574 { kind: "modifier", key: "ctrl", label: "ctrl", modifier: "ctrl" },
575 { kind: "modifier", key: "alt", label: "alt", modifier: "meta" },
576 ];
577​
578 return [
579 { kind: "send", key: "esc", label: "esc", data: "\u001b" },
580 ...modifierActions,
581 { kind: "send", key: "tab", label: "tab", data: "\t" },
582 { kind: "paste", key: "paste", label: "paste" },
583 { kind: "clear", key: "clear", label: "clear" },
584 { kind: "send", key: "up", label: "↑", data: "\u001b[A" },
585 { kind: "send", key: "down", label: "↓", data: "\u001b[B" },
586 { kind: "send", key: "left", label: "←", data: "\u001b[D" },
587 { kind: "send", key: "right", label: "→", data: "\u001b[C" },
588 { kind: "send", key: "tilde", label: "~", data: "~" },
589 { kind: "send", key: "pipe", label: "|", data: "|" },
590 { kind: "send", key: "slash", label: "/", data: "/" },
591 { kind: "send", key: "dash", label: "-", data: "-" },
592 ];
593 }, [hostPlatform]);
594 const keyboardState = useKeyboardState((state) => ({
595 height: state.height,
596 isVisible: state.isVisible,
597 }));
598 const isAccessoryVisible = keyboardState.isVisible && !isAccessoryDismissed;
599 // Android's terminal owns an EditText; turning off autoFocus also clears its native focus.
600 const terminalAutoFocus =
601 Platform.OS === "android"
602 ? !isAccessoryDismissed &&
603 (!SHOWCASE_ENABLED || keyboardFocusRequest > 0 || keyboardState.isVisible)
604 : !SHOWCASE_ENABLED;
605 const terminalBottomInset =
606 (keyboardState.isVisible ? keyboardState.height : 0) +
607 (isAccessoryVisible ? TERMINAL_ACCESSORY_HEIGHT : 0);
608​
609 useEffect(() => {
610 const keyboardWillShow = KeyboardEvents.addListener("keyboardWillShow", () => {
611 setIsAccessoryDismissed(false);
612 });
613 const keyboardWillHide = KeyboardEvents.addListener("keyboardWillHide", () => {
614 setIsAccessoryDismissed(true);
615 });
616​
617 return () => {
618 keyboardWillShow.remove();
619 keyboardWillHide.remove();
620 };
621 }, []);
622​
623 const terminalMenuSessions = useMemo<ReadonlyArray<TerminalMenuSession>>(
624 () =>
625 buildTerminalMenuSessions({
626 knownSessions,
627 workspaceRoot: selectedThreadProject?.workspaceRoot ?? null,
628 currentSession: {
629 terminalId,
630 cwd: cwd ?? null,
631 status: terminal.status,
632 hasRunningSubprocess: terminal.hasRunningSubprocess,
633 displayLabel: resolveTerminalSessionLabel(terminalId, terminal.summary),
634 updatedAt: terminal.updatedAt,
635 },
636 }),
637 [
638 cwd,
639 knownSessions,
640 selectedThreadProject?.workspaceRoot,
641 terminal.hasRunningSubprocess,
642 terminal.summary,
643 terminal.status,
644 terminal.updatedAt,
645 terminalId,
646 ],
647 );
648​
649 useEffect(() => {
650 if (pendingLaunchEntry.key === launchTargetKey) {
651 return;
652 }
653 setPendingLaunchEntry({
654 key: launchTargetKey,
655 launch: launchTarget === null ? null : takePendingTerminalLaunch(launchTarget),
656 });
657 }, [launchTarget, launchTargetKey, pendingLaunchEntry.key]);
658​
659 useEffect(() => {
660 if (initialAttachGridEntry.key === launchTargetKey) {
661 return;
662 }
663 setInitialAttachGridEntry({
664 key: launchTargetKey,
665 size: cachedRouteGridSize ?? {
666 cols: DEFAULT_TERMINAL_COLS,
667 rows: DEFAULT_TERMINAL_ROWS,
668 },
669 });
670 }, [cachedRouteGridSize, initialAttachGridEntry.key, launchTargetKey]);
671​
672 useEffect(() => {
673 if (
674 initialLaunchLocationEntry.key === launchTargetKey &&
675 initialLaunchLocationEntry.location !== null
676 ) {
677 return;
678 }
679 if (initialLaunchLocationEntry.key === launchTargetKey && launchLocationCandidate === null) {
680 return;
681 }
682 setInitialLaunchLocationEntry({
683 key: launchTargetKey,
684 location: launchLocationCandidate,
685 });
686 }, [
687 initialLaunchLocationEntry.key,
688 initialLaunchLocationEntry.location,
689 launchLocationCandidate,
690 launchTargetKey,
691 ]);
692​
693 useEffect(() => {
694 if (!shouldRedirectToRunningTerminal || !selectedThread || !runningSession) {
695 return;
696 }
697 navigation.dispatch(
698 StackActions.replace("ThreadTerminal", {
699 environmentId: String(selectedThread.environmentId),
700 threadId: String(selectedThread.id),
701 terminalId: runningSession.target.terminalId,
702 }),
703 );
704 }, [navigation, runningSession, selectedThread, shouldRedirectToRunningTerminal]);
705​
706 useEffect(() => {
707 const initialInput = pendingLaunch?.initialInput;
708 if (
709 !initialInput ||
710 !selectedThread ||
711 terminal.version === 0 ||
712 sentInitialInputKeyRef.current === launchTargetKey
713 ) {
714 return;
715 }
716 sentInitialInputKeyRef.current = launchTargetKey;
717 void writeTerminal({
718 environmentId: selectedThread.environmentId,
719 input: {
720 threadId: selectedThread.id,
721 terminalId,
722 data: initialInput,
723 },
724 });
725 }, [
726 launchTargetKey,
727 pendingLaunch?.initialInput,
728 selectedThread,
729 terminal.version,
730 terminalId,
731 writeTerminal,
732 ]);
733​
734 useEffect(() => {
735 firstNonEmptyBufferLoggedRef.current = false;
736 sentInitialInputKeyRef.current = null;
737 }, [terminalKey]);
738​
739 const clearBufferReplayTimer = useCallback(() => {
740 if (bufferReplayTimerRef.current !== null) {
741 clearTimeout(bufferReplayTimerRef.current);
742 bufferReplayTimerRef.current = null;
743 }
744 }, []);
745​
746 const scheduleBufferReplayReady = useCallback(() => {
747 clearBufferReplayTimer();
748 const replayKey = bufferReplayKey;
749 terminalDebugLog("replay:schedule-ready", {
750 replayKey,
751 delayMs: TERMINAL_BUFFER_REPLAY_STABILITY_DELAY_MS,
752 });
753 bufferReplayTimerRef.current = setTimeout(() => {
754 bufferReplayTimerRef.current = null;
755 setReadyBufferReplayKey(replayKey);
756 terminalDebugLog("replay:ready", { replayKey });
757 }, TERMINAL_BUFFER_REPLAY_STABILITY_DELAY_MS);
758 }, [bufferReplayKey, clearBufferReplayTimer]);
759​
760 useEffect(() => {
761 if (lastBufferReplayKeyRef.current === bufferReplayKey) {
762 return;
763 }
764​
765 lastBufferReplayKeyRef.current = bufferReplayKey;
766 clearBufferReplayTimer();
767 setReadyBufferReplayKey(null);
768 }, [bufferReplayKey, clearBufferReplayTimer]);
769​
770 useEffect(() => clearBufferReplayTimer, [clearBufferReplayTimer]);
771​
772 useEffect(() => {
773 if (!routeEnvironmentId || !routeThreadId) {
774 setLastGridSize({
775 cols: DEFAULT_TERMINAL_COLS,
776 rows: DEFAULT_TERMINAL_ROWS,
777 });
778 return;
779 }
780​
781 setLastGridSize(
782 getCachedTerminalGridSize({
783 environmentId: routeEnvironmentId,
784 threadId: routeThreadId,
785 terminalId,
786 }) ?? {
787 cols: DEFAULT_TERMINAL_COLS,
788 rows: DEFAULT_TERMINAL_ROWS,
789 },
790 );
791 setHasMeasuredSurface(true);
792 }, [routeEnvironmentId, routeThreadId, terminalId]);
793​
794 /** Resolves true once the pty accepted the write, false if it was skipped or rejected. */
795 const writeInput = useCallback(
796 async (data: string): Promise<boolean> => {
797 if (!selectedThread || !isRunning) {
798 return false;
799 }
800​
801 const result = await writeTerminal({
802 environmentId: selectedThread.environmentId,
803 input: {
804 threadId: selectedThread.id,
805 terminalId,
806 data,
807 },
808 });
809 return result._tag === "Success";
810 },
811 [isRunning, selectedThread, terminalId, writeTerminal],
812 );
813​
814 const pasteSessionRef = useRef<ReturnType<typeof createTerminalPasteSession> | null>(null);
815 if (pasteSessionRef.current === null) {
816 pasteSessionRef.current = createTerminalPasteSession();
817 }
818 const pasteSession = pasteSessionRef.current;
819​
820 // Drop delayed clipboard reads whenever the route or attached pty changes.
821 useEffect(() => {
822 pasteSession.reset(isRunning);
823 return () => {
824 pasteSession.reset(false);
825 };
826 }, [isRunning, pasteSession, terminal.lifecycleVersion, terminalKey]);
827​
828 const pasteFromClipboard = useCallback(async () => {
829 await pasteSession.paste({
830 readText: Clipboard.getStringAsync,
831 write: writeInput,
832 onReadError: (cause) => {
833 console.error(new TerminalClipboardReadError({ terminalId, cause }));
834 },
835 });
836 }, [pasteSession, terminalId, writeInput]);
837​
838 /** Sends a key through the armed toolbar modifier, if any, and disarms it. */
839 const writeModifiedInput = useCallback(
840 (data: string) => {
841 if (pendingModifier === null) {
842 void writeInput(data);
843 return;
844 }
845​
846 setPendingModifierState({ terminalId, value: null });
847 const resolved = resolveModifiedTerminalInput({
848 data,
849 modifier: pendingModifier,
850 hostPlatform,
851 });
852 if (resolved.kind === "paste") {
853 void pasteFromClipboard();
854 return;
855 }
856 void writeInput(resolved.data);
857 },
858 [hostPlatform, pasteFromClipboard, pendingModifier, terminalId, writeInput],
859 );
860​
861 const handleInput = useCallback(
862 (data: string) => {
863 if (data.length === 0) {
864 return;
865 }
866​
867 writeModifiedInput(data);
868 },
869 [writeModifiedInput],
870 );
871​
872 const handleResize = useCallback(
873 (size: { readonly cols: number; readonly rows: number }) => {
874 terminalDebugLog("native:onResize", {
875 cols: size.cols,
876 rows: size.rows,
877 terminalKey,
878 });
879 setHasMeasuredSurface(true);
880 if (readyBufferReplayKey !== bufferReplayKey) {
881 scheduleBufferReplayReady();
882 }
883 if (routeEnvironmentId && routeThreadId) {
884 cacheTerminalGridSize(
885 {
886 environmentId: routeEnvironmentId,
887 threadId: routeThreadId,
888 terminalId,
889 },
890 size,
891 );
892 }
893 if (size.cols === lastGridSize.cols && size.rows === lastGridSize.rows) {
894 return;
895 }
896​
897 setLastGridSize(size);
898 if (!selectedThread || !isRunning) {
899 return;
900 }
901​
902 void resizeTerminal({
903 environmentId: selectedThread.environmentId,
904 input: {
905 threadId: selectedThread.id,
906 terminalId,
907 cols: size.cols,
908 rows: size.rows,
909 },
910 });
911 },
912 [
913 isRunning,
914 lastGridSize.cols,
915 lastGridSize.rows,
916 bufferReplayKey,
917 readyBufferReplayKey,
918 routeEnvironmentId,
919 routeThreadId,
920 resizeTerminal,
921 scheduleBufferReplayReady,
922 selectedThread,
923 terminalId,
924 terminalKey,
925 ],
926 );
927​
928 const handleSelectTerminal = useCallback(
929 (nextTerminalId: string) => {
930 if (!selectedThread || nextTerminalId === terminalId) {
931 return;
932 }
933​
934 navigation.dispatch(
935 StackActions.replace("ThreadTerminal", {
936 environmentId: String(selectedThread.environmentId),
937 threadId: String(selectedThread.id),
938 terminalId: nextTerminalId,
939 }),
940 );
941 },
942 [navigation, selectedThread, terminalId],
943 );
944​
945 const handleCloseTerminal = useCallback(() => {
946 if (navigation.canGoBack()) {
947 navigation.goBack();
948 return;
949 }
950 navigation.dispatch(
951 StackActions.replace("Thread", {
952 environmentId: params.environmentId,
953 threadId: params.threadId,
954 }),
955 );
956 }, [navigation, params.environmentId, params.threadId]);
957​
958 const navigateAwayAfterExit = useCallback(() => {
959 // With other shells still live, fall through to the previous one instead
960 // of dropping the user back on the thread.
961 const fallbackTerminalId = previousLiveTerminalId({
962 sessions: terminalMenuSessions,
963 exitedTerminalId: terminalId,
964 });
965 if (fallbackTerminalId !== null && selectedThread) {
966 navigation.dispatch(
967 StackActions.replace("ThreadTerminal", {
968 environmentId: String(selectedThread.environmentId),
969 threadId: String(selectedThread.id),
970 terminalId: fallbackTerminalId,
971 }),
972 );
973 return;
974 }
975 if (navigation.canGoBack()) {
976 navigation.goBack();
977 return;
978 }
979 // Deep-linked/root mounts have nothing to pop; land on the thread
980 // instead of stranding the user on a dead terminal.
981 if (selectedThread) {
982 navigation.dispatch(
983 StackActions.replace("Thread", {
984 environmentId: String(selectedThread.environmentId),
985 threadId: String(selectedThread.id),
986 }),
987 );
988 }
989 }, [navigation, selectedThread, terminalId, terminalMenuSessions]);
990​
991 useEffect(() => {
992 // Detached (hidden surface or environment drop): forget the running
993 // marker so a reattach takes the stale-reopen path instead of misreading
994 // the dead snapshot as an exit observed on this screen. A pending exit
995 // navigation stays armed — it only clears once the session runs again —
996 // so refocusing a dead screen still leaves it.
997 if (terminalAttachInput === null) {
998 runningTerminalKeyRef.current = null;
999 return;
1001 if (isRunning) {
1002 runningTerminalKeyRef.current = terminalKey;
1003 // The session came back (e.g. respawned elsewhere) before the user
1004 // returned; a stale pending exit must not eject a live terminal.
1005 pendingExitNavigationRef.current = null;
1006 return;
1008 // The web drawer treats both exited and closed as session end.
1009 const sessionEnded = terminal.status === "exited" || terminal.status === "closed";
1010 if (!sessionEnded || runningTerminalKeyRef.current !== terminalKey) {
1011 return;
1013 runningTerminalKeyRef.current = null;
1014 // Mark this key handled so the stale-attach effect doesn't respawn the
1015 // session the user just ended.
1016 reopenedStaleTerminalKeyRef.current = terminalKey;
1017 if (selectedThread) {
1018 void closeTerminal({
1019 environmentId: selectedThread.environmentId,
1020 input: {
1021 threadId: selectedThread.id,
1022 terminalId,
1023 },
1024 });
1026 if (navigation.isFocused()) {
1027 navigateAwayAfterExit();
1028 return;
1030 // An unfocused screen can't navigate; leave when the user returns so
1031 // they never land on the dead session.
1032 pendingExitNavigationRef.current = terminalKey;
1033 }, [
1034 closeTerminal,
1035 isRunning,
1036 navigateAwayAfterExit,
1037 navigation,
1038 selectedThread,
1039 terminal.status,
1040 terminalAttachInput,
1041 terminalId,
1042 terminalKey,
1043 ]);
1044​
1045 useEffect(
1046 () =>
1047 navigation.addListener("focus", () => {
1048 if (pendingExitNavigationRef.current !== terminalKey) {
1049 return;
1051 pendingExitNavigationRef.current = null;
1052 navigateAwayAfterExit();
1053 }),
1054 [navigateAwayAfterExit, navigation, terminalKey],
1055 );
1056​
1057 const handleOpenNewTerminal = useCallback(() => {
1058 if (!selectedThread) {
1059 return;
1061​
1062 navigation.dispatch(
1063 StackActions.replace("ThreadTerminal", {
1064 environmentId: String(selectedThread.environmentId),
1065 threadId: String(selectedThread.id),
1066 terminalId: nextOpenTerminalId({
1067 listedTerminalIds: terminalMenuSessions.map((session) => session.terminalId),
1068 activeRouteTerminalId: terminalId,
1069 }),
1070 }),
1071 );
1072 }, [navigation, selectedThread, terminalId, terminalMenuSessions]);
1073​
1074 const handleDecreaseFontSize = useCallback(() => {
1075 setTerminalFontSize(stepTerminalFontSize(fontSize, -1));
1076 }, [fontSize, setTerminalFontSize]);
1077​
1078 const handleIncreaseFontSize = useCallback(() => {
1079 setTerminalFontSize(stepTerminalFontSize(fontSize, 1));
1080 }, [fontSize, setTerminalFontSize]);
1081​
1082 const handleClearTerminal = useCallback(() => {
1083 if (!selectedThread) {
1084 return;
1086​
1087 setPendingModifierState({ terminalId, value: null });
1088 void clearTerminal({
1089 environmentId: selectedThread.environmentId,
1090 input: {
1091 threadId: selectedThread.id,
1092 terminalId,
1093 },
1094 });
1095 }, [clearTerminal, selectedThread, terminalId]);
1096​
1097 const handleToolbarActionPress = useCallback(
1098 (action: TerminalToolbarAction) => {
1099 if (action.kind === "modifier") {
1100 setPendingModifierState((current) => ({
1101 terminalId,
1102 value:
1103 (current.terminalId === terminalId ? current.value : null) === action.modifier
1104 ? null
1105 : action.modifier,
1106 }));
1107 return;
1109​
1110 if (action.kind === "clear") {
1111 handleClearTerminal();
1112 return;
1114​
1115 if (action.kind === "paste") {
1116 setPendingModifierState({ terminalId, value: null });
1117 void pasteFromClipboard();
1118 return;
1120​
1121 writeModifiedInput(action.data);
1122 },
1123 [handleClearTerminal, pasteFromClipboard, terminalId, writeModifiedInput],
1124 );
1125​
1126 const handleDismissKeyboard = useCallback(() => {
1127 setIsAccessoryDismissed(true);
1128 void KeyboardController.dismiss();
1129 }, []);
1130​
1131 const handleShowKeyboard = useCallback(() => {
1132 setIsAccessoryDismissed(false);
1133 setKeyboardFocusRequest((current) => current + 1);
1134 }, []);
1135 const handleRetryEnvironment = useCallback(() => {
1136 if (routeEnvironmentId !== null) {
1137 void retryEnvironment(routeEnvironmentId);
1139 }, [retryEnvironment, routeEnvironmentId]);
1140​
1141 if (!selectedThread) {
1142 if (workspaceState.isLoadingConnections) {
1143 return <LoadingScreen message="Opening terminal…" />;
1145​
1146 return (
1147 <View className="flex-1 bg-screen">
1148 <EmptyState
1149 title="Thread unavailable"
1150 detail="This terminal route needs an active thread and workspace."
1151 />
1152 </View>
1153 );
1155​
1156 if (!selectedThreadProject?.workspaceRoot) {
1157 return (
1158 <View className="flex-1 bg-screen">
1159 <EmptyState
1160 title="Terminal unavailable"
1161 detail="This thread does not have a workspace root yet, so there is nowhere to open a shell."
1162 />
1163 </View>
1164 );
1166​
1167 if (!environment.isReady && environment.presentation === null) {
1168 return <LoadingScreen message="Opening terminal…" />;
1170​
1171 return (
1172 <>
1173 {capturedOutput !== null && selectedThread ? (
1174 <TerminalContextSheet
1175 text={capturedOutput}
1176 environmentId={selectedThread.environmentId}
1177 threadId={selectedThread.id}
1178 terminalId={terminalId}
1179 terminalLabel={resolveTerminalSessionLabel(terminalId, terminal.summary)}
1180 onClose={() => setCapturedOutput(null)}
1181 onAttach={() => {
1182 setCapturedOutput(null);
1183 if (navigation.canGoBack()) navigation.goBack();
1184 }}
1185 />
1186 ) : null}
1187 <TerminalHeader
1188 subtitle={headerSubtitle}
1189 isEnvironmentReady={isEnvironmentReady}
1190 fontSize={fontSize}
1191 terminalId={terminalId}
1192 sessions={terminalMenuSessions}
1193 status={{
1194 status: terminal.status,
1195 hasRunningSubprocess: terminal.hasRunningSubprocess,
1196 }}
1197 workspaceRoot={selectedThreadProject.workspaceRoot}
1198 onCloseTerminal={handleCloseTerminal}
1199 onDecreaseFontSize={handleDecreaseFontSize}
1200 onIncreaseFontSize={handleIncreaseFontSize}
1201 onOpenNewTerminal={handleOpenNewTerminal}
1202 onSelectTerminal={handleSelectTerminal}
1203 />
1204​
1205 <MaterialScreenContent>
1206 <View
1207 className="flex-1"
1208 style={{
1209 backgroundColor:
1210 Platform.OS === "android"
1211 ? themeVariables["--color-card-alt"]
1212 : terminalTheme.background,
1213 paddingBottom:
1214 Platform.OS === "android" && !keyboardState.isVisible ? insets.bottom : 0,
1215 }}
1217 {!isEnvironmentReady ? (
1218 <EnvironmentConnectionNotice
1219 environmentLabel={
1220 environment.presentation?.entry.target.label ??
1221 selectedEnvironmentConnection?.environmentLabel ??
1222 "Environment"
1224 connection={
1225 environment.presentation?.connection ?? {
1226 phase: "available",
1227 error: null,
1228 traceId: null,
1231 resourceName="terminal"
1232 onRetry={handleRetryEnvironment}
1233 />
1234 ) : (
1235 <>
1236 <View
1237 style={{
1238 flex: 1,
1239 paddingBottom: terminalBottomInset,
1240 }}
1242 <View
1243 pointerEvents="none"
1244 style={{
1245 position: "absolute",
1246 inset: 0,
1247 backgroundColor: terminalTheme.background,
1248 }}
1249 />
1250 <TerminalSurface
1251 autoFocus={terminalAutoFocus}
1252 buffer={terminalSurfaceBuffer}
1253 fontSize={fontSize}
1254 isRunning={isRunning}
1255 keyboardFocusRequest={keyboardFocusRequest}
1256 captureRequest={captureRequest}
1257 onCapture={(text) => {
1258 if (text.trim()) setCapturedOutput(text);
1259 else Alert.alert("No terminal output", "There is no visible output to attach.");
1260 }}
1261 onInput={handleInput}
1262 onResize={handleResize}
1263 style={{ flex: 1 }}
1264 terminalKey={terminalKey}
1265 theme={terminalTheme}
1266 />
1267 </View>
1268​
1269 {Platform.OS === "android" && !keyboardState.isVisible ? (
1270 <View className="min-h-14 flex-row items-center gap-2 bg-card-alt px-2">
1271 {selectedThread && hasNativeTerminalSurface() ? (
1272 <MaterialButton
1273 label="Attach output"
1274 tone="text"
1275 onPress={() => setCaptureRequest((value) => value + 1)}
1276 />
1277 ) : null}
1278 <View className="flex-1" />
1279 <MaterialIconButton
1280 accessibilityLabel="Show keyboard"
1281 icon="keyboard"
1282 onPress={handleShowKeyboard}
1283 />
1284 </View>
1285 ) : Platform.OS !== "android" && selectedThread && hasNativeTerminalSurface() ? (
1286 <Pressable
1287 accessibilityRole="button"
1288 onPress={() => {
1289 KeyboardController.dismiss();
1290 setCaptureRequest((value) => value + 1);
1291 }}
1292 className="px-4 py-2"
1294 <Text style={{ color: terminalTheme.foreground }}>Attach visible output</Text>
1295 </Pressable>
1296 ) : null}
1297 {isAccessoryVisible ? (
1298 <KeyboardStickyView
1299 style={{ position: "absolute", bottom: 0, left: 0, right: 0 }}
1300 offset={{ closed: 0, opened: 0 }}
1302 <View
1303 className="border-t"
1304 style={{
1305 backgroundColor: terminalTheme.background,
1306 borderTopColor: terminalTheme.border,
1307 minHeight: TERMINAL_ACCESSORY_HEIGHT,
1308 }}
1310 <ComposerToolbarRow paddingBottom={4} paddingHorizontal={8} paddingTop={4}>
1311 <ComposerToolbarScroller
1312 contentPaddingRight={2}
1313 fadeOpaque={terminalTheme.background}
1314 fadeTransparent={`${terminalTheme.background}00`}
1316 {terminalToolbarActions.map((action) => {
1317 const active =
1318 action.kind === "modifier" && pendingModifier === action.modifier;
1319​
1320 return (
1321 <ComposerToolbarButton
1322 key={action.key}
1323 active={active}
1324 label={action.label}
1325 maxWidth={120}
1326 minWidth={action.label.length > 1 ? 56 : 44}
1327 onPress={() => handleToolbarActionPress(action)}
1328 showChevron={false}
1329 textTransform={
1330 action.kind === "modifier" || action.kind === "clear"
1331 ? "uppercase"
1332 : "none"
1334 />
1335 );
1336 })}
1337 </ComposerToolbarScroller>
1338 <ComposerToolbarButton
1339 accessibilityLabel="Dismiss keyboard"
1340 icon={{ ios: "keyboard.chevron.compact.down", android: "keyboard_hide" }}
1341 onPress={handleDismissKeyboard}
1342 showChevron={false}
1343 />
1344 </ComposerToolbarRow>
1345 </View>
1346 </KeyboardStickyView>
1347 ) : !keyboardState.isVisible && Platform.OS !== "android" ? (
1348 <Pressable
1349 accessibilityLabel="Show keyboard"
1350 accessibilityRole="button"
1351 onPress={handleShowKeyboard}
1352 style={({ pressed }) => ({
1353 bottom: 16,
1354 borderRadius: 28,
1355 opacity: pressed ? 0.72 : 1,
1356 position: "absolute",
1357 right: 16,
1358 })}
1360 <GlassSurface
1361 chrome="none"
1362 fallbackColor={terminalTheme.background}
1363 glassEffectStyle="regular"
1364 tintColor="transparent"
1365 style={{
1366 alignItems: "center",
1367 borderRadius: 24,
1368 height: 48,
1369 justifyContent: "center",
1370 width: 48,
1371 }}
1372 pointerEvents="none"
1374 <SymbolView
1375 name={{ ios: "keyboard", android: "keyboard" }}
1376 size={20}
1377 tintColor={terminalTheme.foreground}
1378 type="monochrome"
1379 />
1380 </GlassSurface>
1381 </Pressable>
1382 ) : null}
1383 </>
1384 )}
1385 </View>
1386 </MaterialScreenContent>
1387 </>
1388 );