chalk / wrap-ansi

Wordwrap a string with ANSI escape codes
MIT License
120 stars 25 forks source link

Indented text within input (discussion?) #16

Closed imhoffd closed 7 years ago

imhoffd commented 7 years ago

I have a question on some behavior I've noticed with text within long input strings containing newlines.

const chalk = require('chalk');
const wrapAnsi = require('wrap-ansi');

const input = `
The quick brown ${chalk.red('fox jumped over')} the lazy ${chalk.green('dog and then ran away with the unicorn.')}

Afterwards, the fox quoted Shakespeare:

    "If music be the food of love, play on."

`.trim();

console.log(wrapAnsi(input, 20));

image

I guess I would expect the whitespace (multiple spaces, tabs) to be maintained. That, however, may be outside the scope of this module. (What to do when the indented sentence is wrapped?--Are the subsequent lines of the indented sentence indented or not indented?)

One might say the burden is on the caller. Input should be split on newlines and word wrapped individually and re-concatenated. One might also call this a bug of wrap-ansi.

This may open a discussion for the availability of a higher-level module that has options for parsing and wrapping complex bodies of text, instead of simply expecting single sentences.

SamVerschueren commented 7 years ago

Is this what you'd expect it to be?

screen shot 2017-07-23 at 12 48 07

Because then it's a duplicate of #9 and it will be fixed by PR #17.

imhoffd commented 7 years ago

It is. Thanks!