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