chalk / wrap-ansi

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

leading space removed when line starts with ansi escape #27

Closed also closed 5 years ago

also commented 6 years ago

Issuehunt badges

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

const s = chalk.bgGreen(` ${chalk.black('OK')} `);
console.log(s);
console.log(wrapAnsi(s, 100, { trim: false }));

screen shot 2018-03-27 at 1 34 18 pm

stroncium earned $60.00 by resolving this issue!

milesj commented 5 years ago

This is still an issue.

Qix- commented 5 years ago

@milesj we're aware. The ticket is still open.

milesj commented 5 years ago

@Qix- Maybe people forget after almost a year.

astoilkov commented 5 years ago

I am using log-update and experienced this issue there and tracked it up to here. Do you think this is an easy issue? I don't have any experience with the terminal or ansi but I can try to debug it in the future if it is easy.

IssueHuntBot commented 5 years ago

@issuehunt has funded $60.00 to this issue. See it on IssueHunt

ewwink commented 5 years ago

the input OK will converted into

\u001b[47m \u001b[30mOK\u001b[39m \u001b[49m'

Maybe we don't need to split [47m \u001b and [39m \u001b. Will splitting space but not followed by \u001b help?

line 82 .split(' ') become

.split(/\s(?!\u001b)/)

By using that regex the input OK GG or

\u001b[47m \u001b[30mOK GG\u001b[39m \u001b[49m

will be splitted into

\u001b[47m \u001b[30mOK
GG\u001b[39m \u001b[49m
IssueHuntBot commented 5 years ago

@sindresorhus has rewarded $54.00 to @stroncium. See it on IssueHunt