Wordwrap a string with ANSI escape codes
Overall
score
100%
Build a terminal text formatting utility that wraps styled text while preserving various types of terminal control codes.
Your utility should wrap text to a specified column width while correctly handling different types of terminal escape sequences. The function should:
\u001B[31m for red color, \u001B[39m to reset)\u001B]8;;URL\u0007text\u001B]8;;\u0007)Escape sequences should not count toward the column width - only visible characters should be measured. When text wraps to multiple lines, active styling should continue correctly across line breaks.
"\u001B[31mred text here\u001B[39m" at width 8 preserves red color codes across wrapped lines @test"\u001B]8;;https://example.com\u0007click here\u001B]8;;\u0007" at width 6 maintains clickable link across "click" and "here" on separate lines @test@generates
/**
* Wraps text to specified column width while preserving terminal escape sequences.
*
* @param {string} text - The text to wrap, may contain ANSI escape codes
* @param {number} columns - Maximum column width for wrapping
* @returns {string} Wrapped text with preserved escape sequences
*/
function formatText(text, columns) {
// Implementation here
}
module.exports = { formatText };Provides text wrapping with ANSI escape code support.
@satisfied-by
Install with Tessl CLI
npx tessl i tessl/npm-wrap-ansidocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10