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