mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-17 08:00:59 +00:00
Merge branch 'pr-457-wrap-whitespace'
This commit is contained in:
commit
60ec863354
2 changed files with 20 additions and 4 deletions
|
|
@ -498,7 +498,7 @@ function wrapSingleLine(line: string, width: number): string[] {
|
||||||
const totalNeeded = currentVisibleLength + tokenVisibleLength;
|
const totalNeeded = currentVisibleLength + tokenVisibleLength;
|
||||||
|
|
||||||
if (totalNeeded > width && currentVisibleLength > 0) {
|
if (totalNeeded > width && currentVisibleLength > 0) {
|
||||||
// Add specific reset for underline only (preserves background)
|
// Trim trailing whitespace, then add underline reset (not full reset, to preserve background)
|
||||||
let lineToWrap = currentLine.trimEnd();
|
let lineToWrap = currentLine.trimEnd();
|
||||||
const lineEndReset = tracker.getLineEndReset();
|
const lineEndReset = tracker.getLineEndReset();
|
||||||
if (lineEndReset) {
|
if (lineEndReset) {
|
||||||
|
|
@ -527,7 +527,8 @@ function wrapSingleLine(line: string, width: number): string[] {
|
||||||
wrapped.push(currentLine);
|
wrapped.push(currentLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
return wrapped.length > 0 ? wrapped : [""];
|
// Trailing whitespace can cause lines to exceed the requested width
|
||||||
|
return wrapped.length > 0 ? wrapped.map((line) => line.trimEnd()) : [""];
|
||||||
}
|
}
|
||||||
|
|
||||||
const PUNCTUATION_REGEX = /[(){}[\]<>.,;:'"!?+\-=*/\\|&%^$#@~`]/;
|
const PUNCTUATION_REGEX = /[(){}[\]<>.,;:'"!?+\-=*/\\|&%^$#@~`]/;
|
||||||
|
|
|
||||||
|
|
@ -12,14 +12,24 @@ describe("wrapTextWithAnsi", () => {
|
||||||
|
|
||||||
const wrapped = wrapTextWithAnsi(text, 40);
|
const wrapped = wrapTextWithAnsi(text, 40);
|
||||||
|
|
||||||
// First line should NOT contain underline code - it's just "read this thread "
|
// First line should NOT contain underline code - it's just "read this thread"
|
||||||
assert.strictEqual(wrapped[0], "read this thread ");
|
assert.strictEqual(wrapped[0], "read this thread");
|
||||||
|
|
||||||
// Second line should start with underline, have URL content
|
// Second line should start with underline, have URL content
|
||||||
assert.strictEqual(wrapped[1].startsWith(underlineOn), true);
|
assert.strictEqual(wrapped[1].startsWith(underlineOn), true);
|
||||||
assert.ok(wrapped[1].includes("https://"));
|
assert.ok(wrapped[1].includes("https://"));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should not have whitespace before underline reset code", () => {
|
||||||
|
const underlineOn = "\x1b[4m";
|
||||||
|
const underlineOff = "\x1b[24m";
|
||||||
|
const textWithUnderlinedTrailingSpace = `${underlineOn}underlined text here ${underlineOff}more`;
|
||||||
|
|
||||||
|
const wrapped = wrapTextWithAnsi(textWithUnderlinedTrailingSpace, 18);
|
||||||
|
|
||||||
|
assert.ok(!wrapped[0].includes(` ${underlineOff}`));
|
||||||
|
});
|
||||||
|
|
||||||
it("should not bleed underline to padding - each line should end with reset for underline only", () => {
|
it("should not bleed underline to padding - each line should end with reset for underline only", () => {
|
||||||
const underlineOn = "\x1b[4m";
|
const underlineOn = "\x1b[4m";
|
||||||
const underlineOff = "\x1b[24m";
|
const underlineOff = "\x1b[24m";
|
||||||
|
|
@ -101,6 +111,11 @@ describe("wrapTextWithAnsi", () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should truncate trailing whitespace that exceeds width", () => {
|
||||||
|
const twoSpacesWrappedToWidth1 = wrapTextWithAnsi(" ", 1);
|
||||||
|
assert.ok(visibleWidth(twoSpacesWrappedToWidth1[0]) <= 1);
|
||||||
|
});
|
||||||
|
|
||||||
it("should preserve color codes across wraps", () => {
|
it("should preserve color codes across wraps", () => {
|
||||||
const red = "\x1b[31m";
|
const red = "\x1b[31m";
|
||||||
const reset = "\x1b[0m";
|
const reset = "\x1b[0m";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue