fix(tui): mapped empty-string ellipsis argument to Ellipsis.Omit
- Updated truncateToWidth to map a string ellipsis of "" to Ellipsis.Omit. - Added a regression test for issue #848 to verify empty-string ellipsis produces a plain truncation result.
This commit is contained in:
@@ -28,7 +28,17 @@ export function truncateToWidth(
|
||||
// and `maxWidth` is a required `u32` that throws on `null`/`undefined`
|
||||
// everywhere. Pass concrete defaults that mirror the Rust `unwrap_or`s.
|
||||
const safeWidth = Number.isFinite(maxWidth) ? Math.max(0, Math.trunc(maxWidth)) : 0;
|
||||
return nativeTruncateToWidth(text, safeWidth, ellipsisKind ?? Ellipsis.Unicode, pad ?? false, getDefaultTabWidth());
|
||||
let resolvedEllipsis: Ellipsis | null | undefined | string = ellipsisKind;
|
||||
if (typeof resolvedEllipsis === "string") {
|
||||
resolvedEllipsis = resolvedEllipsis === "" ? Ellipsis.Omit : Ellipsis.Unicode;
|
||||
}
|
||||
return nativeTruncateToWidth(
|
||||
text,
|
||||
safeWidth,
|
||||
resolvedEllipsis ?? Ellipsis.Unicode,
|
||||
pad ?? false,
|
||||
getDefaultTabWidth(),
|
||||
);
|
||||
}
|
||||
|
||||
export function wrapTextWithAnsi(text: string, width: number): string[] {
|
||||
|
||||
@@ -26,6 +26,10 @@ describe("issue #848: truncateToWidth wrapper rejects nullish napi inputs", () =
|
||||
expect(result).toBe("hello world");
|
||||
});
|
||||
|
||||
it("maps a legacy empty-string ellipsis argument to omit ellipsis", () => {
|
||||
const result = truncateToWidth("hello world", 5, "" as unknown as Parameters<typeof truncateToWidth>[2]);
|
||||
expect(result).toBe("hello");
|
||||
});
|
||||
it("returns a string when ellipsisKind / pad are undefined", () => {
|
||||
const result = truncateToWidth("hello world", 80, undefined, undefined);
|
||||
expect(typeof result).toBe("string");
|
||||
|
||||
Reference in New Issue
Block a user