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

ThreadTerminalRouteScreen.tsx

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