fix(tui): animate status with unknown terminal theme

This commit is contained in:
chengyongru authored and chengyongru committed 2026-09-29 13:05:36 +08:00
1 parent cf25e91b17
commit 9b72ebe228
2 files changed
+43 -7

No files matched your search

+24 -2
View File
@@ -2464,7 +2464,12 @@ describe("NanobotTui layout", () => {
transcript.user("Unknown terminal background")
expect(connected).toBe(true)
const ui = app as unknown as { composer: TextareaRenderable; status: TextRenderable }
const ui = app as unknown as {
composer: TextareaRenderable
status: TextRenderable
shimmerFrame: number
renderActiveStatus(): void
}
expect(ui.composer.textColor.intent).toBe("default")
expect(ui.composer.backgroundColor.intent).toBe("default")
expect([...transcript.userRows][0]?.backgroundColor.intent).toBe("default")
@@ -2477,14 +2482,31 @@ describe("NanobotTui layout", () => {
if (span.text.trim()) expect(span.fg.intent).toBe("default")
}
}
// Active status must not turn the default color into guessed RGB shimmer colors.
// Keep the fallback readable without guessed RGB colors, but do not freeze
// the active-status animation while waiting for a terminal theme response.
app.accept({ event: "reasoning_delta", chat_id: "chat", text: "thinking" })
await setup.flush()
const terminalFrame = () => (ui.status.content as StyledText).chunks
.slice(0, "Thinking".length)
.map((chunk) => chunk.attributes ?? 0)
const firstFrame = terminalFrame()
ui.shimmerFrame += 1
ui.renderActiveStatus()
const secondFrame = terminalFrame()
expect(firstFrame).toContain(TextAttributes.BOLD)
expect(secondFrame).not.toEqual(firstFrame)
for (const chunk of (ui.status.content as StyledText).chunks) {
expect(chunk.fg?.intent).toBe("default")
}
setup.renderer.emit(CliRenderEvents.THEME_MODE, mode)
await setup.flush()
const shimmerColors = new Set(
(ui.status.content as StyledText).chunks
.slice(0, "Thinking".length)
.map((chunk) => chunk.fg?.toInts().slice(0, 3).join(",")),
)
expect(shimmerColors.size).toBeGreaterThan(1)
expect(ui.composer.textColor.intent).toBe("rgb")
expect(ui.composer.textColor.toInts().slice(0, 3)).toEqual(
mode === "light" ? [24, 24, 27] : [236, 237, 238],
+19 -5
View File
@@ -5,6 +5,7 @@ import {
StyledText,
SyntaxStyle,
TextareaRenderable,
TextAttributes,
TextRenderable,
createCliRenderer,
decodePasteBytes,
@@ -216,6 +217,7 @@ const COMPACT_ACTIVE_COMPOSER_PLACEHOLDER = "Enter now · Tab next"
const IMAGE_PLACEHOLDER_STYLE = "image.placeholder"
const SHIMMER_PAUSE = 16
const SHIMMER_BAND = 4
const TERMINAL_SHIMMER_BAND = 1
const SHIMMER_INTERVAL_MS = 80
const EVENT_BATCH_SIZE = 64
const EVENT_BATCH_BUDGET_MS = 4
@@ -395,15 +397,27 @@ function shimmerStatus(
frame: number,
palette: Palette,
): StyledText {
if (palette === TERMINAL) {
return new StyledText([{ __isChunk: true, text: label + suffix, fg: parseColor(palette.text) }])
}
const chars = Array.from(label)
const base = parseColor(palette.muted).toInts()
const highlight = parseColor(palette.accent).toInts()
// Sweep immediately, then leave a quiet pause before repeating. The text
// keeps a constant width throughout, so the footer never jitters.
const position = frame % (chars.length + SHIMMER_PAUSE)
if (palette === TERMINAL) {
// Terminal-default colors cannot be interpolated without guessing the
// terminal theme, so move a bold band while preserving native color intent.
const foreground = parseColor(palette.text)
const chunks: TextChunk[] = chars.map((text, index) => ({
__isChunk: true,
text,
fg: foreground,
attributes: Math.abs(index - position) <= TERMINAL_SHIMMER_BAND
? TextAttributes.BOLD
: 0,
}))
chunks.push({ __isChunk: true, text: suffix, fg: foreground })
return new StyledText(chunks)
}
const base = parseColor(palette.muted).toInts()
const highlight = parseColor(palette.accent).toInts()
const chunks: TextChunk[] = chars.map((text, index) => {
const distance = Math.abs(index - position)
const intensity = distance > SHIMMER_BAND