xonecas.io
70160
Ce

cel-tui / files

cel-tui / examples / pet.ts

23.2 KB
1/**
2 * cel-tui: Virtual Pet (Tamagotchi)
3 *
4 * A feature-rich example exercising the full API surface:
5 * - Layers (creation modal, log modal, death screen overlay)
6 * - TextInput (pet name)
7 * - Focus traversal (Tab/Shift+Tab/Enter/Escape)
8 * - Controlled scroll (activity log)
9 * - Timers & animation frames
10 * - Buttons, key bindings, click handlers
11 * - External state management
12 *
13 * Run: bun run examples/pet.ts
14 */
15
16import { Button, Divider, Spacer, VDivider } from "@cel-tui/components";
17import {
18  cel,
19  HStack,
20  type Node,
21  ProcessTerminal,
22  Text,
23  TextInput,
24  VStack,
25} from "@cel-tui/core";
26import { warningBox } from "./warning-box";
27
28// ─── Pet Definitions ────────────────────────────────────────────
29
30interface PetDef {
31  kind: string;
32  idle: { happy: string[][]; hungry: string[][] };
33  excited: string[][];
34  dead: string[];
35}
36
37const PETS: PetDef[] = [
38  {
39    kind: "Cat",
40    idle: {
41      happy: [
42        [
43          "    /\\_/\\    ",
44          "   ( ^.^ )   ",
45          "    > ^ <    ",
46          "   /|   |\\   ",
47          "  (_|   |_)  ",
48        ],
49        [
50          "    /\\_/\\    ",
51          "   ( ^.^ )   ",
52          "    > ^ <    ",
53          "   /|   |\\   ",
54          "  (_|   |_)  ",
55          "     ~ ~     ",
56        ],
57      ],
58      hungry: [
59        [
60          "    /\\_/\\    ",
61          "   ( T.T )   ",
62          "    > o <    ",
63          "   /|   |\\   ",
64          "  (_|   |_)  ",
65        ],
66        [
67          "    /\\_/\\    ",
68          "   ( T.T )   ",
69          "    > o <    ",
70          "    |   |    ",
71          "   _|   |_   ",
72        ],
73      ],
74    },
75    excited: [
76      [
77        "    /\\_/\\    ",
78        "   ( >.< )   ",
79        "    >\\^/<    ",
80        "   \\|   |/   ",
81        "   (_\\_/_)   ",
82        "    \\   /    ",
83      ],
84      [
85        "    /\\_/\\    ",
86        "  \\( ^o^ )/  ",
87        "    > ^ <    ",
88        "    |   |    ",
89        "   (_\\_/_)   ",
90        "    /   \\    ",
91      ],
92    ],
93    dead: [
94      "    /\\_/\\    ",
95      "   ( x.x )   ",
96      "    > - <    ",
97      "    |   |    ",
98      "    |___|    ",
99    ],
100  },
101  {
102    kind: "Dog",
103    idle: {
104      happy: [
105        [
106          "  |\\_/|      ",
107          "  | @ @      ",
108          "  |  <>  _   ",
109          "  |_/| |//   ",
110          "    |/   /   ",
111          "   /    /    ",
112        ],
113        [
114          "  |\\_/|      ",
115          "  | @ @      ",
116          "  |  <>  _   ",
117          "  |_/| |//   ",
118          "    |/   /   ",
119          "   /  |_/    ",
120        ],
121      ],
122      hungry: [
123        [
124          "  |\\_/|      ",
125          "  | ; ;      ",
126          "  |  ..  _   ",
127          "  |_/| |//   ",
128          "    |/   /   ",
129          "   /    /    ",
130        ],
131        [
132          "  |\\_/|      ",
133          "  | ; ;      ",
134          "  |  ..      ",
135          "  |_/| |     ",
136          "    |/  |    ",
137          "   /    /    ",
138        ],
139      ],
140    },
141    excited: [
142      [
143        "  |\\_/|      ",
144        "  | O O      ",
145        "  |  D>  _   ",
146        "  |_/| |//   ",
147        "   /|/  _/   ",
148        "  / |__/     ",
149      ],
150      [
151        "   |\\_/|     ",
152        "   | O O     ",
153        "   |  D>     ",
154        " __|_/|\\__   ",
155        "  / |/ \\     ",
156        " /  |  /     ",
157      ],
158    ],
159    dead: [
160      "  |\\_/|      ",
161      "  | x x      ",
162      "  |  --  _   ",
163      "  |_/| |//   ",
164      "    |/   /   ",
165      "   /____/    ",
166    ],
167  },
168  {
169    kind: "Bunny",
170    idle: {
171      happy: [
172        ["   (\\(\\      ", "   ( -.-)    ", '  o_(")(")   '],
173        ["   (\\(\\      ", "   ( -.-)    ", '  o_(")(")   ', "      *      "],
174      ],
175      hungry: [
176        ["   (\\(\\      ", "   ( ;.;)    ", '  c_(")(")   '],
177        ["   (\\(\\      ", "   ( ;.;)    ", '  c_(")(")   ', "     ...     "],
178      ],
179    },
180    excited: [
181      ["    (\\(\\     ", "    ( ^.^)   ", '  (")(")_o   ', "     \\|/     "],
182      ["   (\\(\\      ", "  \\( ^o^)/   ", '   (")(")    ', "    /|\\      "],
183    ],
184    dead: [
185      "   (\\(\\      ",
186      "   ( x.x)    ",
187      '  c_(")(")   ',
188      "    R.I.P    ",
189    ],
190  },
191];
192
193// ─── App State ──────────────────────────────────────────────────
194
195type Screen = "create" | "main" | "dead";
196let screen: Screen = "create";
197
198// -- Creation state --
199let petName = "";
200let selectedKind = 0;
201let nameInputFocused = true; // only TextInput needs controlled focus (arrow key routing)
202
203// -- Pet state --
204let pet: PetDef | null = null;
205let health = 100;
206let hunger = 0; // 0 = full, 100 = starving
207let happiness = 100;
208
209// -- Animation --
210let frame = 0;
211let anim: "idle" | "excited" = "idle";
212let excitedTimer: ReturnType<typeof setTimeout> | null = null;
213
214// -- Timers --
215let tickTimer: ReturnType<typeof setInterval> | null = null;
216let decayTimer: ReturnType<typeof setInterval> | null = null;
217
218// -- Activity log --
219let log: string[] = [];
220let showLog = false;
221let logScroll = 0;
222
223// ─── Helpers ────────────────────────────────────────────────────
224
225function ts(): string {
226  return new Date().toLocaleTimeString("en-US", { hour12: false });
227}
228
229function addLog(msg: string) {
230  log.push(`[${ts()}] ${msg}`);
231  logScroll = Math.max(0, log.length - 12);
232}
233
234function startGame() {
235  pet = PETS[selectedKind]!;
236  petName = petName.trim() || pet.kind;
237  health = 100;
238  hunger = 0;
239  happiness = 100;
240  anim = "idle";
241  frame = 0;
242  log = [];
243  showLog = false;
244  nameInputFocused = false;
245  screen = "main";
246
247  addLog(`${petName} the ${pet.kind} was born!`);
248  addLog("Press [F] feed · [P] pet · [L] log");
249  startTimers();
250  cel.render();
251}
252
253function startTimers() {
254  stopTimers();
255  tickTimer = setInterval(() => {
256    frame++;
257    cel.render();
258  }, 600);
259
260  decayTimer = setInterval(() => {
261    if (screen !== "main") return;
262    hunger = Math.min(100, hunger + 3);
263    happiness = Math.max(0, happiness - 2);
264    if (hunger >= 80) happiness = Math.max(0, happiness - 2);
265    if (hunger >= 90 && happiness <= 20) health = Math.max(0, health - 5);
266    if (health <= 0) return die();
267    if (hunger >= 70) addLog(`${petName} is hungry...`);
268    if (happiness <= 25) addLog(`${petName} feels lonely...`);
269    if (health <= 30) addLog(`${petName} doesn't look well!`);
270    cel.render();
271  }, 3000);
272}
273
274function stopTimers() {
275  if (tickTimer) clearInterval(tickTimer);
276  if (decayTimer) clearInterval(decayTimer);
277  if (excitedTimer) clearTimeout(excitedTimer);
278  tickTimer = decayTimer = excitedTimer = null;
279}
280
281function feed() {
282  if (screen !== "main") return;
283  hunger = Math.max(0, hunger - 30);
284  health = Math.min(100, health + 5);
285  addLog(`You fed ${petName}! Hunger -30`);
286  playExcited();
287}
288
289function petIt() {
290  if (screen !== "main") return;
291  happiness = Math.min(100, happiness + 25);
292  addLog(`You pet ${petName}! Happy +25`);
293  playExcited();
294}
295
296function playExcited() {
297  anim = "excited";
298  frame = 0;
299  if (excitedTimer) clearTimeout(excitedTimer);
300  excitedTimer = setTimeout(() => {
301    anim = "idle";
302    cel.render();
303  }, 2400);
304  cel.render();
305}
306
307function die() {
308  addLog(`${petName} has passed away...`);
309  screen = "dead";
310  stopTimers();
311  cel.render();
312}
313
314function restart() {
315  stopTimers();
316  pet = null;
317  petName = "";
318  selectedKind = 0;
319  nameInputFocused = true;
320  screen = "create";
321  log = [];
322  logScroll = 0;
323  showLog = false;
324  cel.render();
325}
326
327function quit() {
328  stopTimers();
329  cel.stop();
330  process.exit(0);
331}
332
333// ─── Terminal Size ──────────────────────────────────────────────
334
335const MIN_COLS = 40;
336const MIN_ROWS = 15;
337
338function termSize(): { cols: number; rows: number } {
339  return {
340    cols: process.stdout.columns || 80,
341    rows: process.stdout.rows || 24,
342  };
343}
344
345function tooSmallView() {
346  return VStack(
347    {
348      height: "100%",
349      justifyContent: "center",
350      alignItems: "center",
351      onKeyPress: (key) => {
352        if (key === "ctrl+q" || key === "ctrl+c") quit();
353      },
354    },
355    [
356      ...warningBox([
357        "  Terminal too small :(",
358        "",
359        "  Please resize to at",
360        `  least ${String(MIN_COLS).padStart(3)}×${String(MIN_ROWS).padStart(2)} chars.`,
361        "",
362        "  Ctrl+Q to quit",
363      ]),
364    ],
365  );
366}
367
368// ─── Art Helpers ────────────────────────────────────────────────
369
370function maxArtHeight(def: PetDef): number {
371  const frames = [
372    ...def.idle.happy,
373    ...def.idle.hungry,
374    ...def.excited,
375    def.dead,
376  ];
377  return Math.max(...frames.map((f) => f.length));
378}
379
380function currentArt(): string[] {
381  if (!pet) return [];
382  let lines: string[];
383  if (anim === "excited") {
384    lines = pet.excited[frame % pet.excited.length]!;
385  } else {
386    const mood = hunger > 60 || happiness < 30 ? "hungry" : "happy";
387    const frames = pet.idle[mood];
388    lines = frames[frame % frames.length]!;
389  }
390  // Pad to consistent height so buttons don't bounce
391  const target = maxArtHeight(pet);
392  while (lines.length < target) lines = [...lines, ""];
393  return lines;
394}
395
396function artColor(): "color06" | "color03" | "color05" {
397  if (anim === "excited") return "color05";
398  if (hunger > 60 || happiness < 30) return "color03";
399  return "color06";
400}
401
402// ─── Reusable Widgets ───────────────────────────────────────────
403
404function StatBar(
405  label: string,
406  value: number,
407  color: "color02" | "color03" | "color01" | "color06",
408) {
409  const w = 12;
410  const filled = Math.round((value / 100) * w);
411  return VStack({}, [
412    Text(label, { bold: true }),
413    HStack({}, [
414      Text("█", { repeat: Math.max(filled, 0), fgColor: color }),
415      Text("░", { repeat: Math.max(w - filled, 0), fgColor: "color08" }),
416      Text(` ${value}`, { fgColor: "color08" }),
417    ]),
418  ]);
419}
420
421function barColor(
422  val: number,
423  invert = false,
424): "color02" | "color03" | "color01" {
425  const v = invert ? 100 - val : val;
426  if (v > 60) return "color02";
427  if (v > 30) return "color03";
428  return "color01";
429}
430
431// ─── Create Screen ──────────────────────────────────────────────
432
433function createView() {
434  const { rows } = termSize();
435  const preview = PETS[selectedKind]!;
436  const previewArt = preview.idle.happy[frame % preview.idle.happy.length]!;
437  // Compact mode: drop art preview when height is tight
438  const showPreview = rows >= 22;
439
440  return VStack(
441    {
442      height: "100%",
443      alignItems: "center",
444      overflow: "scroll",
445      onKeyPress: (key) => {
446        if (key === "ctrl+q" || key === "ctrl+c") quit();
447        // Arrow keys to pick species (only when name input is NOT focused)
448        if (!nameInputFocused) {
449          if (key === "up") {
450            selectedKind = (selectedKind - 1 + PETS.length) % PETS.length;
451            cel.render();
452          } else if (key === "down") {
453            selectedKind = (selectedKind + 1) % PETS.length;
454            cel.render();
455          }
456        }
457      },
458    },
459    [
460      Spacer(),
461      VStack({ width: 40, padding: { x: 2 }, gap: 0 }, [
462        // Title
463        HStack({ justifyContent: "center" }, [
464          Text("~ New Pet ~", { bold: true, fgColor: "color06" }),
465        ]),
466        Divider({ fgColor: "color08" }),
467
468        // Name
469        Text("Name:", { bold: true }),
470        TextInput({
471          value: petName,
472          onChange: (v) => {
473            petName = v;
474            cel.render();
475          },
476          height: 1,
477          placeholder: Text("enter a name...", {
478            fgColor: "color08",
479          }),
480          // Controlled focus: needed to gate arrow key routing above
481          focused: nameInputFocused,
482          onFocus: () => {
483            nameInputFocused = true;
484            cel.render();
485          },
486          onBlur: () => {
487            nameInputFocused = false;
488            cel.render();
489          },
490          onKeyPress: (key) => {
491            if (key === "enter") {
492              startGame();
493              return false;
494            }
495          },
496        }),
497
498        // Species picker — wrapping chips
499        Text(""),
500        Text("Species:", { bold: true }),
501        HStack(
502          { flexWrap: "wrap", gap: 1 },
503          PETS.map((p, i) => {
504            const sel = i === selectedKind;
505            return HStack(
506              {
507                onClick: () => {
508                  selectedKind = i;
509                  cel.render();
510                },
511                focusable: false,
512              },
513              [
514                Text(sel ? ` ● ${p.kind} ` : `   ${p.kind} `, {
515                  fgColor: sel ? "color00" : undefined,
516                  bgColor: sel ? "color06" : undefined,
517                  bold: sel,
518                }),
519              ],
520            );
521          }),
522        ),
523        Text("  ↑/↓ to change", {
524          fgColor: "color08",
525          italic: true,
526        }),
527
528        // Preview (hidden when terminal is short)
529        ...(showPreview
530          ? [
531              Divider({ fgColor: "color08" }),
532              VStack(
533                { alignItems: "center" },
534                previewArt.map((ln) => Text(ln, { fgColor: "color03" })),
535              ),
536            ]
537          : []),
538
539        Divider({ fgColor: "color08" }),
540
541        // Create button — uncontrolled focus + focusStyle
542        HStack({ justifyContent: "center" }, [
543          Button(" Create Pet! ", {
544            onClick: startGame,
545            fgColor: "color02",
546            bold: true,
547            focusStyle: { bgColor: "color02", fgColor: "color00" },
548          }),
549        ]),
550
551        // Hints — wrapping for narrow terminals
552        HStack({ justifyContent: "center", flexWrap: "wrap", gap: 1 }, [
553          HStack({}, [
554            Text("Enter", { fgColor: "color08", bold: true }),
555            Text(" create", { fgColor: "color08" }),
556          ]),
557          HStack({}, [
558            Text("Tab", { fgColor: "color08", bold: true }),
559            Text(" navigate", { fgColor: "color08" }),
560          ]),
561          HStack({}, [
562            Text("Ctrl+Q", { fgColor: "color08", bold: true }),
563            Text(" quit", { fgColor: "color08" }),
564          ]),
565        ]),
566      ]),
567      Spacer(),
568    ],
569  );
570}
571
572// ─── Main Screen ────────────────────────────────────────────────
573
574function mainView() {
575  const { cols } = termSize();
576  const art = currentArt();
577  const color = artColor();
578  // Narrow mode: stack sidebar above pet pane instead of side-by-side
579  const narrow = cols < 50;
580
581  const statsPanel = VStack(
582    { ...(narrow ? {} : { width: 20 }), padding: { x: 1 }, gap: 0 },
583    [
584      ...(narrow
585        ? [
586            HStack({ gap: 2 }, [
587              StatBar("Health", health, barColor(health)),
588              StatBar("Food", 100 - hunger, barColor(hunger, true)),
589              StatBar("Happy", happiness, barColor(happiness)),
590            ]),
591          ]
592        : [
593            Text("  Stats", { bold: true, fgColor: "color08" }),
594            Divider({ char: "─", fgColor: "color08" }),
595            StatBar("Health", health, barColor(health)),
596            StatBar("Food", 100 - hunger, barColor(hunger, true)),
597            StatBar("Happy", happiness, barColor(happiness)),
598            Spacer(),
599            Divider({ char: "─", fgColor: "color08" }),
600            Text(" [F] Feed", { fgColor: "color03", bold: true }),
601            Text(" [P] Pet", { fgColor: "color05", bold: true }),
602          ]),
603    ],
604  );
605
606  const petPane = VStack(
607    { flex: 1, justifyContent: "center", alignItems: "center", gap: 1 },
608    [
609      VStack(
610        { alignItems: "center" },
611        art.map((ln) => Text(ln, { fgColor: color, bold: anim === "excited" })),
612      ),
613      Text(""),
614      HStack({ gap: 3 }, [
615        Button(" Feed ", {
616          onClick: feed,
617          fgColor: "color03",
618          bold: true,
619          focusStyle: { bgColor: "color03", fgColor: "color00" },
620        }),
621        Button(" Pet ", {
622          onClick: petIt,
623          fgColor: "color05",
624          bold: true,
625          focusStyle: { bgColor: "color05", fgColor: "color00" },
626        }),
627      ]),
628    ],
629  );
630
631  return VStack(
632    {
633      height: "100%",
634      onKeyPress: (key) => {
635        if (key === "ctrl+q" || key === "ctrl+c") quit();
636        if (key === "f") feed();
637        if (key === "p") petIt();
638        if (key === "l") {
639          showLog = !showLog;
640          if (showLog) {
641            logScroll = Math.max(0, log.length - 12);
642          }
643          cel.render();
644        }
645      },
646    },
647    [
648      // ── Header ──
649      HStack({ padding: { x: 1 } }, [
650        Text(` ${petName} `, {
651          bold: true,
652          fgColor: "color00",
653          bgColor: "color06",
654        }),
655        Text(` the ${pet!.kind} `, { fgColor: "color08" }),
656        Spacer(),
657        Text("[L]", { fgColor: "color08", bold: true }),
658        Text("og ", { fgColor: "color08" }),
659        Text("[Q]", { fgColor: "color08", bold: true }),
660        Text("uit ", { fgColor: "color08" }),
661      ]),
662      Divider({ char: "═", fgColor: "color08" }),
663
664      // ── Body ──
665      ...(narrow
666        ? [
667            // Narrow: stats bar on top, pet below
668            statsPanel,
669            Divider({ char: "─", fgColor: "color08" }),
670            petPane,
671          ]
672        : [
673            // Wide: sidebar | pet side-by-side
674            HStack({ flex: 1 }, [
675              statsPanel,
676              VDivider({ fgColor: "color08" }),
677              petPane,
678            ]),
679          ]),
680    ],
681  );
682}
683
684// ─── Log Modal (Layer) ──────────────────────────────────────────
685
686function logView() {
687  const { cols, rows } = termSize();
688  const closeLog = () => {
689    showLog = false;
690    cel.render();
691  };
692
693  // Adapt modal size to terminal
694  const modalW = Math.min(60, cols - 4);
695  const modalH = Math.min(14, rows - 4);
696  const borderW = modalW - 2;
697
698  return VStack(
699    {
700      height: "100%",
701      justifyContent: "center",
702      alignItems: "center",
703      onKeyPress: (key) => {
704        if (key === "l" || key === "escape") closeLog();
705      },
706    },
707    [
708      // Top border
709      HStack({ bgColor: "color08", fgColor: "color07" }, [
710        Text("╔"),
711        Text("═", { repeat: borderW }),
712        Text("╗"),
713      ]),
714
715      VStack(
716        {
717          width: modalW,
718          height: modalH,
719          padding: { x: 1 },
720          bgColor: "color08",
721          fgColor: "color07",
722        },
723        [
724          // Header row
725          HStack({}, [
726            Text(" Activity Log ", { bold: true, fgColor: "color06" }),
727            VStack({ flex: 1 }, [Text(" ", { repeat: "fill" })]),
728            HStack({ onClick: closeLog, focusable: false }, [
729              Text(" [x] ", { fgColor: "color01", bold: true }),
730            ]),
731          ]),
732          Text("─", { repeat: "fill", fgColor: "color00" }),
733
734          // Scrollable entries
735          VStack(
736            {
737              flex: 1,
738              overflow: "scroll",
739              scrollbar: true,
740              scrollOffset: logScroll,
741              onScroll: (off) => {
742                logScroll = off;
743                cel.render();
744              },
745            },
746            (() => {
747              if (log.length === 0) {
748                return [
749                  Text(" No activity yet.", {
750                    fgColor: "color08",
751                    italic: true,
752                  }),
753                ];
754              }
755              return log.map((entry) => {
756                let fg:
757                  | "color03"
758                  | "color05"
759                  | "color01"
760                  | "color02"
761                  | "color09"
762                  | undefined;
763                if (entry.includes("born")) fg = "color02";
764                else if (entry.includes("fed") || entry.includes("Feed"))
765                  fg = "color03";
766                else if (entry.includes("pet ") || entry.includes("Happy"))
767                  fg = "color05";
768                else if (entry.includes("hungry") || entry.includes("lonely"))
769                  fg = "color09";
770                else if (entry.includes("passed") || entry.includes("well"))
771                  fg = "color01";
772                return Text(entry, { fgColor: fg });
773              });
774            })(),
775          ),
776
777          Text("─", { repeat: "fill", fgColor: "color00" }),
778          Text(" Scroll: mouse wheel  Close: [L] or Esc", {
779            fgColor: "color00",
780            italic: true,
781          }),
782        ],
783      ),
784
785      // Bottom border
786      HStack({ bgColor: "color08", fgColor: "color07" }, [
787        Text("╚"),
788        Text("═", { repeat: borderW }),
789        Text("╝"),
790      ]),
791    ],
792  );
793}
794
795// ─── Dead Screen ────────────────────────────────────────────────
796
797function deadView() {
798  const art = pet?.dead ?? [];
799  return VStack(
800    {
801      height: "100%",
802      alignItems: "center",
803      overflow: "scroll",
804      onKeyPress: (key) => {
805        if (key === "ctrl+q" || key === "ctrl+c") quit();
806        if (key === "l") {
807          showLog = !showLog;
808          cel.render();
809        }
810      },
811    },
812    [
813      Spacer(),
814      Text("╔═══════════════════════╗", { fgColor: "color08" }),
815      Text("║                       ║", { fgColor: "color08" }),
816      Text("║      R . I . P .      ║", { fgColor: "color01", bold: true }),
817      Text("║                       ║", { fgColor: "color08" }),
818      Text("╚═══════════════════════╝", { fgColor: "color08" }),
819      Text(""),
820      ...art.map((ln) => Text(ln, { fgColor: "color08" })),
821      Text(""),
822      Text(`${petName} has crossed the rainbow bridge.`, {
823        fgColor: "color08",
824        italic: true,
825      }),
826      Text(""),
827      HStack({ gap: 3 }, [
828        Button(" New Pet ", {
829          onClick: restart,
830          fgColor: "color02",
831          bold: true,
832          focusStyle: { bgColor: "color02", fgColor: "color00" },
833        }),
834        Button(" View Log ", {
835          onClick: () => {
836            showLog = !showLog;
837            cel.render();
838          },
839          fgColor: "color06",
840          bold: true,
841          focusStyle: { bgColor: "color06", fgColor: "color00" },
842        }),
843      ]),
844      HStack({}, [
845        Text("Ctrl+Q", { fgColor: "color08", bold: true }),
846        Text(" quit", { fgColor: "color08" }),
847      ]),
848      Spacer(),
849    ],
850  );
851}
852
853// ─── Viewport ───────────────────────────────────────────────────
854
855cel.init(new ProcessTerminal());
856
857cel.viewport(() => {
858  const { cols, rows } = termSize();
859  if (cols < MIN_COLS || rows < MIN_ROWS) return tooSmallView();
860
861  let base: Node;
862  if (screen === "create") base = createView();
863  else if (screen === "main") base = mainView();
864  else base = deadView();
865
866  if (showLog) return [base, logView()];
867  return base;
868});