CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/npm-wrap-ansi

tessl install tessl/npm-wrap-ansi@9.0.0

Wordwrap 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%

task.mdevals/scenario-1/

Terminal Text Formatter with Style Preservation

Build a terminal text formatting utility that wraps styled text while preserving various types of terminal control codes.

Requirements

Your utility should wrap text to a specified column width while correctly handling different types of terminal escape sequences. The function should:

  1. Wrap plain text at word boundaries to fit within the specified column width
  2. Preserve SGR (Select Graphic Rendition) codes for colors and text styling (e.g., \u001B[31m for red color, \u001B[39m to reset)
  3. Preserve OSC 8 hyperlink sequences (format: \u001B]8;;URL\u0007text\u001B]8;;\u0007)
  4. Handle text containing multiple escape sequence types simultaneously

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.

Test Cases

  • Wrapping plain text "hello world" at width 6 returns "hello\nworld" @test
  • Wrapping "\u001B[31mred text here\u001B[39m" at width 8 preserves red color codes across wrapped lines @test
  • Wrapping text with hyperlink "\u001B]8;;https://example.com\u0007click here\u001B]8;;\u0007" at width 6 maintains clickable link across "click" and "here" on separate lines @test
  • Wrapping text with both red color and hyperlink at width 5 correctly preserves both SGR codes and OSC 8 sequences @test

Implementation

@generates

API

/**
 * 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 };

Dependencies { .dependencies }

wrap-ansi { .dependency }

Provides text wrapping with ANSI escape code support.

@satisfied-by

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/wrap-ansi@9.0.x
tile.json