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 terminal status display formatter that handles styled terminal output. The formatter should correctly wrap status messages containing colors and styling to fit within specified column widths while maintaining proper visual alignment.
Create a module that formats status messages for terminal display with the following capabilities:
Implement a function that formats status messages with the following behavior:
The formatter must correctly calculate visual width:
formatStatusMessage(message, columnWidth)Parameters:
message (string): Status message that may contain ANSI escape codescolumnWidth (number): Maximum number of visible columns per lineReturns:
File: formatter.test.js
import { formatStatusMessage } from './formatter.js';
// Basic styled message wrapping
const message = '\x1b[32mSuccess:\x1b[0m Operation completed successfully and all systems are operational';
const result = formatStatusMessage(message, 30);
// Should wrap at word boundaries while preserving color codes
// Expected output spans multiple lines, no line exceeds 30 visible characters
console.assert(result.includes('\n'), 'Output should contain line breaks');
console.assert(result.includes('\x1b[32m'), 'Output should preserve color codes');File: formatter.test.js
import { formatStatusMessage } from './formatter.js';
// Message with multiple ANSI codes
const message = '\x1b[1m\x1b[33mWarning:\x1b[0m The \x1b[4mconfiguration file\x1b[0m was not found';
const result = formatStatusMessage(message, 25);
// Should preserve bold, yellow, and underline codes
console.assert(result.includes('\x1b[1m'), 'Output should preserve bold');
console.assert(result.includes('\x1b[33m'), 'Output should preserve yellow');
console.assert(result.includes('\x1b[4m'), 'Output should preserve underline');File: formatter.test.js
import { formatStatusMessage } from './formatter.js';
// Message with a very long word
const message = '\x1b[31mError:\x1b[0m FileNotFoundException in /very/long/path/to/configuration/file.json';
const result = formatStatusMessage(message, 20);
// Should break long words that exceed column width
const lines = result.split('\n');
console.assert(lines.every(line => {
// Remove ANSI codes for width check
const visibleText = line.replace(/\x1b\[[0-9;]*m/g, '');
return visibleText.length <= 20;
}), 'No line should exceed 20 visible characters');Provides text wrapping with ANSI escape code support.