xonecas.io
5875
Os

ollama-space-molt-player / files

ollama-space-molt-player / packages / tui / tests / manual / component-previews.tsx

6.9 KB
1#!/usr/bin/env bun
2
3import React from "react";
4import { Box, Text } from "ink";
5import { runTests, createMockData } from "./test-harness.tsx";
6import { colors, boxChars, ascii } from "../../src/theme.ts";
7
8function HeaderPreview({
9	tick,
10	loopState,
11	width,
12}: {
13	tick: number;
14	loopState: string;
15	width: number;
16}) {
17	const statusColor =
18		loopState === "error" ? colors.error : loopState === "idle" ? colors.inactive : colors.active;
19
20	return (
21		<Box borderStyle="double" borderColor={colors.primary} width={width} padding={1}>
22			<Box flexDirection="row" justifyContent="space-between" width="100%">
23				<Text bold color={colors.primary}>
24					{ascii.diamond} SPACEMOLT TERMINAL
25				</Text>
26				<Text>
27					<Text color={colors.textDim}>TICK:</Text>{" "}
28					<Text bold color={colors.accent}>
29						{tick}
30					</Text>
31				</Text>
32				<Text>
33					<Text color={colors.textDim}>STATUS:</Text>{" "}
34					<Text bold color={statusColor}>
35						{loopState.toUpperCase()}
36					</Text>
37				</Text>
38			</Box>
39		</Box>
40	);
41}
42
43/**
44 * Player Actions Panel Preview
45 */
46function PlayerActionsPanelPreview({ width, height }: { width: number; height: number }) {
47	return (
48		<Box
49			borderStyle="single"
50			borderColor={colors.border}
51			width={width}
52			height={height}
53			flexDirection="column"
54		>
55			<Box padding={1} flexDirection="column">
56				<Text bold color={colors.accent}>
57					{ascii.diamond} PLAYER ACTIONS & RESPONSES
58				</Text>
59				<Box marginTop={1} flexDirection="column">
60					<Text wrap="truncate-end">
61						<Text color={colors.textDim}>T:1336 {ascii.arrow}</Text>{" "}
62						<Text color={colors.info}>travel sector-7</Text>
63					</Text>
64					<Text wrap="truncate-end">
65						<Text color={colors.success}>{ascii.bullet}</Text> Travel initiated. ETA: 2 ticks
66					</Text>
67				</Box>
68				<Box marginTop={1} flexDirection="column">
69					<Text>
70						<Text color={colors.textDim}>T:1335 {ascii.arrow}</Text>{" "}
71						<Text color={colors.info}>scan nearby</Text>
72					</Text>
73					<Text>
74						<Text color={colors.info}>{ascii.bullet}</Text> Scan complete. 3 ships detected
75					</Text>
76				</Box>
77				<Box marginTop={1} flexDirection="column">
78					<Text>
79						<Text color={colors.textDim}>T:1334 {ascii.arrow}</Text>{" "}
80						<Text color={colors.info}>mine asteroid</Text>
81					</Text>
82					<Text>
83						<Text color={colors.error}>{ascii.bullet}</Text> Error: No mining equipment detected
84					</Text>
85				</Box>
86			</Box>
87		</Box>
88	);
89}
90
91function SocialPanelPreview({ width, height }: { width: number; height: number }) {
92	return (
93		<Box
94			borderStyle="single"
95			borderColor={colors.border}
96			width={width}
97			height={height}
98			flexDirection="column"
99		>
100			<Box padding={1} flexDirection="column">
101				<Text bold color={colors.accent}>
102					{ascii.diamond} SOCIAL [CHAT | FORUM]
103				</Text>
104				<Box marginTop={1} flexDirection="column">
105					<Text color={colors.textDim}>{boxChars.horizontal.repeat(5)} CHAT</Text>
106					<Text>
107						<Text color={colors.warning}>local</Text> | <Text color={colors.info}>Trader_01</Text>:
108						Anyone selling fuel?
109					</Text>
110					<Text>
111						<Text color={colors.info}>system</Text> | <Text dimColor>SERVER</Text>: Player
112						CaptainTest entered
113					</Text>
114				</Box>
115				<Box marginTop={1} flexDirection="column">
116					<Text color={colors.textDim}>{boxChars.horizontal.repeat(5)} FORUM</Text>
117					<Text>
118						{ascii.star} <Text color={colors.highlight}>Welcome to SpaceMolt!</Text>{" "}
119						<Text dimColor>(42 replies)</Text>
120					</Text>
121					<Text>
122						{ascii.star} <Text color={colors.highlight}>Best trade routes</Text>{" "}
123						<Text dimColor>(15 replies)</Text>
124					</Text>
125				</Box>
126			</Box>
127		</Box>
128	);
129}
130
131/**
132 * Ship Status Sidebar Preview
133 */
134function ShipStatusPreview({ width, height }: { width: number; height: number }) {
135	return (
136		<Box
137			borderStyle="single"
138			borderColor={colors.border}
139			width={width}
140			height={height}
141			flexDirection="column"
142		>
143			<Box padding={1} flexDirection="column">
144				<Text bold color={colors.info}>
145					{ascii.star} SHIP STATUS
146				</Text>
147				<Box marginTop={1} flexDirection="column">
148					<Text>
149						<Text color={colors.textDim}>Name:</Text> SS TestRunner
150					</Text>
151					<Text>
152						<Text color={colors.textDim}>Health:</Text> <Text color={colors.success}>85%</Text>{" "}
153						{ascii.square.repeat(8)}
154					</Text>
155					<Text>
156						<Text color={colors.textDim}>Fuel:</Text> <Text color={colors.warning}>42%</Text>{" "}
157						{ascii.square.repeat(4)}
158					</Text>
159					<Text>
160						<Text color={colors.textDim}>Credits:</Text> 10,500 {ascii.diamond}
161					</Text>
162				</Box>
163				<Box marginTop={1} flexDirection="column">
164					<Text color={colors.textDim}>{boxChars.horizontal.repeat(10)}</Text>
165					<Text>
166						<Text color={colors.textDim}>Location:</Text>
167					</Text>
168					<Text dimColor>Alpha Centauri</Text>
169					<Text dimColor>Station Prime</Text>
170				</Box>
171			</Box>
172		</Box>
173	);
174}
175
176/**
177 * Server Messages Sidebar Preview
178 */
179function ServerMessagesPreview({ width, height }: { width: number; height: number }) {
180	return (
181		<Box
182			borderStyle="single"
183			borderColor={colors.border}
184			width={width}
185			height={height}
186			flexDirection="column"
187		>
188			<Box padding={1} flexDirection="column">
189				<Text bold color={colors.warning}>
190					{ascii.triangle} SERVER MESSAGES
191				</Text>
192				<Box marginTop={1} flexDirection="column">
193					<Text>
194						<Text color={colors.error}>combat</Text> {ascii.bullet} Enemy ship detected
195					</Text>
196					<Text>
197						<Text color={colors.info}>trade</Text> {ascii.bullet} Market prices updated
198					</Text>
199					<Text>
200						<Text color={colors.success}>system</Text> {ascii.bullet} Jump gate available
201					</Text>
202					<Text>
203						<Text color={colors.warning}>alert</Text> {ascii.bullet} Low fuel warning
204					</Text>
205				</Box>
206			</Box>
207		</Box>
208	);
209}
210
211// Run component preview tests
212runTests("Component Previews", [
213	{
214		name: "Header - Standard",
215		description: "Header at typical width showing active state",
216		component: <HeaderPreview tick={1337} loopState="processing_tick" width={120} />,
217	},
218	{
219		name: "Header - Compact",
220		description: "Header at minimum width",
221		component: <HeaderPreview tick={42} loopState="idle" width={80} />,
222	},
223	{
224		name: "Header - Error State",
225		description: "Header showing error state",
226		component: <HeaderPreview tick={999} loopState="error" width={100} />,
227	},
228	{
229		name: "Player Actions Panel - Standard",
230		description: "Player actions with success, info, and error responses",
231		component: <PlayerActionsPanelPreview width={60} height={15} />,
232	},
233	{
234		name: "Social Panel - Standard",
235		description: "Chat and forum messages combined",
236		component: <SocialPanelPreview width={60} height={15} />,
237	},
238	{
239		name: "Ship Status Sidebar - Standard",
240		description: "Ship health, fuel, credits, and location",
241		component: <ShipStatusPreview width={30} height={15} />,
242	},
243	{
244		name: "Server Messages Sidebar - Standard",
245		description: "Categorized server messages",
246		component: <ServerMessagesPreview width={30} height={12} />,
247	},
248]);