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