Terminal Simulator
Terminal animation: CLI demo that types commands and prints output. Terminal window with chunked command playback, freeze-frame pauses, step scrolling, and an optional cursor-pinned zoom camera.
Source
components/kuchi/terminal-simulator.tsx
1"use client";23import {4 Easing,5 getRemotionEnvironment,6 interpolate,7 useCurrentFrame,8 useVideoConfig,9} from "remotion";10import {11 Item,12 mixOklch,13 parseColor,14 resolveFont,15 type KuchiTheme,16 useKuchiTheme,17 withAlpha,18} from "@/lib/kuchi-ui";1920export type TerminalLineType = "command" | "log" | "success" | "error";2122/** Package-manager command panel — the flythrough's second station. */23export interface CommandSpec {24 /** Tab labels. The first is the active tab. */25 managers?: string[];26 /** The command typed into the active tab, e.g. "npm install One Tool". */27 text: string;28}2930export interface TerminalLine {31 text: string;32 type: TerminalLineType;33 /** Frame gap before this line starts typing. Defaults to 8. */34 delay?: number;35 /**36 * Extra freeze-frame pause AFTER this line finishes typing, in frames.37 * Use this to build tension before the next batch of logs. If omitted,38 * lines whose text ends in "..." auto-freeze for 18 frames.39 */40 pause?: number;41}4243export interface TerminalZoom {44 /** Turn the extra landing zoom on. */45 enabled: boolean;46 /** Camera zoom the final punch-in lands at. Defaults to 2.4. */47 scale?: number;48 /** Kept for API compatibility; the flythrough camera always leads the eye. */49 followCursor?: boolean;50}5152export interface TerminalSimulatorProps {53 lines?: TerminalLine[];54 /**55 * Headline at the first camera station. Wrap words in `*asterisks*` to tint56 * them with the accent gradient. `null`/"" skips the station — the camera57 * starts on the command panel instead.58 */59 intro?: string | null;60 /**61 * Command panel at the second camera station. `null` skips the station.62 */63 command?: CommandSpec | null;64 /** Command-panel surface color. */65 /** Overrides the design system's `card`. */66 background?: string;67 /** Hairline border color for the command-panel ring and divider. */68 /** Overrides the design system's `border`. */69 borderColor?: string;70 /** Design-system token overrides. */71 theme?: Partial<KuchiTheme>;72 /** Defaults to `"dark"` — a terminal is lit for dark. */73 mode?: "light" | "dark";74 /**75 * The face this scene paints its words in — a label from `fonts.ts`76 * ("Inter", "Space Grotesk", "Instrument Serif") or a CSS family you have77 * loaded yourself. Unset, the scene keeps the face it was designed around.78 *79 * Overrides `theme.fontFamily`, which is how a brand kit re-skins a whole80 * timeline from one value.81 */82 fontFamily?: string;83 fontSize?: number;84 /**85 * Reveal speed. The reveal is CHUNKED — every `1 / charsPerFrame` frames86 * bumps the cursor by `chunkSize` characters, so output appears in bursts87 * instead of dripping char-by-char.88 */89 charsPerFrame?: number;90 /** Characters revealed per step. */91 chunkSize?: number;92 /**93 * Landing zoom of the final punch onto the terminal. Pass `true` for the94 * 2.4x default or an object for a custom scale. Off = 1.5x.95 */96 zoom?: boolean | TerminalZoom;97 speed?: number;98 className?: string;99}100101// ─── Stage & camera constants ────────────────────────────────────────────────102// The scene is ONE world the camera flies over. Nothing enters from a screen103// edge — the camera pans/zooms between three fixed stations on a single black104// canvas, exactly like a camera-type-flythrough.105106// The stage, the panel and the tab row are app chrome and come from the design107// system. The syntax palette below is the terminal's own colour scheme — the108// look, not chrome — and stays literal, exposed through props.109110/** Station anchors in world px (world is sized for a 1280x720 viewport). */111const INTRO_POS = { x: 640, y: 360 };112const CMD_POS = { x: 2140, y: 520 };113const TERM_POS = { x: 2140, y: 1660 };114115/** Camera timeline (frames at speed 1). */116const DRIFT_START = 22; // intro starts creeping left117const WHIP_START = 40; // sudden acceleration toward the command panel118const CMD_ARRIVE = 70; // camera lands on the command panel119const CMD_TYPE_START = 74; // "npm install One Tool" starts typing120const PUSH_END = 112; // slow push-in while typing (leaves the ghost trail)121const PULL_END = 138; // zoom-out + descend toward the terminal122const PUNCH_END = 158; // sudden punch-in lands on the terminal123const TERM_TYPE_START = 146; // terminal lines start typing as we land124125/** Command-panel geometry in world px. */126const CMD_W = 760;127const CMD_H = 170;128129/** Terminal station geometry in world px (sized against the reference). */130const TERM_BAR_OFFSET = 137; // bar sits this far left of the focus point131const TERM_TEXT_OFFSET = 90; // text column left edge relative to focus132const TERM_BLOCK_TOP = 215; // first line sits this far above the focus point133const TERM_LINE_H = 83;134const TERM_FONT = 44;135136/** Lead-in used for the terminal lines' start schedule. */137const LEAD_IN_FRAMES = 10;138139// ─── Palette (matched against the reference stills) ─────────────────────────140141/** Accent gradient for `*emphasized*` intro words. */142const ACCENT_GRADIENT = "linear-gradient(90deg, #7C96FF 0%, #A78BFA 100%)";143144/** Command-row syntax palette: dim manager/subcommand, highlighted args. */145const CMD_MANAGER_COLOR = "#A0673F";146const CMD_SUBCOMMAND_COLOR = "#64789B";147const CMD_ARG_COLOR = "#D7E4F8";148149/** Focus-terminal palette. */150const TERM_ACCENT = "#2EA043";151const TERM_CURSOR = "#1D5B36";152const TERM_COLORS: Record<TerminalLineType, string> = {153 command: "#F2F5F3",154 log: "#6E7873",155 success: "#1F8039",156 error: "#F04438",157};158159/**160 * On a light page the two colours drawn for a dark one — near-white args and161 * commands — would vanish, so they take ink instead; the rest read on either.162 */163const LIGHT_ARG_COLOR = "#1B2533";164const LIGHT_TERM_COLORS: Record<TerminalLineType, string> = {165 ...TERM_COLORS,166 command: "#141414",167};168169/** Functional color map kept for the public helper API. */170const TYPE_COLORS: Record<TerminalLineType, string> = TERM_COLORS;171172const SANS_FAMILY =173 '-apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif';174const MONO_FAMILY = "ui-monospace, SFMono-Regular, Menlo, monospace";175176const DEFAULT_INTRO = "*work* one step at a *time.*";177178const DEFAULT_COMMAND: CommandSpec = {179 managers: ["npm", "pnpm", "yarn", "bun"],180 text: "npm install One Tool",181};182183const DEFAULT_LINES: TerminalLine[] = [184 { text: "{labels: ['bug']})", type: "log", delay: 0 },185 { text: "→ label added", type: "success", delay: 6 },186 { text: "$", type: "log", delay: 10 },187 { text: "One task", type: "command", delay: 4 },188];189190// ─── Pure helpers ────────────────────────────────────────────────────────────191192/** Auto freeze-frame heuristic: any line ending in "..." holds the camera. */193export function autoPause(line: TerminalLine): number {194 if (line.pause !== undefined) return line.pause;195 // `replace`, not `trimEnd` (ES2019): stock Remotion types ES2015.196 if (line.text.replace(/\s+$/, "").endsWith("...")) return 18;197 return 0;198}199200/** Frames the chunked reveal needs to type `textLength` characters. */201export function typingDuration(202 textLength: number,203 charsPerFrame: number,204 chunkSize: number,205): number {206 return Math.ceil(textLength / (chunkSize * charsPerFrame));207}208209/**210 * Cumulative start frame for each line, including per-line delays and the211 * auto/explicit freeze pauses AFTER a line finishes typing.212 */213export function computeLineStarts(214 lines: TerminalLine[],215 charsPerFrame: number,216 chunkSize: number,217 leadIn: number = LEAD_IN_FRAMES,218): number[] {219 const starts: number[] = [];220 let acc = leadIn;221 for (const line of lines) {222 acc += line.delay ?? 8;223 starts.push(acc);224 acc +=225 typingDuration(line.text.length, charsPerFrame, chunkSize) +226 autoPause(line);227 }228 return starts;229}230231/**232 * Chunked reveal: Math.floor of an interpolated count, snapped up to the233 * nearest multiple of `chunkSize`. This is what gives the bursty terminal234 * feel — text doesn't drip, it lurches.235 */236export function chunkedReveal(237 localFrame: number,238 totalChars: number,239 charsPerFrame: number,240 chunkSize: number,241): number {242 if (totalChars <= 0) return 0;243 const linear = Math.floor(244 interpolate(localFrame, [0, totalChars / charsPerFrame], [0, totalChars], {245 extrapolateLeft: "clamp",246 extrapolateRight: "clamp",247 }),248 );249 return Math.min(totalChars, Math.ceil(linear / chunkSize) * chunkSize);250}251252/**253 * STEP-FUNCTION scroll. Each overflowing line snaps the buffer up by exactly254 * one row on the frame it begins. No interpolation, no easing — terminals do255 * not glide. Returns the number of rows scrolled off the top.256 */257export function computeScrollRows(258 frame: number,259 starts: number[],260 visibleLines: number,261): number {262 let rows = 0;263 for (let i = visibleLines; i < starts.length; i++) {264 if (frame >= starts[i]) rows++;265 }266 return rows;267}268269/** Normalize the `zoom` prop into a fully-resolved camera config. */270export function resolveZoom(271 zoom: boolean | TerminalZoom | undefined,272): Required<TerminalZoom> {273 if (zoom === undefined || zoom === false) {274 return { enabled: false, scale: 1, followCursor: true };275 }276 if (zoom === true) {277 return { enabled: true, scale: 2.4, followCursor: true };278 }279 return {280 enabled: zoom.enabled,281 scale: zoom.scale ?? 2.4,282 followCursor: zoom.followCursor ?? true,283 };284}285286/** Split `*emphasis*` runs out of the intro string, preserving spaces. */287export function parseIntro(288 text: string,289): Array<{ text: string; accent: boolean }> {290 const out: Array<{ text: string; accent: boolean }> = [];291 const re = /\*([^*]+)\*/g;292 let last = 0;293 let m: RegExpExecArray | null = re.exec(text);294 while (m !== null) {295 if (m.index > last)296 out.push({ text: text.slice(last, m.index), accent: false });297 out.push({ text: m[1], accent: true });298 last = m.index + m[0].length;299 m = re.exec(text);300 }301 if (last < text.length) out.push({ text: text.slice(last), accent: false });302 return out;303}304305/** Colour a shell command: word 0 = manager, word 1 = subcommand, rest = args. */306export function commandSpans(307 text: string,308 argColor: string = CMD_ARG_COLOR,309): Array<{ text: string; color: string }> {310 const out: Array<{ text: string; color: string }> = [];311 let wordIndex = -1;312 for (const part of text.split(/(\s+)/)) {313 if (part.length === 0) continue;314 if (/^\s+$/.test(part)) {315 out.push({ text: part, color: argColor });316 continue;317 }318 wordIndex++;319 const color =320 wordIndex === 0321 ? CMD_MANAGER_COLOR322 : wordIndex === 1323 ? CMD_SUBCOMMAND_COLOR324 : argColor;325 out.push({ text: part, color });326 }327 return out;328}329330// ─── Camera ──────────────────────────────────────────────────────────────────331332export interface CameraStop {333 /** Frame this stop is reached. */334 frame: number;335 /** World focus point (px) the camera centers on. */336 x: number;337 y: number;338 /** Zoom at this stop. */339 z: number;340 /** Easing applied while travelling INTO this stop from the previous one. */341 easing?: (t: number) => number;342}343344export interface CameraState {345 x: number;346 y: number;347 z: number;348}349350/**351 * Piecewise camera resolver. Between consecutive stops the camera lerps352 * x/y/z with the segment's own easing — so a lazy drift can hand off to a353 * sudden ease-in whip, which is the whole feel of the flythrough. Clamps to354 * the first/last stop outside the timeline.355 */356export function cameraAt(frame: number, stops: CameraStop[]): CameraState {357 const first = stops[0];358 const last = stops[stops.length - 1];359 if (frame <= first.frame) return { x: first.x, y: first.y, z: first.z };360 if (frame >= last.frame) return { x: last.x, y: last.y, z: last.z };361 for (let i = 0; i < stops.length - 1; i++) {362 const a = stops[i];363 const b = stops[i + 1];364 if (frame >= a.frame && frame < b.frame) {365 const t = (frame - a.frame) / (b.frame - a.frame);366 const e = b.easing ? b.easing(t) : t;367 return {368 x: a.x + (b.x - a.x) * e,369 y: a.y + (b.y - a.y) * e,370 z: a.z + (b.z - a.z) * e,371 };372 }373 }374 return { x: last.x, y: last.y, z: last.z };375}376377/**378 * The flythrough's shot list: hold on the intro → creep left → sudden379 * ease-in whip to the command panel → slow push while it types (this is380 * what draws the ghost trail) → zoom-out descending → sudden punch-in381 * landing on the terminal. When a station is skipped its segment collapses.382 */383export function buildCameraStops(384 hasIntro: boolean,385 hasCommand: boolean,386 landingZoom: number,387): CameraStop[] {388 const whip = Easing.bezier(0.7, 0, 0.25, 1);389 const punch = Easing.bezier(0.75, 0, 0.3, 1);390 const glide = Easing.bezier(0.35, 0, 0.55, 1);391392 const stops: CameraStop[] = [];393 if (hasIntro) {394 stops.push(395 { frame: 0, x: INTRO_POS.x, y: INTRO_POS.y, z: 1 },396 { frame: DRIFT_START, x: INTRO_POS.x, y: INTRO_POS.y, z: 1 },397 // The slight leftward text drift = camera creeping right, accelerating.398 {399 frame: WHIP_START,400 x: INTRO_POS.x + 52,401 y: INTRO_POS.y,402 z: 1.02,403 easing: Easing.in(Easing.quad),404 },405 );406 }407 if (hasCommand) {408 stops.push(409 {410 frame: hasIntro ? CMD_ARRIVE : 0,411 x: CMD_POS.x,412 y: CMD_POS.y,413 z: 1.55,414 easing: whip,415 },416 // Slow push-in while the command types — leaves the trailing copies.417 {418 frame: PUSH_END,419 x: CMD_POS.x,420 y: CMD_POS.y + 28,421 z: 1.9,422 easing: Easing.inOut(Easing.quad),423 },424 // Zoom out and start descending toward the terminal.425 {426 frame: PULL_END,427 x: CMD_POS.x,428 y: CMD_POS.y + 630,429 z: 0.95,430 easing: glide,431 },432 );433 }434 stops.push({435 frame: hasCommand ? PUNCH_END : hasIntro ? CMD_ARRIVE : 0,436 x: TERM_POS.x,437 y: TERM_POS.y,438 z: landingZoom,439 easing: punch,440 });441 return stops;442}443444/** Screen-space speed of the focus point — drives the motion-blur trail. */445export function cameraSpeed(frame: number, stops: CameraStop[]): number {446 const a = cameraAt(frame - 1, stops);447 const b = cameraAt(frame, stops);448 const pan = Math.hypot(b.x - a.x, b.y - a.y) * b.z;449 const zoomEdge = Math.abs(b.z - a.z) * 360;450 return pan + zoomEdge;451}452453// ─── Component ───────────────────────────────────────────────────────────────454455/** Ghost samples for the motion-blur trail: frames back, opacity, blur px. */456const GHOSTS = [457 { back: 2, alpha: 0.3, blur: 3 },458 { back: 4, alpha: 0.18, blur: 6 },459 { back: 6, alpha: 0.1, blur: 10 },460];461462export function TerminalSimulator({463 lines = DEFAULT_LINES,464 intro = DEFAULT_INTRO,465 command = DEFAULT_COMMAND,466 background,467 borderColor,468 theme,469 mode,470 fontFamily,471 fontSize = 18,472 charsPerFrame = 2,473 chunkSize = 3,474 zoom = false,475 speed = 1,476 className,477}: TerminalSimulatorProps) {478 const frame = useCurrentFrame() * speed;479 const { fps, width, height } = useVideoConfig();480 const { isRendering } = getRemotionEnvironment();481 const t = useKuchiTheme(theme, mode ?? "dark");482 const light = (mode ?? "dark") === "light";483 const face = resolveFont(fontFamily ?? t.fontFamily) ?? SANS_FAMILY;484 const panel = background ?? t.card;485 const hairline = borderColor ?? t.border;486 // One constant stage across the whole flythrough — the page, a shade under487 // the panel that floats on it.488 // A transparent page asks for no page, so the stage under the panel goes too.489 const stage =490 parseColor(t.background).alpha === 0491 ? "transparent"492 : mixOklch(t.background, "#000", 0.35);493494 const hasIntro = intro != null && intro.trim().length > 0;495 const hasCommand = command != null && command.text.trim().length > 0;496 const camera = resolveZoom(zoom);497 const landingZoom = camera.enabled ? camera.scale : 1.5;498499 const stops = buildCameraStops(hasIntro, hasCommand, landingZoom);500 const cam = cameraAt(frame, stops);501 const speedPx = cameraSpeed(frame, stops);502 // Trail strength ramps in from barely-moving; saturates on the whip.503 const trail = Math.min(1, Math.max(0, (speedPx - 2) / 30));504505 const worldTransform = (c: CameraState) =>506 `translate(${width / 2 - c.x * c.z}px, ${height / 2 - c.y * c.z}px) scale(${c.z})`;507508 // The world is drawn once per ghost and once under the camera; only the509 // camera's copy hands its lines to Studio, so each line has one outline.510 const world = (primary: boolean) => (511 <WorldContent512 face={face}513 frame={frame}514 fps={fps}515 intro={hasIntro ? intro : null}516 command={hasCommand ? command : null}517 lines={lines}518 background={panel}519 borderColor={hairline}520 ink={t.foreground}521 inkMuted={t.mutedForeground}522 light={light}523 fontSize={fontSize}524 charsPerFrame={charsPerFrame}525 chunkSize={chunkSize}526 hasIntro={hasIntro}527 primary={primary}528 />529 );530531 return (532 <div533 className={className}534 style={{535 position: "absolute",536 inset: 0,537 overflow: "hidden",538 background: stage,539 textRendering: "geometricPrecision",540 }}541 >542 {/* Motion-blur trail: the same world drawn at recent camera positions.543 Only alive while the camera actually moves — it IS the drop of the544 fast moves, no element ever slides in from a screen edge. */}545 {trail > 0.01 &&546 GHOSTS.map((g) => (547 <div548 key={g.back}549 style={{550 position: "absolute",551 left: 0,552 top: 0,553 transformOrigin: "0 0",554 transform: worldTransform(cameraAt(frame - g.back, stops)),555 opacity: g.alpha * trail,556 filter: `blur(${g.blur * trail}px)`,557 pointerEvents: "none",558 }}559 >560 {world(false)}561 </div>562 ))}563564 {/* The camera */}565 <div566 style={{567 position: "absolute",568 left: 0,569 top: 0,570 transformOrigin: "0 0",571 transform: worldTransform(cam),572 ...(isRendering ? {} : { willChange: "transform" }),573 }}574 >575 {world(true)}576 </div>577 </div>578 );579}580581// ─── World (all three stations on one canvas) ────────────────────────────────582583function WorldContent({584 frame,585 fps,586 intro,587 command,588 lines,589 background,590 borderColor,591 ink,592 inkMuted,593 light,594 fontSize,595 charsPerFrame,596 chunkSize,597 hasIntro,598 face,599 primary,600}: {601 frame: number;602 fps: number;603 intro: string | null;604 command: CommandSpec | null;605 lines: TerminalLine[];606 background: string;607 borderColor: string;608 ink: string;609 inkMuted: string;610 light: boolean;611 fontSize: number;612 charsPerFrame: number;613 chunkSize: number;614 hasIntro: boolean;615 face: string;616 primary: boolean;617}) {618 const s = fontSize / 18; // font scale, layout stays fixed619620 return (621 <div style={{ position: "absolute", left: 0, top: 0 }}>622 {intro !== null && (623 <IntroStation624 frame={frame}625 text={intro}626 fontScale={s}627 ink={ink}628 face={face}629 />630 )}631 {command !== null && (632 <CommandStation633 frame={frame}634 command={command}635 background={background}636 borderColor={borderColor}637 ink={ink}638 inkMuted={inkMuted}639 light={light}640 fontScale={s}641 charsPerFrame={charsPerFrame}642 chunkSize={chunkSize}643 fps={fps}644 typeStart={hasIntro ? CMD_TYPE_START : 8}645 />646 )}647 <TerminalStation648 frame={frame}649 light={light}650 lines={lines}651 fontScale={s}652 charsPerFrame={charsPerFrame}653 chunkSize={chunkSize}654 fps={fps}655 primary={primary}656 typeStart={657 command !== null ? TERM_TYPE_START : hasIntro ? CMD_ARRIVE - 6 : 6658 }659 />660 </div>661 );662}663664/** Station 1 — the headline, words fading in staggered. */665function IntroStation({666 frame,667 text,668 fontScale,669 ink,670 face,671}: {672 frame: number;673 text: string;674 fontScale: number;675 ink: string;676 face: string;677}) {678 const tokens = parseIntro(text);679 return (680 <div681 style={{682 position: "absolute",683 left: INTRO_POS.x,684 top: INTRO_POS.y,685 transform: "translate(-50%, -50%)",686 whiteSpace: "pre",687 fontFamily: face,688 fontSize: Math.round(58 * fontScale),689 fontWeight: 600,690 letterSpacing: "-0.01em",691 }}692 >693 {tokens.map((tok, i) => {694 const t = interpolate(frame, [2 + i * 4, 14 + i * 4], [0, 1], {695 extrapolateLeft: "clamp",696 extrapolateRight: "clamp",697 easing: Easing.out(Easing.cubic),698 });699 const style = tok.accent700 ? {701 backgroundImage: ACCENT_GRADIENT,702 WebkitBackgroundClip: "text" as const,703 backgroundClip: "text" as const,704 color: "transparent",705 }706 : { color: ink };707 return (708 <span709 // biome-ignore lint/suspicious/noArrayIndexKey: positional tokens710 key={i}711 style={{ ...style, opacity: t, filter: `blur(${(1 - t) * 3}px)` }}712 >713 {tok.text}714 </span>715 );716 })}717 </div>718 );719}720721/** Station 2 — the package-manager panel with the highlighted install command. */722function CommandStation({723 frame,724 command,725 background,726 borderColor,727 ink,728 inkMuted,729 light,730 fontScale,731 charsPerFrame,732 chunkSize,733 fps,734 typeStart,735}: {736 frame: number;737 command: CommandSpec;738 background: string;739 borderColor: string;740 ink: string;741 inkMuted: string;742 light: boolean;743 fontScale: number;744 charsPerFrame: number;745 chunkSize: number;746 fps: number;747 typeStart: number;748}) {749 const argColor = light ? LIGHT_ARG_COLOR : CMD_ARG_COLOR;750 const managers = command.managers?.length ? command.managers : ["npm"];751 const revealed = chunkedReveal(752 Math.max(0, frame - typeStart),753 command.text.length,754 charsPerFrame,755 chunkSize,756 );757 const typingDone = revealed >= command.text.length;758 const blink = Math.floor((frame / fps) * 2) % 2 === 0;759 const spans = commandSpans(command.text, argColor);760761 const tabFont = Math.round(20 * fontScale);762 const rowFont = Math.round(33 * fontScale);763764 return (765 <div766 style={{767 position: "absolute",768 left: CMD_POS.x - CMD_W / 2,769 top: CMD_POS.y - CMD_H / 2,770 width: CMD_W,771 height: CMD_H,772 background,773 borderRadius: 14,774 overflow: "hidden",775 boxShadow: `0 0 0 1px ${borderColor}, 0 30px 60px ${withAlpha(776 mixOklch(background, "#000", 0.8),777 0.55,778 )}`,779 fontFamily: MONO_FAMILY,780 }}781 >782 {/* Tab row */}783 <div784 style={{785 height: 54,786 display: "flex",787 alignItems: "center",788 gap: 6,789 padding: "0 16px",790 borderBottom: `1px solid ${borderColor}`,791 }}792 >793 {managers.map((m, i) => (794 <div795 key={m}796 style={{797 fontSize: tabFont,798 fontWeight: i === 0 ? 600 : 500,799 padding: "7px 14px",800 borderRadius: 8,801 color: i === 0 ? ink : inkMuted,802 background: i === 0 ? withAlpha(ink, 0.1) : "transparent",803 }}804 >805 {m}806 </div>807 ))}808 </div>809810 {/* Command row — manager and subcommand dim, the args highlighted */}811 <div812 style={{813 display: "flex",814 alignItems: "center",815 height: CMD_H - 54,816 padding: "0 24px",817 fontSize: rowFont,818 letterSpacing: "0.01em",819 whiteSpace: "pre",820 }}821 >822 {(() => {823 let acc = 0;824 return spans.map((p, i) => {825 const start = acc;826 acc += p.text.length;827 const vis = Math.max(0, Math.min(p.text.length, revealed - start));828 return (829 <span830 // biome-ignore lint/suspicious/noArrayIndexKey: positional spans831 key={i}832 style={{ color: p.color }}833 >834 {p.text.slice(0, vis)}835 </span>836 );837 });838 })()}839 {!typingDone && frame >= typeStart && blink && (840 <span841 style={{842 display: "inline-block",843 width: rowFont * 0.55,844 height: rowFont,845 background: argColor,846 marginLeft: 2,847 }}848 />849 )}850 </div>851 </div>852 );853}854855/** Station 3 — the green focus terminal. */856function TerminalStation({857 frame,858 light,859 lines,860 fontScale,861 charsPerFrame,862 chunkSize,863 fps,864 typeStart,865 primary,866}: {867 frame: number;868 light: boolean;869 lines: TerminalLine[];870 fontScale: number;871 charsPerFrame: number;872 chunkSize: number;873 fps: number;874 typeStart: number;875 primary: boolean;876}) {877 const starts = computeLineStarts(lines, charsPerFrame, chunkSize, typeStart);878 const font = Math.round(TERM_FONT * fontScale);879 const blink = Math.floor((frame / fps) * 2) % 2 === 0;880881 return (882 <>883 {/* Accent bar */}884 <div885 style={{886 position: "absolute",887 left: TERM_POS.x - TERM_BAR_OFFSET,888 top: TERM_POS.y - 520,889 width: 5,890 height: 1040,891 background: TERM_ACCENT,892 boxShadow: `0 0 22px ${withAlpha(TERM_ACCENT, 0.75)}`,893 }}894 />895 {/* Output column */}896 <div897 style={{898 position: "absolute",899 left: TERM_POS.x - TERM_TEXT_OFFSET,900 top: TERM_POS.y - TERM_BLOCK_TOP,901 fontFamily: MONO_FAMILY,902 }}903 >904 {lines.map((line, index) => {905 const revealed = chunkedReveal(906 Math.max(0, frame - starts[index]),907 line.text.length,908 charsPerFrame,909 chunkSize,910 );911 const typingDone = revealed >= line.text.length;912 const isLast = index === lines.length - 1;913 const showCursor =914 line.type === "command" &&915 frame >= starts[index] &&916 (!typingDone || (isLast && blink));917 return (918 // The line Studio selects is its row: nothing moves a line on its919 // own, the camera carries the whole column.920 <Item921 // biome-ignore lint/suspicious/noArrayIndexKey: lines are positional and never reorder922 key={index}923 index={index}924 primary={primary}925 >926 <div927 style={{928 height: TERM_LINE_H,929 display: "flex",930 alignItems: "center",931 color: (light ? LIGHT_TERM_COLORS : TERM_COLORS)[line.type],932 fontSize: font,933 whiteSpace: "pre",934 }}935 >936 <span>{line.text.substring(0, revealed)}</span>937 {showCursor && (938 <span939 style={{940 display: "inline-block",941 width: font * 0.6,942 height: font * 0.95,943 background: TERM_CURSOR,944 marginLeft: 6,945 }}946 />947 )}948 </div>949 </Item>950 );951 })}952 </div>953 </>954 );955}956957export { TYPE_COLORS };









