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