fix(tui): wrap CJK text at grapheme boundaries

closes #5495
This commit is contained in:
Mario Zechner
2026-06-09 12:51:27 +02:00
parent def99d395e
commit 8da077bcca
3 changed files with 75 additions and 16 deletions

View File

@@ -111,6 +111,30 @@ describe("wrapTextWithAnsi", () => {
}
});
it("should break CJK runs at grapheme boundaries after Latin text", () => {
const text = "This is an example 中文汉字测试段落内容中文汉字测试段落内容.";
const wrapped = wrapTextWithAnsi(text, 40);
assert.deepStrictEqual(wrapped, ["This is an example 中文汉字测试段落内容", "中文汉字测试段落内容."]);
for (const line of wrapped) {
assert.ok(visibleWidth(line) <= 40);
}
});
it("should preserve color codes when wrapping CJK runs", () => {
const red = "\x1b[31m";
const reset = "\x1b[0m";
const text = `${red}This is an example 中文汉字测试段落内容中文汉字测试段落内容.${reset}`;
const wrapped = wrapTextWithAnsi(text, 40);
assert.strictEqual(wrapped.length, 2);
assert.strictEqual(wrapped[0], `${red}This is an example 中文汉字测试段落内容`);
assert.strictEqual(wrapped[1], `${red}中文汉字测试段落内容.${reset}`);
for (const line of wrapped) {
assert.ok(visibleWidth(line) <= 40);
}
});
it("should ignore OSC 133 semantic markers in visible width", () => {
const text = "\x1b]133;A\x07hello\x1b]133;B\x07";
assert.strictEqual(visibleWidth(text), 5);