From c24153db869006b66fee4a4a3306bdf7cd6abe32 Mon Sep 17 00:00:00 2001 From: chengyongru <61816729+chengyongru@users.noreply.github.com> Date: Thu, 15 Oct 2026 15:21:28 +0800 Subject: [PATCH] fix(ui): keep theme text and selections readable (#6226) * fix(ui): keep theme text and selections readable * fix(tui): theme the blank composer cursor cell * refactor(webui): centralize diff theme colors * fix(tui): keep conversation selections readable * fix(ui): preserve nested syntax colors and selection lifetimes --- tui/src/app/app.ts | 7 + tui/src/app/layout.test.ts | 129 ++++++++++++++++-- tui/src/app/layout.ts | 10 +- tui/src/app/sessions.test.ts | 23 +++- tui/src/app/theme.ts | 17 ++- tui/src/composer/textarea.ts | 19 +++ tui/src/platform/selection.ts | 30 ++++ tui/src/views/diff-viewer.ts | 6 +- webui/src/components/CliAppMentionText.tsx | 4 - webui/src/components/CodeBlock.tsx | 39 ++---- webui/src/components/FileReferenceChip.tsx | 2 +- webui/src/components/InlineTokenHighlight.tsx | 4 +- webui/src/components/MessageBubble.tsx | 2 +- webui/src/components/ViewportCodeRows.tsx | 2 +- .../thread/ComposerUsagePopover.tsx | 4 +- .../components/thread/StreamErrorNotice.tsx | 2 +- .../src/components/thread/ThreadComposer.tsx | 2 +- .../components/thread/activity/DiffPair.tsx | 4 +- .../thread/activity/DiffSyntaxHighlight.tsx | 34 ++--- .../thread/activity/FileEditRow.tsx | 2 +- .../activity/ThinkingReasoningShell.tsx | 4 +- webui/src/globals.css | 59 +++++++- webui/src/lib/ansi.ts | 65 ++++++--- .../src/tests/agent-activity-cluster.test.tsx | 2 +- webui/src/tests/code-block.test.tsx | 39 ++---- ...diff-syntax-highlight.integration.test.tsx | 64 ++++++++- .../src/tests/diff-syntax-highlight.test.tsx | 12 +- webui/src/tests/message-bubble.test.tsx | 8 +- .../tests/thinking-reasoning-shell.test.tsx | 2 +- webui/src/tests/thread-composer.test.tsx | 9 +- webui/src/tests/thread-messages.test.tsx | 2 +- webui/tailwind.config.js | 8 ++ 32 files changed, 451 insertions(+), 165 deletions(-) create mode 100644 tui/src/composer/textarea.ts create mode 100644 tui/src/platform/selection.ts diff --git a/tui/src/app/app.ts b/tui/src/app/app.ts index 056a1b338..38781bab4 100644 --- a/tui/src/app/app.ts +++ b/tui/src/app/app.ts @@ -90,6 +90,7 @@ import { } from "../views/footer-hints" import { copyWithSystemClipboard } from "../platform/clipboard" import { configureOpenTuiEnvironment, createTuiHost, type TuiHost } from "../platform/host" +import { applySelectionColors } from "../platform/selection" import { LOCAL_COMMANDS } from "./commands" import { CooperativeEventQueue } from "./event-queue" import { @@ -404,6 +405,10 @@ export class NanobotTui { this.status = layout.status this.meta = layout.meta this.renderer.root.add(this.shell) + this.shell.renderBefore = () => { + const selection = this.renderer.getSelection() + if (selection) applySelectionColors(selection, this.palette.selection) + } this.renderer.keyInput.on("keypress", this.handleKey) this.renderer.on(CliRenderEvents.THEME_MODE, this.handleTheme) @@ -1729,6 +1734,8 @@ export class NanobotTui { this.composerFrame.borderColor = this.palette.accent this.composer.backgroundColor = surface this.composer.focusedBackgroundColor = surface + this.composer.selectionBg = this.palette.selection.background + this.composer.selectionFg = this.palette.selection.foreground this.composer.placeholderColor = this.palette.muted } diff --git a/tui/src/app/layout.test.ts b/tui/src/app/layout.test.ts index 9593b875e..237f97545 100644 --- a/tui/src/app/layout.test.ts +++ b/tui/src/app/layout.test.ts @@ -1,5 +1,5 @@ import { afterEach, describe, expect, test } from "bun:test" -import { BoxRenderable, CliRenderEvents, StyledText, TextareaRenderable, TextAttributes, TextRenderable } from "@opentui/core" +import { BoxRenderable, CliRenderEvents, StyledText, TextareaRenderable, TextAttributes, TextRenderable, rgbToHex } from "@opentui/core" import { MockTreeSitterClient, TestRecorder, setRendererCapabilities, createTestRenderer, type TestRendererSetup } from "@opentui/core/testing" import { NanobotTui } from "./app" import type { Transcript } from "../rendering/transcript" @@ -515,7 +515,7 @@ describe("NanobotTui layout and themes", () => { expect(internals.composerFrame.borderColor.toInts().slice(0, 3)).toEqual([185, 77, 11]) expect(internals.composerFrame.backgroundColor.toInts().slice(0, 3)).toEqual([240, 240, 240]) expect(internals.composer.backgroundColor.toInts().slice(0, 3)).toEqual([240, 240, 240]) - expect(internals.composer.placeholderColor.toInts().slice(0, 3)).toEqual([111, 111, 120]) + expect(internals.composer.placeholderColor.toInts().slice(0, 3)).toEqual([98, 98, 107]) app.accept({ event: "attached", chat_id: "chat" }) await waitUntil(() => internals.ready) @@ -528,6 +528,118 @@ describe("NanobotTui layout and themes", () => { expect(composerLine).not.toContain("┐") }) + test.each(["light", "dark", "auto"] as const)( + "keeps the %s composer cursor cell readable at the end of input", + async (theme) => { + setup = await createRenderer({ width: 72, height: 20, screenMode: "alternate-screen" }) + const app = NanobotTui.mount( + setup.renderer, + { ...options, theme }, + client(), + new MockTreeSitterClient({ autoResolveTimeout: 0 }), + ) + const ui = app as unknown as { ready: boolean; composer: TextareaRenderable } + app.accept({ event: "attached", chat_id: "chat" }) + await waitUntil(() => ui.ready) + await setup.mockInput.pressKeys([..."Draft 中文🙂"]) + + const expectCursorCell = async () => { + await setup!.flush() + const cursor = setup!.renderer.getCursorState() + const spans = setup!.captureSpans().lines[cursor.y - 1]!.spans + let column = 1 + const cell = spans.find((span) => { + const containsCursor = column <= cursor.x && cursor.x < column + span.width + column += span.width + return containsCursor + })! + expect(cursor.visible).toBe(true) + const buffer = setup!.renderer.currentRenderBuffer + expect(buffer.buffers.char[(cursor.y - 1) * buffer.width + cursor.x - 1]).toBe(32) + expect(cell.fg.equals(ui.composer.textColor)).toBe(true) + expect(cell.bg.equals(ui.composer.backgroundColor)).toBe(true) + } + + await expectCursorCell() + setup.mockInput.pressKey("HOME") + setup.mockInput.pressKey("END") + await expectCursorCell() + setup.mockInput.pressArrow("left") + setup.mockInput.pressArrow("right") + await expectCursorCell() + setup.mockInput.pressBackspace() + await expectCursorCell() + expect(ui.composer.plainText).toBe("Draft 中文") + setup.resize(18, 20) + await expectCursorCell() + }, + ) + + test.each(["light", "dark", "auto"] as const)( + "keeps %s conversation selections readable across Markdown blocks", + async (theme) => { + setup = await createRenderer({ width: 96, height: 48, screenMode: "alternate-screen" }) + const app = NanobotTui.mount( + setup.renderer, + { ...options, theme }, + client(), + new MockTreeSitterClient({ autoResolveTimeout: 0 }), + ) + const ui = app as unknown as { transcript: Transcript; composer: TextareaRenderable } + ui.transcript.user("User selection text") + ui.transcript.assistant([ + "Normal selection text", + "**Bold selection text**", + "- List selection text", + "```text\nCode selection text\n```", + "| Heading |\n| --- |\n| Table selection text |", + ].join("\n\n")) + await setup.flush() + + for (const text of [ + "User selection text", "Normal selection text", "Bold selection text", + "List selection text", "Code selection text", "Table selection text", + ]) { + setup.renderer.clearSelection() + await setup.flush() + const lines = setup.captureCharFrame().split("\n") + const y = lines.findIndex((line) => line.includes(text)) + const x = lines[y]!.indexOf(text) + await setup.mockMouse.drag(x, y, x + text.length, y) + await setup.flush() + expect(setup.renderer.getSelection()?.getSelectedText()).toContain(text) + const selected = setup.captureSpans().lines[y]!.spans.find((span) => span.text.includes(text))! + expect(selected.fg.intent).toBe("rgb") + expect(selected.bg.intent).toBe("rgb") + expect(contrastRatio(rgbToHex(selected.fg), rgbToHex(selected.bg))).toBeGreaterThanOrEqual(4.5) + } + + if (theme === "auto") { + for (const mode of ["light", "dark"] as const) { + setup.renderer.emit(CliRenderEvents.THEME_MODE, mode) + await setup.flush() + expect(setup.renderer.getSelection()?.getSelectedText()).toContain("Table selection text") + const selected = setup.captureSpans().lines.flatMap((line) => line.spans) + .find((span) => span.text.includes("Table selection text"))! + expect(selected.fg.intent).toBe("rgb") + expect(selected.bg.intent).toBe("rgb") + expect(contrastRatio(rgbToHex(selected.fg), rgbToHex(selected.bg))).toBeGreaterThanOrEqual(4.5) + } + } + + setup.renderer.clearSelection() + await setup.mockInput.typeText("Composer selection text") + setup.mockInput.pressKey("HOME", { shift: true }) + await setup.flush() + expect(ui.composer.getSelectedText()).toBe("Composer selection text") + const selected = setup.captureSpans().lines.flatMap((line) => line.spans) + .find((span) => span.text.includes("Composer selection text"))! + expect(selected.fg.intent).toBe("rgb") + expect(selected.bg.intent).toBe("rgb") + expect(contrastRatio(rgbToHex(selected.fg), rgbToHex(selected.bg))).toBeGreaterThanOrEqual(4.5) + }, + ) + test("uses asymmetric roles instead of chat bubbles", async () => { setup = await createRenderer({ width: 72, height: 24, screenMode: "alternate-screen" }) const app = NanobotTui.mount( @@ -750,11 +862,12 @@ describe("NanobotTui layout and themes", () => { const internals = app as unknown as { palette: Record & { referenceBackground: string; faint: string } } - const assertContrast = () => { - for (const tone of ["text", "muted", "accent", "link", "success", "error", "user", "warm", "cool"]) { - expect(contrastRatio(internals.palette[tone] ?? "", internals.palette.referenceBackground)).toBeGreaterThanOrEqual(4.5) + const assertContrast = (backgrounds: string[]) => { + for (const background of backgrounds) { + for (const tone of ["text", "muted", "faint", "accent", "link", "success", "error", "user", "warm", "cool"]) { + expect(contrastRatio(internals.palette[tone] ?? "", background)).toBeGreaterThanOrEqual(4.5) + } } - expect(contrastRatio(internals.palette.faint, internals.palette.referenceBackground)).toBeGreaterThanOrEqual(3) const turnContrast = contrastRatio( internals.palette.userBackground ?? "", internals.palette.referenceBackground, @@ -764,11 +877,11 @@ describe("NanobotTui layout and themes", () => { } setup.renderer.emit(CliRenderEvents.THEME_MODE, "dark") - assertContrast() + assertContrast([internals.palette.referenceBackground, "#282C34", "#282A36", "#282828", "#002B36"]) expect(internals.palette.accent).toBe("#EF8E30") expect(internals.palette.user).toBe("#EF8E30") setup.renderer.emit(CliRenderEvents.THEME_MODE, "light") - assertContrast() + assertContrast([internals.palette.referenceBackground, "#FDF6E3"]) expect(internals.palette.accent).toBe("#B94D0B") expect(internals.palette.user).toBe("#B94D0B") }) diff --git a/tui/src/app/layout.ts b/tui/src/app/layout.ts index e877b1d64..027d1fd58 100644 --- a/tui/src/app/layout.ts +++ b/tui/src/app/layout.ts @@ -1,7 +1,6 @@ import { BoxRenderable, RGBA, - TextareaRenderable, TextRenderable, type CliRenderer, type PasteEvent, @@ -9,6 +8,7 @@ import { } from "@opentui/core" import type { QueuePreview } from "../composer/queue-preview" +import { ComposerTextarea } from "../composer/textarea" import type { BranchMenu } from "../menus/branch-menu" import type { CommandMenu } from "../menus/command-menu" import type { MentionMenu } from "../menus/mention-menu" @@ -57,7 +57,7 @@ export interface AppLayout { shell: BoxRenderable title: BoxRenderable composerFrame: BoxRenderable - composer: TextareaRenderable + composer: ComposerTextarea status: TextRenderable meta: TextRenderable } @@ -116,7 +116,7 @@ export function createAppLayout( paddingRight: 1, backgroundColor: composerSurface, }) - const composer = new TextareaRenderable(renderer, { + const composer = new ComposerTextarea(renderer, { id: "nanobot-tui-composer", width: "100%", minHeight: 1, @@ -128,10 +128,10 @@ export function createAppLayout( focusedTextColor: palette.text, backgroundColor: composerSurface, focusedBackgroundColor: composerSurface, + selectionBg: palette.selection.background, + selectionFg: palette.selection.foreground, cursorColor: palette.accent, syntaxStyle: composerSyntax, - // A steady line cursor avoids the block-cell trails produced by some - // terminals when a retained full-screen UI redraws around the composer. cursorStyle: { style: "line", blinking: false }, showCursor: true, keyBindings: [ diff --git a/tui/src/app/sessions.test.ts b/tui/src/app/sessions.test.ts index c75438e07..6f342355f 100644 --- a/tui/src/app/sessions.test.ts +++ b/tui/src/app/sessions.test.ts @@ -1,9 +1,9 @@ import { afterEach, describe, expect, test } from "bun:test" -import { CliRenderEvents, TextareaRenderable, TextRenderable } from "@opentui/core" +import { CliRenderEvents, TextareaRenderable, TextRenderable, rgbToHex } from "@opentui/core" import { MockTreeSitterClient, createTestRenderer, type TestRendererSetup } from "@opentui/core/testing" import { NanobotTui } from "./app" import type { RecoveryState, SlashCommand, WorkspaceScopePayload } from "../client" -import { options, client, mount, waitUntil, occurrences } from "./test-support" +import { options, client, mount, waitUntil, occurrences, contrastRatio } from "./test-support" describe("NanobotTui session navigation", () => { let setup: TestRendererSetup | undefined @@ -907,7 +907,7 @@ describe("NanobotTui session navigation", () => { }) test("opens the latest turn diff as a full-screen, navigable view", async () => { - setup = await createRenderer({ width: 96, height: 28, screenMode: "alternate-screen" }) + setup = await createRenderer({ width: 96, height: 28, screenMode: "alternate-screen", consoleMode: "disabled" }) const app = mount(setup) app.accept({ event: "attached", chat_id: "chat" }) await waitUntil(() => (app as unknown as { ready: boolean }).ready) @@ -972,6 +972,23 @@ describe("NanobotTui session navigation", () => { expect(frame).toContain("Diff truncated by the gateway") expect(frame).not.toContain("Ask nanobot anything") + const rows = frame.split("\n") + const y = rows.findIndex((row) => row.includes("const newValue = 2")) + const x = rows[y]!.indexOf("const newValue = 2") + await setup.mockMouse.drag(x, y, x + "const newValue = 2".length, y) + await setup.flush() + expect(setup.renderer.getSelection()?.getSelectedText()).toBe("const newValue = 2") + const selected = setup.captureSpans().lines[y]!.spans.find((span) => span.text.includes("const newValue = 2"))! + expect(selected.fg.intent).toBe("rgb") + expect(selected.bg.intent).toBe("rgb") + expect(contrastRatio(rgbToHex(selected.fg), rgbToHex(selected.bg))).toBeGreaterThanOrEqual(4.5) + + setup.renderer.emit(CliRenderEvents.THEME_MODE, "light") + await setup.flush() + expect(setup.renderer.console.visible).toBe(false) + expect(setup.captureCharFrame()).toContain("const newValue = 2") + setup.renderer.clearSelection() + setup.mockInput.pressArrow("right") await setup.flush() frame = setup.captureCharFrame() diff --git a/tui/src/app/theme.ts b/tui/src/app/theme.ts index 8be241776..ed0281713 100644 --- a/tui/src/app/theme.ts +++ b/tui/src/app/theme.ts @@ -16,6 +16,7 @@ import type { DiffViewerTheme } from "../views/diff-viewer" import type { FooterHintTheme } from "../views/footer-hints" import type { RecoveryNoticeTheme } from "../views/recovery-notice" import type { UsagePanelTheme } from "../views/usage-panel" +import type { SelectionColors } from "../platform/selection" export const IMAGE_PLACEHOLDER_STYLE = "image.placeholder" export const SHIMMER_INTERVAL_MS = 80 @@ -38,13 +39,14 @@ export interface Palette { userBackground: ColorInput warm: ColorInput cool: ColorInput + selection: SelectionColors } export const DARK: Palette = { referenceBackground: "#0E0F11", text: "#ECEDEE", muted: "#A1A1AA", - faint: "#71717A", + faint: "#A1A1AA", border: "#3F3F46", accent: "#EF8E30", link: "#60A5FA", @@ -54,15 +56,16 @@ export const DARK: Palette = { user: "#EF8E30", // Codex-style turn anchor: 12% white over the reference dark background. userBackground: "#2B2C2E", - warm: "#C26A25", - cool: "#1795A2", + warm: "#E9965A", + cool: "#36B8C7", + selection: { background: RGBA.fromHex("#3F3F46"), foreground: RGBA.fromHex("#ECEDEE") }, } export const LIGHT: Palette = { referenceBackground: "#FAFAFA", text: "#18181B", - muted: "#6F6F78", - faint: "#8A8A94", + muted: "#62626B", + faint: "#62626B", border: "#D4D4D8", accent: "#B94D0B", link: "#1D4ED8", @@ -74,6 +77,7 @@ export const LIGHT: Palette = { userBackground: "#F0F0F0", warm: "#C2410C", cool: "#0F766E", + selection: { background: RGBA.fromHex("#D4D4D8"), foreground: RGBA.fromHex("#18181B") }, } // Until the terminal answers OSC 10/11, its default foreground is the only @@ -93,6 +97,7 @@ export const TERMINAL: Palette = { userBackground: RGBA.defaultBackground(), warm: RGBA.defaultForeground(), cool: RGBA.defaultForeground(), + selection: { background: RGBA.fromHex("#93C5FD"), foreground: RGBA.fromHex("#18181B") }, } @@ -182,6 +187,8 @@ export function diffViewerTheme(palette: Palette, backgroundKnown: boolean): Dif error: palette.error, addedBackground: backgroundKnown ? light ? "#E7F6EC" : "#142D22" : null, removedBackground: backgroundKnown ? light ? "#FCE8EA" : "#352024" : null, + selectionBackground: palette.selection.background, + selectionForeground: palette.selection.foreground, syntax: syntaxStyle(palette), } } diff --git a/tui/src/composer/textarea.ts b/tui/src/composer/textarea.ts new file mode 100644 index 000000000..a54d7d9a4 --- /dev/null +++ b/tui/src/composer/textarea.ts @@ -0,0 +1,19 @@ +import { TextareaRenderable, type OptimizedBuffer } from "@opentui/core" + +export class ComposerTextarea extends TextareaRenderable { + override renderCursor(buffer: OptimizedBuffer): void { + if (this.focused && this.showCursor) { + const { visualCol, visualRow } = this.visualCursor + const x = this.x + visualCol + const y = this.y + visualRow + if (x >= 0 && x < buffer.width && y >= 0 && y < buffer.height) { + const index = y * buffer.width + x + const { char, fg } = buffer.buffers + // OpenTUI clears unused editor cells with a white foreground. Hosts + // that draw a cursor by reversing the cell use that color as its fill. + if (char[index] === 32) fg.set(this.textColor.buffer, index * 4) + } + } + super.renderCursor(buffer) + } +} diff --git a/tui/src/platform/selection.ts b/tui/src/platform/selection.ts new file mode 100644 index 000000000..1bf55ad33 --- /dev/null +++ b/tui/src/platform/selection.ts @@ -0,0 +1,30 @@ +import { + EditBufferRenderable, + TextBufferRenderable, + TextTableRenderable, + type RGBA, + type Selection, +} from "@opentui/core" + +export interface SelectionColors { + background: RGBA + foreground: RGBA +} + +export function applySelectionColors(selection: Selection, colors: SelectionColors): void { + for (const renderable of selection.selectedRenderables) { + if (renderable.isDestroyed) continue + if (renderable instanceof TextBufferRenderable || renderable instanceof EditBufferRenderable) { + renderable.selectionBg = colors.background + renderable.selectionFg = colors.foreground + } else if (renderable instanceof TextTableRenderable) { + // OpenTUI 0.5.11 exposes table selection colors only at construction. + // Update its retained palette without replacing streaming table cells. + const table = renderable as unknown as { _selectionBg?: RGBA; _selectionFg?: RGBA } + if (table._selectionBg === colors.background && table._selectionFg === colors.foreground) continue + table._selectionBg = colors.background + table._selectionFg = colors.foreground + renderable.onSelectionChanged(selection) + } + } +} diff --git a/tui/src/views/diff-viewer.ts b/tui/src/views/diff-viewer.ts index 8c0f2c2c9..50f885195 100644 --- a/tui/src/views/diff-viewer.ts +++ b/tui/src/views/diff-viewer.ts @@ -24,6 +24,8 @@ export interface DiffViewerTheme { error: ColorInput addedBackground: ColorInput | null removedBackground: ColorInput | null + selectionBackground: ColorInput + selectionForeground: ColorInput syntax: SyntaxStyle } @@ -295,8 +297,8 @@ export class DiffViewer { removedLineNumberBg: this.theme.removedBackground || RGBA.defaultBackground(), addedSignColor: this.theme.success, removedSignColor: this.theme.error, - selectionBg: this.theme.border, - selectionFg: this.theme.text, + selectionBg: this.theme.selectionBackground, + selectionFg: this.theme.selectionForeground, })) if (edit.diff?.truncated) { this.scroll.add(this.text("… Diff truncated by the gateway; line counts may be larger.", "accent")) diff --git a/webui/src/components/CliAppMentionText.tsx b/webui/src/components/CliAppMentionText.tsx index b0f6ea747..d55f104a2 100644 --- a/webui/src/components/CliAppMentionText.tsx +++ b/webui/src/components/CliAppMentionText.tsx @@ -179,7 +179,6 @@ function CliAppMentionToken({ isHero?: boolean; }) { const { t } = useTranslation(); - const color = app.brand_color || INLINE_TOKEN_HIGHLIGHT_COLOR; const displayName = app.display_name?.trim() || app.name; const mentionName = variant === "message" ? displayName @@ -195,7 +194,6 @@ function CliAppMentionToken({ title={t("thread.composer.mentions.cliTitle", { name: variant === "message" ? `${displayName} (${label})` : displayName, })} - color={color} className={variant === "composer" ? "font-normal" : "inline-flex max-w-full items-baseline [overflow-wrap:anywhere]"} > { const [ { default: SyntaxHighlighter }, - { default: oneDark }, - { default: oneLight }, { ViewportCodeRows }, ] = await Promise.all([ import("react-syntax-highlighter/dist/esm/prism-async-light"), - import("react-syntax-highlighter/dist/esm/styles/prism/one-dark"), - import("react-syntax-highlighter/dist/esm/styles/prism/one-light"), import("@/components/ViewportCodeRows"), ]); @@ -60,29 +55,16 @@ const LazyHighlightedCode = lazy(async () => { default({ language, code, - isDark, chrome, showLineNumbers, wrapLongLines, viewportHighlight, }: HighlightedCodeProps) { - const theme = isDark ? oneDark : oneLight; - const transparentTheme = chrome === "none" ? { - ...theme, - 'pre[class*="language-"]': { - ...theme['pre[class*="language-"]'], - background: "transparent", - }, - 'code[class*="language-"]': { - ...theme['code[class*="language-"]'], - background: "transparent", - }, - } : theme; - return ( { lineNumberStyle={{ minWidth: "2.6em", paddingRight: "1.15rem", - color: isDark ? "rgba(212, 212, 216, 0.45)" : "rgba(63, 63, 70, 0.68)", + color: "var(--code-comment)", fontFamily: CODE_FONT_STACK, userSelect: "none", }} @@ -125,8 +107,8 @@ function renderPlainText(value: string): ReactNode { return value; } -function renderAnsiText(value: string): ReactNode { - return parseAnsiSegments(value).map((segment, index) => ( +function renderAnsiText(value: string, theme: "light" | "dark"): ReactNode { + return parseAnsiSegments(value, theme).map((segment, index) => ( {segment.text} @@ -168,14 +150,14 @@ function CodeTextBlock({ {showLineNumbers && compact ? ( - {lines.map((_, index) => index + 1).join("\n")} {renderText(code)} ) : showLineNumbers ? ( lines.map((line, index) => ( - + {index + 1} {renderText(line || " ")} @@ -264,7 +246,7 @@ export const CodeBlock = memo(function CodeBlock({
renderAnsiText(value, isDark ? "dark" : "light")} compact={useViewportHighlight} /> ) : highlight && withinHighlightBudget && (!deferHighlight || highlightedSource === code) ? ( @@ -295,7 +277,6 @@ export const CodeBlock = memo(function CodeBlock({ {display === "path" && directory ? ( <> - {directory} + {directory} {name} ) : ( diff --git a/webui/src/components/InlineTokenHighlight.tsx b/webui/src/components/InlineTokenHighlight.tsx index 818cabbd0..e27bbbe05 100644 --- a/webui/src/components/InlineTokenHighlight.tsx +++ b/webui/src/components/InlineTokenHighlight.tsx @@ -13,7 +13,7 @@ export function InlineTokenHighlight({ }: { children: ReactNode; className?: string; - color: string; + color?: string; testId?: string; title?: string; }) { @@ -22,7 +22,7 @@ export function InlineTokenHighlight({ data-testid={testId} title={title} className={cn( - "relative inline font-[550] transition-colors duration-150", + "relative inline font-[550] text-foreground transition-colors duration-150", className, )} style={{ color }} diff --git a/webui/src/components/MessageBubble.tsx b/webui/src/components/MessageBubble.tsx index cefcf6ed7..ed898496a 100644 --- a/webui/src/components/MessageBubble.tsx +++ b/webui/src/components/MessageBubble.tsx @@ -261,7 +261,7 @@ export function MessageBlockMenuActions({ {timestampLabel || automationSourceLabel ? (
{timestampLabel ? (