fix(paint): backgroundColor now visible with borders and text

Root causes:
- drawBorder wrote plain characters, overwriting fillBackground's ANSI codes
- renderTextWithInlineStyles spread node.props over inherited bg, but
  undefined props from Vue clobbered the inherited backgroundColor
- Child text nodes did not inherit backgroundColor from parent Box

Fixes:
- drawBorder applies backgroundColor (and borderColor) to border chars
- Filter out undefined props before merging in renderTextWithInlineStyles
- Pass inheritedBg through the paint tree to text nodes

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Yunfei He
2026-05-25 11:11:54 +08:00
parent e850cb15ee
commit 8e6c4c5c2b
4 changed files with 75 additions and 12 deletions
@@ -0,0 +1,47 @@
import chalk from "chalk";
import { afterEach, beforeEach, expect, test } from "vite-plus/test";
import { render } from "@vue-tui/testing";
import { Box, Text } from "@vue-tui/runtime";
const BG_BLUE = "\x1b[44m";
let prevLevel: typeof chalk.level;
beforeEach(() => {
prevLevel = chalk.level;
chalk.level = 1;
});
afterEach(() => {
chalk.level = prevLevel;
});
test("Box backgroundColor produces ANSI background codes", async () => {
const { frames } = await render(
() => <Box backgroundColor="blue" width={5} height={1} />,
{ columns: 10 },
);
expect(frames.at(-1)).toContain(BG_BLUE);
});
test("Box backgroundColor survives border rendering", async () => {
const { frames } = await render(
() => <Box backgroundColor="blue" borderStyle="single" width={6} height={3} />,
{ columns: 10 },
);
const raw = frames.at(-1)!;
expect(raw).toContain(BG_BLUE);
expect(raw).toContain("┌");
});
test("child Text inherits backgroundColor from parent Box", async () => {
const { frames } = await render(
() => (
<Box backgroundColor="blue" width={10} height={1}>
<Text>hello</Text>
</Box>
),
{ columns: 20 },
);
const raw = frames.at(-1)!;
expect(raw).toContain("hello");
expect(raw).toContain(BG_BLUE);
});
+1
View File
@@ -12,6 +12,7 @@
"@vitejs/plugin-vue-jsx": "catalog:",
"@vue-tui/runtime": "workspace:*",
"@vue-tui/testing": "workspace:*",
"chalk": "catalog:",
"typescript": "^6.0.3",
"vite-plus": "^0.1.20",
"vue": "^3.4.0"