xonecas.io
5875
Os

ollama-space-molt-player / commit c75b330

refactor: restructure TUI modules with modular panels and utilities

xonecas2026-02-02 c75b330d379399948c665d117ce50e9341d7e2d4 parent 076469f

18 files changed

This diff is too big to show in full. The first 1000 lines are below, and every file is listed with its counts.

src/tui-screenshot.ts+0−169
@@ -1,169 +0,0 @@
1-// Simple script to capture TUI state to a file for debugging
2-
3-import { SpaceMoltClient } from "../client/src/client";
4-import type {
5- Base,
6- LoggedInPayload,
7- Player,
8- POI,
9- Ship,
10- StateUpdatePayload,
11- System,
12- WelcomePayload,
13-} from "../client/src/types";
14-import { config } from "./config";
15-import { MemoryStore } from "./memory";
16-import { renderLocationPanel } from "./tui/panels/location";
17-import { renderPlayerShipPanel } from "./tui/panels/player-ship";
18-import { renderTacticalPanel } from "./tui/panels/tactical";
19-import { renderWorldInfoPanel } from "./tui/panels/world-info";
20-import type { Credentials } from "./types";
21-
22-const client = new SpaceMoltClient({
23- url: config.spacemoltUrl,
24- debug: false,
25- reconnect: false,
26-});
27-
28-const memory = new MemoryStore(config.memoryPath);
29-
30-type WorldSnapshot = {
31- system?: System | null;
32- poi?: POI | null;
33- pois?: POI[];
34- base?: Base | null;
35-};
36-
37-let credentials: Credentials | null = null;
38-let cachedPlayer: Player | null = null;
39-let cachedShip: Ship | null = null;
40-const worldSnapshot: WorldSnapshot = {};
41-
42-function loadCredentials(): Credentials | null {
43- try {
44- return memory.getCredentials();
45- } catch (error) {
46- console.log(`Failed to load credentials: ${(error as Error).message}`);
47- process.exit(1);
48- }
49-}
50-
51-function dumpTuiState() {
52- console.log(`\n${"=".repeat(80)}`);
53- console.log("TUI STATE DUMP");
54- console.log("=".repeat(80));
55- console.log("\n--- CACHED DATA ---");
56- console.log("Player:", JSON.stringify(cachedPlayer, null, 2));
57- console.log("Ship:", JSON.stringify(cachedShip, null, 2));
58- console.log("World Snapshot:", JSON.stringify(worldSnapshot, null, 2));
59-
60- console.log("\n--- PANEL RENDERS ---");
61- console.log("\n[Player/Ship Panel]");
62- console.log(
63- renderPlayerShipPanel({
64- player: cachedPlayer,
65- ship: cachedShip,
66- personality: undefined,
67- tick: 0,
68- }),
69- );
70-
71- console.log("\n[World Info Panel]");
72- console.log(
73- renderWorldInfoPanel({
74- base: worldSnapshot.base ?? null,
75- }),
76- );
77-
78- console.log("\n[Location Panel]");
79- console.log(
80- renderLocationPanel({
81- player: cachedPlayer,
82- system: worldSnapshot.system ?? null,
83- poi: worldSnapshot.poi ?? null,
84- pois: worldSnapshot.pois ?? [],
85- traveling: false,
86- travelTarget: null,
87- jumping: false,
88- jumpTarget: null,
89- }),
90- );
91-
92- console.log("\n[Tactical Panel]");
93- console.log(
94- renderTacticalPanel({
95- inCombat: false,
96- combatTarget: undefined,
97- nearby: [],
98- }),
99- );
100-
101- console.log(`\n${"=".repeat(80)}`);
102-}
103-
104-client.on<WelcomePayload>("welcome", async (data) => {
105- console.log(`Connected to SpaceMolt v${data.version}`);
106-
107- if (credentials) {
108- console.log(`Logging in as ${credentials.username}`);
109- client.login(credentials.username, credentials.token);
110- } else {
111- console.log("No credentials found");
112- process.exit(1);
113- }
114-});
115-
116-client.on<LoggedInPayload>("logged_in", (data) => {
117- console.log(`Logged in as ${data.player.username}`);
118-
119- cachedPlayer = data.player;
120- cachedShip = data.ship;
121- worldSnapshot.system = data.system;
122- worldSnapshot.poi = data.poi;
123-
124- client.getSystem();
125- client.getPOI();
126- if (data.player.docked_at_base) {
127- client.getBase();
128- }
129-
130- // Wait a bit for data to arrive, then dump state
131- setTimeout(() => {
132- dumpTuiState();
133- process.exit(0);
134- }, 3000);
135-});
136-
137-client.on<StateUpdatePayload>("state_update", (data) => {
138- if (data.player) {
139- cachedPlayer = data.player;
140- }
141- if (data.ship) {
142- cachedShip = data.ship;
143- }
144-});
145-
146-client.on("ok", (data: Record<string, unknown>) => {
147- if (data.system && typeof data.system === "object") {
148- worldSnapshot.system = data.system;
149- }
150- if (Array.isArray(data.pois)) {
151- worldSnapshot.pois = data.pois;
152- }
153- if (data.poi && typeof data.poi === "object") {
154- worldSnapshot.poi = data.poi;
155- }
156- if (data.base && typeof data.base === "object") {
157- worldSnapshot.base = data.base;
158- }
159-});
160-
161-credentials = loadCredentials();
162-
163-if (!credentials) {
164- console.log("No credentials found in DB. Please run the main app first.");
165- process.exit(1);
166-}
167-
168-console.log("Connecting to SpaceMolt...");
169-await client.connect();
src/tui/colors.ts+0−63
@@ -1,63 +0,0 @@
1-// Color scheme and theme configuration for TUI
2-
3-export const COLORS = {
4- // Panel styling
5- PANEL_BORDER_ACTIVE: "cyan",
6- PANEL_BORDER_INACTIVE: "blue",
7- PANEL_TITLE: "cyan",
8- PANEL_LABEL: "yellow",
9- PANEL_VALUE: "white",
10-
11- // Status colors
12- STATUS_SAFE: "green",
13- STATUS_WARNING: "yellow",
14- STATUS_DANGER: "red",
15- STATUS_INACTIVE: "gray",
16-
17- // Message categories
18- MSG_SUCCESS: "green",
19- MSG_ERROR: "red",
20- MSG_INFO: "white",
21- MSG_AI: "cyan",
22- MSG_CHAT: "yellow",
23- MSG_TIMESTAMP: "gray",
24-
25- // Progress bars
26- PROGRESS_HEALTHY: "green",
27- PROGRESS_WARNING: "yellow",
28- PROGRESS_CRITICAL: "red",
29-
30- // Background
31- BG_DEFAULT: "black",
32- BG_STATUS_BAR: "black",
33-} as const;
34-
35-export const THRESHOLDS = {
36- CRITICAL: 30, // % - below this is critical (red)
37- WARNING: 60, // % - below this is warning (yellow)
38- FUEL_LOW: 25, // % - fuel warning threshold
39-} as const;
40-
41-export function applyColor(text: string, color: string): string {
42- return `{${color}-fg}${text}{/${color}-fg}`;
43-}
44-
45-export function applyBold(text: string): string {
46- return `{bold}${text}{/bold}`;
47-}
48-
49-export function applyBg(text: string, color: string): string {
50- return `{${color}-bg}${text}{/${color}-bg}`;
51-}
52-
53-export function getProgressColor(percentage: number): string {
54- if (percentage < THRESHOLDS.CRITICAL) return COLORS.PROGRESS_CRITICAL;
55- if (percentage < THRESHOLDS.WARNING) return COLORS.PROGRESS_WARNING;
56- return COLORS.PROGRESS_HEALTHY;
57-}
58-
59-export function getResourceColor(current: number, max: number): string {
60- if (max <= 0) return COLORS.PROGRESS_CRITICAL;
61- const percentage = (current / max) * 100;
62- return getProgressColor(percentage);
63-}
src/tui/formatters.ts+44−39
@@ -8,7 +8,8 @@ import type {
88 ScanResultPayload,
99 WelcomePayload,
1010 } from "../../client/src/types";
11-import { applyColor, COLORS } from "./colors";
11+import { PALETTE, THEME } from "./theme";
12+import { applyColor } from "./widgets";
1213
1314 export type LogCategory = "game" | "ai" | "combat" | "chat" | "system";
1415
@@ -43,7 +44,8 @@ function formatWithTimestamp(
4344 tick?: number,
4445 ): FormattedMessage {
4546 const timestamp = getTimestamp(tick);
46- const ts = applyColor(timestamp, COLORS.MSG_TIMESTAMP);
47+ // Dim timestamp
48+ const ts = applyColor(timestamp, PALETTE.GRAY);
4749 return {
4850 text: `${ts} ${message}`,
4951 category,
@@ -59,13 +61,13 @@ export function formatWelcome(
5961 ): FormattedMessage {
6062 const msg = applyColor(
6163 `Connected to SpaceMolt v${data.version} (tick rate: ${data.tick_rate}s)`,
62- COLORS.MSG_SUCCESS,
64+ THEME.MSG_SYSTEM,
6365 );
6466 return formatWithTimestamp(msg, "system", tick);
6567 }
6668
6769 export function formatMotd(motd: string, tick?: number): FormattedMessage {
68- const msg = applyColor(`MOTD: ${motd}`, COLORS.MSG_CHAT);
70+ const msg = applyColor(`MOTD: ${motd}`, THEME.MSG_GAME);
6971 return formatWithTimestamp(msg, "system", tick);
7072 }
7173
@@ -76,7 +78,7 @@ export function formatRegistered(
7678 ): FormattedMessage {
7779 const msg = applyColor(
7880 `Registration successful - credentials saved`,
79- COLORS.MSG_SUCCESS,
81+ THEME.SAFE,
8082 );
8183 return formatWithTimestamp(msg, "system", tick);
8284 }
@@ -88,7 +90,7 @@ export function formatLoggedIn(
8890 ): FormattedMessage {
8991 const msg = applyColor(
9092 `Logged in as ${data.player.username} (${data.player.empire})`,
91- COLORS.MSG_SUCCESS,
93+ THEME.SAFE,
9294 );
9395 return formatWithTimestamp(msg, "game", tick);
9496 }
@@ -100,7 +102,7 @@ export function formatError(
100102 ): FormattedMessage {
101103 const msg = applyColor(
102104 `Error [${data.code}]: ${data.message}`,
103- COLORS.MSG_ERROR,
105+ THEME.MSG_ERROR,
104106 );
105107 return formatWithTimestamp(msg, "system", tick);
106108 }
@@ -110,10 +112,12 @@ export function formatChatMessage(
110112 data: ChatMessage,
111113 tick?: number,
112114 ): FormattedMessage {
113- const msg = applyColor(
114- `[${data.channel}] ${data.sender}: ${data.content}`,
115- COLORS.MSG_CHAT,
116- );
115+ const channelColor =
116+ data.channel === "global" ? PALETTE.ORANGE : PALETTE.WHITE;
117+ const content = applyColor(data.content, channelColor);
118+ const sender = applyColor(data.sender, PALETTE.AMBER);
119+
120+ const msg = `[${data.channel}] ${sender}: ${content}`;
117121 return formatWithTimestamp(msg, "chat", tick);
118122 }
119123
@@ -143,7 +147,7 @@ export function formatScanResult(
143147 }
144148 }
145149
146- const msg = `Scan result: ${parts.join(", ")}`;
150+ const msg = applyColor(`Scan result: ${parts.join(", ")}`, PALETTE.MOSS);
147151 return formatWithTimestamp(msg, "game", tick);
148152 }
149153
@@ -154,7 +158,7 @@ export function formatMiningYield(
154158 ): FormattedMessage {
155159 const resource = String(data.resource_id ?? "ore");
156160 const quantity = Number(data.quantity ?? 0);
157- const msg = applyColor(`Mined ${quantity}x ${resource}`, COLORS.MSG_SUCCESS);
161+ const msg = applyColor(`Mined ${quantity}x ${resource}`, THEME.MSG_PLAYER);
158162 return formatWithTimestamp(msg, "game", tick);
159163 }
160164
@@ -165,19 +169,25 @@ export function formatOk(
165169 tick?: number,
166170 ): FormattedMessage {
167171 const action = String(data.action ?? "");
172+ let color = THEME.MSG_GAME;
173+
174+ // Highlight player successful actions
175+ if (["mine", "travel", "jump", "dock", "buy", "sell"].includes(action)) {
176+ color = THEME.MSG_PLAYER;
177+ }
168178
169179 switch (action) {
170180 case "travel": {
171181 const targetId = String(
172182 data.target_poi ?? context?.travelTarget ?? "unknown",
173183 );
174- const msg = applyColor(`Traveling to ${targetId}`, COLORS.MSG_SUCCESS);
184+ const msg = applyColor(`Traveling to ${targetId}`, color);
175185 return formatWithTimestamp(msg, "game", tick);
176186 }
177187
178188 case "arrived": {
179189 const poiId = String(data.poi_id ?? "destination");
180- const msg = applyColor(`Arrived at ${poiId}`, COLORS.MSG_SUCCESS);
190+ const msg = applyColor(`Arrived at ${poiId}`, THEME.SAFE);
181191 return formatWithTimestamp(msg, "game", tick);
182192 }
183193
@@ -185,35 +195,29 @@ export function formatOk(
185195 const targetSystem = String(
186196 data.target_system ?? context?.jumpTarget ?? "unknown",
187197 );
188- const msg = applyColor(
189- `Jumping to ${targetSystem} system`,
190- COLORS.MSG_SUCCESS,
191- );
198+ const msg = applyColor(`Jumping to ${targetSystem} system`, color);
192199 return formatWithTimestamp(msg, "game", tick);
193200 }
194201
195202 case "jumped": {
196203 const systemId = String(data.system_id ?? "new system");
197- const msg = applyColor(
198- `Jumped to ${systemId} system`,
199- COLORS.MSG_SUCCESS,
200- );
204+ const msg = applyColor(`Jumped to ${systemId} system`, THEME.SAFE);
201205 return formatWithTimestamp(msg, "game", tick);
202206 }
203207
204208 case "dock": {
205209 const baseId = String(data.base_id ?? "base");
206- const msg = applyColor(`Docked at ${baseId}`, COLORS.MSG_SUCCESS);
210+ const msg = applyColor(`Docked at ${baseId}`, THEME.SAFE);
207211 return formatWithTimestamp(msg, "game", tick);
208212 }
209213
210214 case "undock": {
211- const msg = applyColor("Undocked from base", COLORS.MSG_SUCCESS);
215+ const msg = applyColor("Undocked from base", color);
212216 return formatWithTimestamp(msg, "game", tick);
213217 }
214218
215219 case "mine": {
216- const msg = applyColor("Mining...", COLORS.MSG_INFO);
220+ const msg = applyColor("Mining...", color);
217221 return formatWithTimestamp(msg, "game", tick);
218222 }
219223
@@ -223,7 +227,7 @@ export function formatOk(
223227 const cost = Number(data.cost ?? 0);
224228 const msg = applyColor(
225229 `Bought ${quantity}x ${itemId} for ${cost} credits`,
226- COLORS.MSG_SUCCESS,
230+ color,
227231 );
228232 return formatWithTimestamp(msg, "game", tick);
229233 }
@@ -234,7 +238,7 @@ export function formatOk(
234238 const revenue = Number(data.revenue ?? 0);
235239 const msg = applyColor(
236240 `Sold ${quantity}x ${itemId} for ${revenue} credits`,
237- COLORS.MSG_SUCCESS,
241+ color,
238242 );
239243 return formatWithTimestamp(msg, "game", tick);
240244 }
@@ -243,7 +247,7 @@ export function formatOk(
243247 const cost = Number(data.cost ?? 0);
244248 const msg = applyColor(
245249 `Repaired ship (cost: ${cost} credits)`,
246- COLORS.MSG_SUCCESS,
250+ THEME.SAFE,
247251 );
248252 return formatWithTimestamp(msg, "game", tick);
249253 }
@@ -252,7 +256,7 @@ export function formatOk(
252256 const cost = Number(data.cost ?? 0);
253257 const msg = applyColor(
254258 `Refueled ship (cost: ${cost} credits)`,
255- COLORS.MSG_SUCCESS,
259+ THEME.SAFE,
256260 );
257261 return formatWithTimestamp(msg, "game", tick);
258262 }
@@ -262,7 +266,7 @@ export function formatOk(
262266 const damage = Number(data.damage ?? 0);
263267 const msg = applyColor(
264268 `Attacked ${targetId}${damage > 0 ? ` (${damage} damage)` : ""}`,
265- COLORS.STATUS_DANGER,
269+ THEME.DANGER,
266270 );
267271 return formatWithTimestamp(msg, "combat", tick);
268272 }
@@ -305,9 +309,7 @@ export function formatAiThinking(
305309 thinking: string,
306310 tick?: number,
307311 ): FormattedMessage {
308- const truncated =
309- thinking.length > 200 ? `${thinking.slice(0, 200)}...` : thinking;
310- const msg = applyColor(`[AI Thinking] ${truncated}`, COLORS.MSG_AI);
312+ const msg = applyColor(`[Thinking] ${thinking}`, THEME.MSG_AI);
311313 return formatWithTimestamp(msg, "ai", tick);
312314 }
313315
@@ -322,7 +324,7 @@ export function formatAiAction(
322324 .map(([k, v]) => `${k}=${v}`)
323325 .join(", ")})`
324326 : "";
325- const msg = applyColor(`[AI Action] ${action}${argsStr}`, COLORS.MSG_AI);
327+ const msg = applyColor(`>> ACTION: ${action}${argsStr}`, PALETTE.AMBER);
326328 return formatWithTimestamp(msg, "ai", tick);
327329 }
328330
@@ -330,7 +332,7 @@ export function formatAiMission(
330332 mission: string,
331333 tick?: number,
332334 ): FormattedMessage {
333- const msg = applyColor(`[AI Mission] ${mission}`, COLORS.MSG_AI);
335+ const msg = applyColor(`[Mission Update] ${mission}`, THEME.MSG_AI);
334336 return formatWithTimestamp(msg, "ai", tick);
335337 }
336338
@@ -347,7 +349,10 @@ export function formatCombatEnd(
347349 tick?: number,
348350 ): FormattedMessage {
349351 const result = victory ? "Victory" : "Defeated";
350- const msg = applyColor(`Combat ended - ${result}`, COLORS.STATUS_DANGER);
352+ const msg = applyColor(
353+ `Combat ended - ${result}`,
354+ victory ? THEME.SAFE : THEME.DANGER,
355+ );
351356 return formatWithTimestamp(msg, "combat", tick);
352357 }
353358
@@ -361,7 +366,7 @@ export function formatDamageTaken(
361366 ): FormattedMessage {
362367 const msg = applyColor(
363368 `Took ${damage} damage (Hull: ${hull}/${maxHull}, Shield: ${shield}/${maxShield})`,
364- COLORS.STATUS_DANGER,
369+ THEME.DANGER,
365370 );
366371 return formatWithTimestamp(msg, "combat", tick);
367372 }
@@ -373,7 +378,7 @@ export function formatDamageDealt(
373378 ): FormattedMessage {
374379 const msg = applyColor(
375380 `Dealt ${damage} damage to ${targetId}`,
376- COLORS.STATUS_DANGER,
381+ PALETTE.ORANGE, // High visibility for damage dealt
377382 );
378383 return formatWithTimestamp(msg, "combat", tick);
379384 }
src/tui/index.ts+113−133
@@ -4,18 +4,21 @@ import blessed from "blessed";
44 import type { Base, Player, POI, Ship, System } from "../../client/src/types";
55 import type { PersonalityType } from "../actions";
66 import type { AlignmentType } from "../types";
7-import { applyColor, COLORS, THRESHOLDS } from "./colors";
87 import type { FormattedMessage } from "./formatters";
98 import { computeLayout, createBoxOptions } from "./layout";
9+import { renderActionResultPanel } from "./panels/action-result";
1010 import { renderContextPanel } from "./panels/context";
11-import { type LocationData, renderLocationPanel } from "./panels/location";
11+// Panels
1212 import { LogPanel, type LogTab } from "./panels/log";
1313 import {
14- type PlayerShipData,
15- renderPlayerShipPanel,
16-} from "./panels/player-ship";
14+ type NavigationData,
15+ renderNavigationPanel,
16+} from "./panels/navigation";
17+import { type PlayerData, renderPlayerPanel } from "./panels/player";
18+import { renderShipPanel, type ShipData } from "./panels/ship";
1719 import { renderTacticalPanel, type TacticalData } from "./panels/tactical";
18-import { renderWorldInfoPanel, type WorldInfoData } from "./panels/world-info";
20+import { PALETTE, THEME } from "./theme";
21+import { applyColor } from "./widgets";
1922
2023 export interface ContextWarnings {
2124 repetition?: {
@@ -46,7 +49,12 @@ export interface TuiUpdateData {
4649 poi?: POI | null;
4750 base?: Base | null;
4851 pois?: Array<{ id: string; name: string; type?: string }>;
49- nearby?: Array<{ player_id?: string; username?: string }>;
52+ nearby?: Array<{
53+ player_id?: string;
54+ username?: string;
55+ ship_class?: string;
56+ faction_tag?: string;
57+ }>;
5058 alignment?: AlignmentType;
5159 personality?: PersonalityType;
5260 tick?: number;
@@ -69,14 +77,21 @@ export interface TuiUpdateData {
6977
7078 export class Tui {
7179 private screen: blessed.Widgets.Screen;
72- private playerShipBox: blessed.Widgets.BoxElement;
73- private worldInfoBox: blessed.Widgets.BoxElement;
80+
81+ // Panel Boxes
82+ private playerBox: blessed.Widgets.BoxElement;
83+ private shipBox: blessed.Widgets.BoxElement;
84+ private navigationBox: blessed.Widgets.BoxElement;
85+
7486 private logPanel: LogPanel;
75- private locationBox: blessed.Widgets.BoxElement;
87+ private actionResultBox: blessed.Widgets.BoxElement;
88+
7689 private tacticalBox: blessed.Widgets.BoxElement;
7790 private contextBox: blessed.Widgets.BoxElement;
91+
7892 private statusBar: blessed.Widgets.BoxElement;
7993 private debugBox: blessed.Widgets.BoxElement | null;
94+
8095 private exitHandler: (() => void) | null = null;
8196 private debugEnabled: boolean;
8297
@@ -88,7 +103,7 @@ export class Tui {
88103 this.screen = blessed.screen({
89104 smartCSR: true,
90105 title: "SpaceMolt Ollama Player",
91- fullUnicode: false,
106+ fullUnicode: true, // Enabled for symbols
92107 terminal: resolveTerminal(),
93108 });
94109
@@ -103,50 +118,42 @@ export class Tui {
103118
104119 const layout = computeLayout(termWidth, termHeight);
105120
106- // Create panels
107- this.playerShipBox = blessed.box(
108- createBoxOptions(
109- layout.playerShip,
110- "Player/Ship",
111- COLORS.PANEL_BORDER_INACTIVE,
112- ),
121+ // -- LEFT COLUMN --
122+ this.playerBox = blessed.box(
123+ createBoxOptions(layout.player, " PLAYER ", THEME.BORDER_INACTIVE),
124+ );
125+ this.screen.append(this.playerBox);
126+
127+ this.shipBox = blessed.box(
128+ createBoxOptions(layout.ship, " SHIP ", THEME.BORDER_INACTIVE),
113129 );
114- this.screen.append(this.playerShipBox);
115-
116- this.worldInfoBox = blessed.box(
117- createBoxOptions(
118- layout.worldInfo,
119- "World Info",
120- COLORS.PANEL_BORDER_INACTIVE,
121- ),
130+ this.screen.append(this.shipBox);
131+
132+ this.navigationBox = blessed.box(
133+ createBoxOptions(layout.navigation, " NAV ", THEME.BORDER_INACTIVE),
122134 );
123- this.screen.append(this.worldInfoBox);
135+ this.screen.append(this.navigationBox);
124136
137+ // -- CENTER COLUMN --
125138 this.logPanel = new LogPanel(this.screen, layout.log);
126139
127- this.locationBox = blessed.box(
128- createBoxOptions(
129- layout.location,
130- "Location",
131- COLORS.PANEL_BORDER_INACTIVE,
132- ),
140+ this.actionResultBox = blessed.box(
141+ createBoxOptions(layout.actionResult, " RESULT ", PALETTE.AMBER),
133142 );
134- this.screen.append(this.locationBox);
143+ this.screen.append(this.actionResultBox);
135144
145+ // -- RIGHT COLUMN --
136146 this.tacticalBox = blessed.box(
137- createBoxOptions(
138- layout.tactical,
139- "Tactical",
140- COLORS.PANEL_BORDER_INACTIVE,
141- ),
147+ createBoxOptions(layout.tactical, " TACTICAL ", THEME.BORDER_INACTIVE),
142148 );
143149 this.screen.append(this.tacticalBox);
144150
145151 this.contextBox = blessed.box(
146- createBoxOptions(layout.context, "Context", COLORS.PANEL_BORDER_INACTIVE),
152+ createBoxOptions(layout.context, " CONTEXT ", THEME.BORDER_INACTIVE),
147153 );
148154 this.screen.append(this.contextBox);
149155
156+ // -- STATUS BAR --
150157 this.statusBar = blessed.box({
151158 parent: this.screen,
152159 bottom: 0,
@@ -155,13 +162,13 @@ export class Tui {
155162 height: 1,
156163 tags: true,
157164 style: {
158- bg: "black",
159- fg: "cyan",
165+ bg: PALETTE.BLACK,
166+ fg: PALETTE.WHITE,
160167 },
161- content: "Starting...",
168+ content: "Initializing...",
162169 });
163170
164- // Debug panel (optional) - positioned right of main layout
171+ // Debug panel (optional)
165172 this.debugBox = this.debugEnabled
166173 ? blessed.box({
167174 parent: this.screen,
@@ -171,20 +178,14 @@ export class Tui {
171178 height: "100%-1",
172179 tags: false,
173180 border: "line",
174- label: "Debug Prompt",
181+ label: "Debug",
175182 style: {
176- border: {
177- fg: "blue",
178- },
183+ border: { fg: "blue" },
179184 bg: "black",
180185 fg: "white",
181186 },
182187 scrollable: true,
183188 alwaysScroll: false,
184- scrollbar: {
185- ch: " ",
186- inverse: true,
187- },
188189 content: "No prompt yet",
189190 })
190191 : null;
@@ -225,8 +226,6 @@ export class Tui {
225226
226227 update(data: TuiUpdateData): void {
227228 // Merge new data into state
228- // Note: player/ship skip null to preserve data when events don't include them
229- // Other fields allow null since they can legitimately be cleared (e.g., undocking clears base)
230229 if (data.player !== undefined && data.player !== null)
231230 this.state.player = data.player;
232231 if (data.ship !== undefined && data.ship !== null)
@@ -256,7 +255,7 @@ export class Tui {
256255 }
257256
258257 setStatus(text: string): void {
259- this.statusBar.setContent(applyColor(text, COLORS.PANEL_VALUE));
258+ this.statusBar.setContent(applyColor(text, THEME.VALUE));
260259 this.screen.render();
261260 }
262261
@@ -276,36 +275,40 @@ export class Tui {
276275 }
277276
278277 private updatePanels(): void {
279- // Player/Ship panel
280- const playerShipData: PlayerShipData = {
278+ // Player Panel
279+ const playerData: PlayerData = {
281280 player: this.state.player ?? null,
282- ship: this.state.ship ?? null,
283281 alignment: this.state.alignment,
284282 personality: this.state.personality,
285283 tick: this.state.tick ?? 0,
284+ currentMission: this.state.mission ?? null,
286285 };
287- this.playerShipBox.setContent(renderPlayerShipPanel(playerShipData));
286+ this.playerBox.setContent(renderPlayerPanel(playerData));
288287
289- // World Info panel
290- const worldInfoData: WorldInfoData = {
291- base: this.state.base ?? null,
288+ // Ship Panel
289+ const shipData: ShipData = {
290+ ship: this.state.ship ?? null,
292291 };
293- this.worldInfoBox.setContent(renderWorldInfoPanel(worldInfoData));
292+ this.shipBox.setContent(renderShipPanel(shipData));
294293
295- // Location panel
296- const locationData: LocationData = {
294+ // Navigation Panel
295+ const navData: NavigationData = {
297296 player: this.state.player ?? null,
298297 system: this.state.system ?? null,
299298 poi: this.state.poi ?? null,
300- pois: this.state.pois ?? [],
299+ base: this.state.base ?? null,
301300 traveling: this.state.traveling ?? false,
302301 travelTarget: this.state.travelTarget ?? null,
303302 jumping: this.state.jumping ?? false,
304303 jumpTarget: this.state.jumpTarget ?? null,
305304 };
306- this.locationBox.setContent(renderLocationPanel(locationData));
305+ this.navigationBox.setContent(renderNavigationPanel(navData));
307306
308- // Tactical panel
307+ // Action Result
308+ const lastResult = this.state.context?.lastActionResult;
309+ this.actionResultBox.setContent(renderActionResultPanel(lastResult));
310+
311+ // Tactical Panel
309312 const tacticalData: TacticalData = {
310313 inCombat: this.state.inCombat ?? false,
311314 combatTarget: this.state.combatTarget,
@@ -313,58 +316,34 @@ export class Tui {
313316 };
314317 this.tacticalBox.setContent(renderTacticalPanel(tacticalData));
315318
316- // Context panel
319+ // Update Border Color based on threat
320+ if (this.state.inCombat) {
321+ this.tacticalBox.style.border.fg = PALETTE.BRICK;
322+ } else {
323+ this.tacticalBox.style.border.fg = THEME.BORDER_INACTIVE;
324+ }
325+
326+ // Context Panel
317327 this.contextBox.setContent(renderContextPanel(this.state.context));
318328
319- // Status bar
329+ // Status Bar
320330 this.updateStatusBar();
321331 }
322332
323333 private updateStatusBar(): void {
324334 const parts: string[] = [];
335+ const tick = this.state.tick ?? 0;
325336
326- // Current status
327- if (this.state.inCombat) {
328- parts.push(applyColor("COMBAT", COLORS.STATUS_DANGER));
329- } else if (this.state.jumping) {
330- const target = this.state.jumpTarget ?? "unknown";
331- parts.push(`Jumping to ${target}`);
332- } else if (this.state.traveling) {
333- const target = this.state.travelTarget ?? "unknown";
334- parts.push(`Traveling to ${target}`);
335- } else if (this.state.player?.docked_at_base) {
336- parts.push("Docked");
337- } else if (this.state.poi?.name) {
338- parts.push(`At ${this.state.poi.name}`);
339- }
340-
341- // Mission
342- if (this.state.mission) {
343- parts.push(`Mission: ${this.state.mission}`);
344- }
345-
346- // Tick
347- if (this.state.tick !== undefined) {
348- parts.push(`Tick: ${this.state.tick}`);
349- }
337+ parts.push(applyColor(`Tick: ${tick}`, PALETTE.GRAY));
350338
351- // Fuel warning
352- if (this.state.ship) {
353- const fuelPct = (this.state.ship.fuel / this.state.ship.max_fuel) * 100;
354- if (fuelPct < THRESHOLDS.FUEL_LOW) {
355- parts.push(
356- applyColor(
357- `LOW FUEL (${Math.round(fuelPct)}%)`,
358- COLORS.STATUS_DANGER,
359- ),
360- );
361- }
339+ if (this.state.inCombat) {
340+ parts.push(applyColor("!!! COMBAT !!!", PALETTE.BRICK));
362341 }
363342
364- // Controls hint
365- parts.push("Press 'q' to quit");
343+ // Hints
344+ parts.push(applyColor("Tabs: 1-6 | Exit: q", THEME.INACTIVE));
366345
367- this.statusBar.setContent(parts.join(" | "));
346+ this.statusBar.setContent(parts.join(" | "));
368347 }
369348
370349 private applyLayout(): void {
@@ -379,38 +358,24 @@ export class Tui {
379358
380359 const layout = computeLayout(termWidth, termHeight);
381360
382- // Update panel dimensions
383- this.playerShipBox.left = layout.playerShip.left;
384- this.playerShipBox.top = layout.playerShip.top;
385- this.playerShipBox.width = layout.playerShip.width;
386- this.playerShipBox.height = layout.playerShip.height;
387-
388- this.worldInfoBox.left = layout.worldInfo.left;
389- this.worldInfoBox.top = layout.worldInfo.top;
390- this.worldInfoBox.width = layout.worldInfo.width;
391- this.worldInfoBox.height = layout.worldInfo.height;
361+ // Left
362+ this.updateBoxDims(this.playerBox, layout.player);
363+ this.updateBoxDims(this.shipBox, layout.ship);
364+ this.updateBoxDims(this.navigationBox, layout.navigation);
392365
366+ // Center
393367 this.logPanel.updateDimensions(layout.log);
368+ this.updateBoxDims(this.actionResultBox, layout.actionResult);
394369
395- this.locationBox.left = layout.location.left;
396- this.locationBox.top = layout.location.top;
397- this.locationBox.width = layout.location.width;
398- this.locationBox.height = layout.location.height;
399-
400- this.tacticalBox.left = layout.tactical.left;
401- this.tacticalBox.top = layout.tactical.top;
402- this.tacticalBox.width = layout.tactical.width;
403- this.tacticalBox.height = layout.tactical.height;
404-
405- this.contextBox.left = layout.context.left;
406- this.contextBox.top = layout.context.top;
407- this.contextBox.width = layout.context.width;
408- this.contextBox.height = layout.context.height;
370+ // Right
371+ this.updateBoxDims(this.tacticalBox, layout.tactical);
372+ this.updateBoxDims(this.contextBox, layout.context);
409373
374+ // Bottom
410375 this.statusBar.top = layout.statusBar.top;
411376 this.statusBar.width = layout.statusBar.width;
412377
413- // Debug panel - positioned off-screen by default, can be toggled
378+ // Debug panel - offscreen by default
414379 if (this.debugBox) {
415380 const debugWidth = Math.floor(termWidth * 0.3);
416381 this.debugBox.left = termWidth - debugWidth;
@@ -418,6 +383,21 @@ export class Tui {
418383 }
419384 }
420385
386+ private updateBoxDims(
387+ box: blessed.Widgets.BoxElement,
388+ dims: {
389+ left: number;
390+ top: number;
391+ width: number | string;
392+ height: number | string;
393+ },
394+ ) {
395+ box.left = dims.left;
396+ box.top = dims.top;
397+ box.width = dims.width;
398+ box.height = dims.height;
399+ }
400+
421401 private render(): void {
422402 this.screen.render();
423403 }
src/tui/layout.ts+69−52
@@ -1,5 +1,7 @@
11 // Panel layout and positioning logic
22
3+import { THEME } from "./theme";
4+
35 export interface PanelDimensions {
46 left: number;
57 top: number;
@@ -8,28 +10,30 @@ export interface PanelDimensions {
810 }
911
1012 export interface LayoutConfig {
11- leftWidth: number; // Width percentage for left sidebar
12- rightWidth: number; // Width percentage for right sidebar
13- leftTopHeightPercent: number; // Percent of left sidebar for top panel
14- leftMiddleHeightPercent: number; // Percent of left sidebar for middle panel
15- rightTopHeightPercent: number; // Percent of right sidebar for top panel
13+ leftWidth: number; // Percent
14+ rightWidth: number; // Percent
1615 }
1716
1817 export const DEFAULT_LAYOUT: LayoutConfig = {
19- leftWidth: 20, // 20% for left sidebar
20- rightWidth: 20, // 20% for right sidebar (center gets 60%)
21- leftTopHeightPercent: 35, // 35% of left sidebar for player/ship panel
22- leftMiddleHeightPercent: 35, // 35% of left sidebar for world info panel
23- rightTopHeightPercent: 40, // 40% of right sidebar for tactical panel
18+ leftWidth: 25,
19+ rightWidth: 25,
2420 };
2521
2622 export interface ComputedLayout {
27- playerShip: PanelDimensions;
28- worldInfo: PanelDimensions;
23+ // Left Column
24+ player: PanelDimensions;
25+ ship: PanelDimensions;
26+ navigation: PanelDimensions;
27+
28+ // Center Column
2929 log: PanelDimensions;
30- location: PanelDimensions;
30+ actionResult: PanelDimensions;
31+
32+ // Right Column
3133 tactical: PanelDimensions;
3234 context: PanelDimensions;
35+
36+ // Bottom
3337 statusBar: PanelDimensions;
3438 }
3539
@@ -38,10 +42,10 @@ export function computeLayout(
3842 termHeight: number,
3943 config: LayoutConfig = DEFAULT_LAYOUT,
4044 ): ComputedLayout {
41- // Minimum sizes to prevent panel collapse
42- const MIN_SIDEBAR_WIDTH = 18;
45+ // Minimum sizes
46+ const MIN_SIDEBAR_WIDTH = 25;
4347 const MIN_CENTER_WIDTH = 40;
44- const MIN_PANEL_HEIGHT = 5;
48+ const MIN_PANEL_HEIGHT = 4;
4549
4650 // Calculate absolute widths
4751 const leftWidthAbs = Math.max(
@@ -57,78 +61,91 @@ export function computeLayout(
5761 termWidth - leftWidthAbs - rightWidthAbs,
5862 );
5963
60- // Height for panels (reserve 1 line for status bar)
64+ // Available height (minus status bar)
6165 const availableHeight = termHeight - 1;
6266
63- // Left sidebar split into 3 panels: player/ship, world info, location
64- const leftTopHeight = Math.max(
67+ // -- Left Column --
68+ // Split: Player (25%), Ship (45%), Nav (30%)
69+ const playerHeight = Math.max(
6570 MIN_PANEL_HEIGHT,
66- Math.floor((availableHeight * config.leftTopHeightPercent) / 100),
71+ Math.floor(availableHeight * 0.25),
6772 );
68- const leftMiddleHeight = Math.max(
73+ const shipHeight = Math.max(
6974 MIN_PANEL_HEIGHT,
70- Math.floor((availableHeight * config.leftMiddleHeightPercent) / 100),
Cut short: this commit's diff is over 1000 lines.
src/tui/panels/action-result.ts+38−0
Cut short: this commit's diff is over 1000 lines.
src/tui/panels/context.ts+26−69
Cut short: this commit's diff is over 1000 lines.
src/tui/panels/location.ts+0−118
Cut short: this commit's diff is over 1000 lines.
src/tui/panels/log.ts+11−10
Cut short: this commit's diff is over 1000 lines.
src/tui/panels/navigation.ts+138−0
Cut short: this commit's diff is over 1000 lines.
src/tui/panels/player-ship.ts+0−84
Cut short: this commit's diff is over 1000 lines.
src/tui/panels/player.ts+71−0
Cut short: this commit's diff is over 1000 lines.
src/tui/panels/ship.ts+51−0
Cut short: this commit's diff is over 1000 lines.
src/tui/panels/tactical.ts+41−42
Cut short: this commit's diff is over 1000 lines.
src/tui/panels/world-info.ts+0−90
Cut short: this commit's diff is over 1000 lines.
src/tui/theme.ts+61−0
Cut short: this commit's diff is over 1000 lines.
src/tui/utils.ts+0−38
Cut short: this commit's diff is over 1000 lines.
src/tui/widgets.ts+74−0
Cut short: this commit's diff is over 1000 lines.