Fix characters (#372)

* Fix cat command

* Fix text rendering crash from undefined code points in bash output

* Revert unintentional model parameter changes from fix cat command commit
This commit is contained in:
Mr. Rc 2026-01-01 06:46:29 +05:30 committed by GitHub
parent 46bb5dcde8
commit bbf23bd5f1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 40 additions and 9 deletions

View file

@ -4,6 +4,7 @@ import stringWidth from "string-width";
* Calculate the visible width of a string in terminal columns.
*/
export function visibleWidth(str: string): number {
if (!str) return 0;
const normalized = str.replace(/\t/g, " ");
return stringWidth(normalized);
}
@ -472,6 +473,9 @@ function breakLongWord(word: string, width: number, tracker: AnsiCodeTracker): s
}
const grapheme = seg.value;
// Skip empty graphemes to avoid issues with string-width calculation
if (!grapheme) continue;
const graphemeWidth = visibleWidth(grapheme);
if (currentWidth + graphemeWidth > width) {
@ -576,6 +580,9 @@ export function truncateToWidth(text: string, maxWidth: number, ellipsis: string
}
const grapheme = seg.value;
// Skip empty graphemes to avoid issues with string-width calculation
if (!grapheme) continue;
const graphemeWidth = visibleWidth(grapheme);
if (currentWidth + graphemeWidth > targetWidth) {