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-2/

Terminal Column Formatter

Build a command-line utility that formats text output for terminal display with configurable column widths.

Problem

Create a text formatting utility that accepts terminal output (which may include colored text) and reformats it to fit within a specified column width. The utility should handle both plain text and styled terminal output correctly.

Requirements

Your solution must:

  1. Accept text input that may contain terminal styling codes
  2. Reformat the text to fit within a specified column width
  3. Preserve all text styling in the reformatted output
  4. Handle text wrapping intelligently at word boundaries
  5. Calculate column width based on visible characters, not including styling codes

Input Format

The utility should accept:

  • A text string (may contain ANSI escape sequences for colors/styles)
  • A target column width (positive integer)

Output Format

Return the reformatted text as a string with:

  • Lines wrapped to fit within the specified column width
  • Original styling preserved
  • Newlines inserted where text wraps

Test Cases

  • When given plain text "The quick brown fox jumps over the lazy dog" with column width 20, the output wraps to produce lines no longer than 20 visible characters, breaking at word boundaries @test
  • When given text containing ANSI color codes "Hello \u001b[31mred\u001b[39m world" with column width 10, the output wraps based on visible character count (ignoring ANSI codes) while preserving all color codes @test
  • When given text "Short" with column width 50, the output remains as "Short" without modification @test

Implementation

@generates

API

/**
 * Formats text to fit within specified column width
 * @param {string} text - Input text (may contain ANSI codes)
 * @param {number} columns - Target column width
 * @returns {string} Formatted text with line breaks
 */
function formatText(text, columns) {
  // Implementation here
}

module.exports = { formatText };

Dependencies { .dependencies }

wrap-ansi { .dependency }

Provides text wrapping with ANSI escape code support.

Version

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