fix: prevent last-char clipping on deferred-wrap terminals (#1079)

Co-authored-by: Letta <noreply@letta.com>
This commit is contained in:
jnjpng
2026-02-23 11:06:18 -08:00
committed by GitHub
parent 32b1a9e0c8
commit 33f4b4d299

View File

@@ -1,5 +1,6 @@
import ansiEscapes from 'ansi-escapes';
import cliCursor from 'cli-cursor';
import stringWidth from 'string-width';
const create = (stream, { showCursor = false } = {}) => {
let previousLineCount = 0;
@@ -7,8 +8,17 @@ const create = (stream, { showCursor = false } = {}) => {
let hasHiddenCursor = false;
const renderWithClearedLineEnds = (output) => {
// On some terminals, writing to the last column leaves the cursor in a
// deferred-wrap state where CSI K (Erase in Line) erases the character
// at the final column instead of being a no-op. Skip the erase for
// lines that already fill the terminal width — there is nothing beyond
// them to clean up.
const cols = stream.columns || 80;
const lines = output.split('\n');
return lines.map((line) => line + ansiEscapes.eraseEndLine).join('\n');
return lines.map((line) => {
if (stringWidth(line) >= cols) return line;
return line + ansiEscapes.eraseEndLine;
}).join('\n');
};
const render = (str) => {
@@ -60,4 +70,3 @@ const create = (stream, { showCursor = false } = {}) => {
const logUpdate = { create };
export default logUpdate;