@@ -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 }