@@ -1,36 +1,48 @@
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);
917 return HStack({ flex: 1, alignItems: "center" }, [
1018 VStack({ flex: 1, alignItems: "center", gap: 1 }, [
1119 HStack({ gap: 1 }, [
1220 Text("mini"),
13- TextPill("coder", theme.black, randColor),
21+ TextPill(
22+ "coder",
23+ textColorForBackground(randColor, state.options.theme),
24+ randColor,
25+ ),
1426 ]),
1527 VStack({ gap: 1 }, [
1628 HStack({ gap: 1 }, [
17- TextPill("/new", randColor, theme.bblack, 13),
29+ TextPill("/new", shortcutFgColor, theme.bblack, 13),
1830 Text("Start a new session from the input box.", {
1931 fgColor: theme.bblack,
2032 }),
2133 ]),
2234 HStack({ gap: 1 }, [
23- TextPill("ctrl+p", randColor, theme.bblack, 13),
35+ TextPill("ctrl+p", shortcutFgColor, theme.bblack, 13),
2436 Text("Menu for session history, and settings.", {
2537 fgColor: theme.bblack,
2638 }),
2739 ]),
2840 HStack({ gap: 1 }, [
29- TextPill("ESC", randColor, theme.bblack, 13),
41+ TextPill("ESC", shortcutFgColor, theme.bblack, 13),
3042 Text("Abort agent response.", { fgColor: theme.bblack }),
3143 ]),
3244 HStack({ gap: 1 }, [
33- TextPill("ctrl+c|d|q", randColor, theme.bblack, 13),
45+ TextPill("ctrl+c|d|q", shortcutFgColor, theme.bblack, 13),
3446 Text("Quit.", { fgColor: theme.bblack }),
3547 ]),
3648 ]),
@@ -38,7 +50,10 @@ export function emptyState(): Node {
3850 ]);
3951 }
4052
41-function ConversationMessageToolCall(call: TUIToolCall) {
53+function ConversationMessageToolCall(
54+ call: TUIToolCall,
55+ syntaxTheme: SyntaxHighlightTheme,
56+) {
4257 let outputNode: Node | null = null;
4358
4459 // Compress read and bash calls
@@ -64,7 +79,7 @@ function ConversationMessageToolCall(call: TUIToolCall) {
6479
6580 outputNode = VStack({ width: "100%" }, blocks);
6681 } else if (call.tool === "edit") {
67- outputNode = SyntaxHighlight(call.output, "patch");
82+ outputNode = SyntaxHighlight(call.output, "patch", { theme: syntaxTheme });
6883 } else {
6984 outputNode = Text(call.output, { wrap: "word" });
7085 }
@@ -81,7 +96,7 @@ function ConversationMessageToolCall(call: TUIToolCall) {
8196
8297 // Syntax highlight bash args
8398 if (call.tool === "bash") {
84- node = SyntaxHighlight(String(value), "bash");
99+ node = SyntaxHighlight(String(value), "bash", { theme: syntaxTheme });
85100 return node;
86101 }
87102
@@ -99,7 +114,11 @@ function ConversationMessageToolCall(call: TUIToolCall) {
99114 ]);
100115 }
101116
102-function ConversationMessage(message: TUIMessage) {
117+function ConversationMessage(
118+ message: TUIMessage,
119+ syntaxTheme: SyntaxHighlightTheme,
120+ userMessageBgColor: Color | undefined,
121+) {
103122 const blocks: Node[] = [];
104123
105124 if (message.thinking) {
@@ -118,17 +137,22 @@ function ConversationMessage(message: TUIMessage) {
118137 VStack(
119138 {
120139 width: "100%",
121- bgColor: message.role === "user" ? theme.bblack : undefined,
140+ bgColor: message.role === "user" ? userMessageBgColor : undefined,
122141 padding: { y: 1, x: message.role === "user" ? 1 : 0 },
123142 },
124- [SyntaxHighlight(message.text, "markdown")],
143+ [SyntaxHighlight(message.text, "markdown", { theme: syntaxTheme })],
125144 ),
126145 );
127146 }
128147
129148 if (message.toolCalls?.length) {
130149 blocks.push(
131- VStack({ gap: 1 }, message.toolCalls.map(ConversationMessageToolCall)),
150+ VStack(
151+ { gap: 1 },
152+ message.toolCalls.map((call) =>
153+ ConversationMessageToolCall(call, syntaxTheme),
154+ ),
155+ ),
132156 );
133157 }
134158
@@ -158,6 +182,8 @@ function ConversationMessage(message: TUIMessage) {
158182 }
159183
160184 export function Conversation(state: TUIState) {
185+ const activeTheme = getTUITheme(state.options.theme);
186+
161187 return VStack(
162188 {
163189 flex: 1,
@@ -169,6 +195,12 @@ export function Conversation(state: TUIState) {
169195 state.stickToBottom = offset >= maxOffset;
170196 },
171197 },
172- state.tuiMessages.map(ConversationMessage),
198+ state.tuiMessages.map((message) =>
199+ ConversationMessage(
200+ message,
201+ activeTheme.syntax,
202+ activeTheme.userMessageBgColor,
203+ ),
204+ ),
173205 );
174206 }