From bfc9d4b25a3565ff721c717b24ee7a22c58f3f69 Mon Sep 17 00:00:00 2001 From: Charles Packer Date: Tue, 10 Mar 2026 21:08:24 -0700 Subject: [PATCH] fix(tui): trim leading space on word-wrapped continuation lines (#1346) Co-authored-by: Letta Code --- scripts/postinstall-patches.js | 1 + vendor/ink/build/wrap-text.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 vendor/ink/build/wrap-text.js diff --git a/scripts/postinstall-patches.js b/scripts/postinstall-patches.js index 1684d7a..2f1e5b9 100644 --- a/scripts/postinstall-patches.js +++ b/scripts/postinstall-patches.js @@ -101,6 +101,7 @@ await copyToResolved( ); await copyToResolved("vendor/ink/build/devtools.js", "ink/build/devtools.js"); await copyToResolved("vendor/ink/build/log-update.js", "ink/build/log-update.js"); +await copyToResolved("vendor/ink/build/wrap-text.js", "ink/build/wrap-text.js"); // ink-text-input (optional vendor with externalCursorOffset support) await copyToResolved( diff --git a/vendor/ink/build/wrap-text.js b/vendor/ink/build/wrap-text.js new file mode 100644 index 0000000..9ccb81c --- /dev/null +++ b/vendor/ink/build/wrap-text.js @@ -0,0 +1,31 @@ +import wrapAnsi from 'wrap-ansi'; +import cliTruncate from 'cli-truncate'; +const cache = {}; +const wrapText = (text, maxWidth, wrapType) => { + const cacheKey = text + String(maxWidth) + String(wrapType); + const cachedText = cache[cacheKey]; + if (cachedText) { + return cachedText; + } + let wrappedText = text; + if (wrapType === 'wrap') { + wrappedText = wrapAnsi(text, maxWidth, { + trim: true, + hard: true, + }); + } + if (wrapType.startsWith('truncate')) { + let position = 'end'; + if (wrapType === 'truncate-middle') { + position = 'middle'; + } + if (wrapType === 'truncate-start') { + position = 'start'; + } + wrappedText = cliTruncate(text, maxWidth, { position }); + } + cache[cacheKey] = wrappedText; + return wrappedText; +}; +export default wrapText; +//# sourceMappingURL=wrap-text.js.map \ No newline at end of file