tessl install tessl/npm-wrap-ansi@9.0.0Wordwrap a string with ANSI escape codes
Agent Success
Agent success rate when using this tile
100%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.04x
Baseline
Agent success rate without this tile
96%
Build a text formatter that wraps styled terminal text while providing precise control over whitespace handling.
Your formatter should wrap text to fit within a specified column width. The key requirement is to provide users with control over how leading and trailing whitespace is handled on wrapped lines.
Implement two whitespace handling modes:
The formatter must correctly handle text containing terminal styling codes (ANSI escape sequences) - these should not affect width calculations or be removed during wrapping.
When text wraps across multiple lines:
Single-line text (text that fits within the column width without wrapping) should maintain its original formatting regardless of mode.
@generates
/**
* Wraps text to specified column width with configurable whitespace handling
* @param {string} text - The text to wrap (may contain ANSI styling codes)
* @param {number} columns - Maximum column width
* @param {object} options - Configuration options
* @param {boolean} options.preserveWhitespace - If true, preserve all whitespace; if false (default), trim whitespace from wrapped lines
* @returns {string} The wrapped text
*/
function formatText(text, columns, options) {
// Implementation here
}
module.exports = { formatText };Provides text wrapping with ANSI escape code support.
@satisfied-by