@@ -1,44 +1,71 @@
1-import { SyntaxHighlight } from "@cel-tui/components";
2-import { HStack, type Node, Text, VStack } from "@cel-tui/core";
1+import {
2+ SyntaxHighlight,
3+ type SyntaxHighlightTheme,
4+} from "@cel-tui/components";
5+import { type Color, HStack, type Node, Text, VStack } from "@cel-tui/core";
36 import { estimateTokens } from "./shared";
7+import { getTUITheme, textColorForBackground } from "./themes";
48 import { TextPill, theme } from "./tui-components";
59 import type { TUIMessage, TUIState, TUIToolCall } from "./types";
610
7-export function emptyState(): Node {
11+export function emptyState(state: TUIState): Node {
812 const randColor = theme.bgreen;
13+ const shortcutFgColor =
14+ state.options.theme === "ansi16"
15+ ? randColor
16+ : textColorForBackground(theme.bblack, state.options.theme);
17+ const updateNotice = state.availableUpdate
18+ ? [
19+ HStack({ gap: 1 }, [
20+ TextPill("update", shortcutFgColor, theme.bblack, 13),
21+ Text(
22+ `mini-coder ${state.availableUpdate.latestVersion} is available. Run mc --update.`,
23+ { fgColor: theme.bblack },
24+ ),
25+ ]),
26+ ]
27+ : [];
928 return HStack({ flex: 1, alignItems: "center" }, [
1029 VStack({ flex: 1, alignItems: "center", gap: 1 }, [
1130 HStack({ gap: 1 }, [
1231 Text("mini"),
13- TextPill("coder", theme.black, randColor),
32+ TextPill(
33+ "coder",
34+ textColorForBackground(randColor, state.options.theme),
35+ randColor,
36+ ),
1437 ]),
1538 VStack({ gap: 1 }, [
1639 HStack({ gap: 1 }, [
17- TextPill("/new", randColor, theme.bblack, 13),
40+ TextPill("/new", shortcutFgColor, theme.bblack, 13),
1841 Text("Start a new session from the input box.", {
1942 fgColor: theme.bblack,
2043 }),
2144 ]),
2245 HStack({ gap: 1 }, [
23- TextPill("ctrl+p", randColor, theme.bblack, 13),
46+ TextPill("ctrl+p", shortcutFgColor, theme.bblack, 13),
2447 Text("Menu for session history, and settings.", {
2548 fgColor: theme.bblack,
2649 }),
2750 ]),
2851 HStack({ gap: 1 }, [
29- TextPill("ESC", randColor, theme.bblack, 13),
52+ TextPill("ESC", shortcutFgColor, theme.bblack, 13),
3053 Text("Abort agent response.", { fgColor: theme.bblack }),
3154 ]),
3255 HStack({ gap: 1 }, [
33- TextPill("ctrl+c|d|q", randColor, theme.bblack, 13),
56+ TextPill("ctrl+c|d|q", shortcutFgColor, theme.bblack, 13),
3457 Text("Quit.", { fgColor: theme.bblack }),
3558 ]),
59+ ...updateNotice,
3660 ]),
3761 ]),
3862 ]);
3963 }
4064
41-function ConversationMessageToolCall(call: TUIToolCall) {
65+function ConversationMessageToolCall(
66+ call: TUIToolCall,
67+ syntaxTheme: SyntaxHighlightTheme,
68+) {
4269 let outputNode: Node | null = null;
4370
4471 // Compress read and bash calls
@@ -64,7 +91,7 @@ function ConversationMessageToolCall(call: TUIToolCall) {
6491
6592 outputNode = VStack({ width: "100%" }, blocks);
6693 } else if (call.tool === "edit") {
67- outputNode = SyntaxHighlight(call.output, "patch");
94+ outputNode = SyntaxHighlight(call.output, "patch", { theme: syntaxTheme });
6895 } else {
6996 outputNode = Text(call.output, { wrap: "word" });
7097 }
@@ -81,7 +108,7 @@ function ConversationMessageToolCall(call: TUIToolCall) {
81108
82109 // Syntax highlight bash args
83110 if (call.tool === "bash") {
84- node = SyntaxHighlight(String(value), "bash");
111+ node = SyntaxHighlight(String(value), "bash", { theme: syntaxTheme });
85112 return node;
86113 }
87114
@@ -99,7 +126,11 @@ function ConversationMessageToolCall(call: TUIToolCall) {
99126 ]);
100127 }
101128
102-function ConversationMessage(message: TUIMessage) {
129+function ConversationMessage(
130+ message: TUIMessage,
131+ syntaxTheme: SyntaxHighlightTheme,
132+ userMessageBgColor: Color | undefined,
133+) {
103134 const blocks: Node[] = [];
104135
105136 if (message.thinking) {
@@ -118,17 +149,22 @@ function ConversationMessage(message: TUIMessage) {
118149 VStack(
119150 {
120151 width: "100%",
121- bgColor: message.role === "user" ? theme.bblack : undefined,
152+ bgColor: message.role === "user" ? userMessageBgColor : undefined,
122153 padding: { y: 1, x: message.role === "user" ? 1 : 0 },
123154 },
124- [SyntaxHighlight(message.text, "markdown")],
155+ [SyntaxHighlight(message.text, "markdown", { theme: syntaxTheme })],
125156 ),
126157 );
127158 }
128159
129160 if (message.toolCalls?.length) {
130161 blocks.push(
131- VStack({ gap: 1 }, message.toolCalls.map(ConversationMessageToolCall)),
162+ VStack(
163+ { gap: 1 },
164+ message.toolCalls.map((call) =>
165+ ConversationMessageToolCall(call, syntaxTheme),
166+ ),
167+ ),
132168 );
133169 }
134170
@@ -158,6 +194,8 @@ function ConversationMessage(message: TUIMessage) {
158194 }
159195
160196 export function Conversation(state: TUIState) {
197+ const activeTheme = getTUITheme(state.options.theme);
198+
161199 return VStack(
162200 {
163201 flex: 1,
@@ -169,6 +207,12 @@ export function Conversation(state: TUIState) {
169207 state.stickToBottom = offset >= maxOffset;
170208 },
171209 },
172- state.tuiMessages.map(ConversationMessage),
210+ state.tuiMessages.map((message) =>
211+ ConversationMessage(
212+ message,
213+ activeTheme.syntax,
214+ activeTheme.userMessageBgColor,
215+ ),
216+ ),
173217 );
174218 }