chalk / slice-ansi

Slice a string with ANSI escape codes
MIT License
47 stars 21 forks source link

Fails with strings styled with background and foreground #22

Closed slammayjammay closed 4 years ago

slammayjammay commented 5 years ago

Issuehunt badges

PR for a demo test: #21

Looks like slicing a string styled with background and foreground colors fails.

const str = chalk.bgGreen.black('test');
// => '\u001b[42m\u001b[30mtest\u001b[39m\u001b[49m'

const sliced = sliceAnsi(str, 0, 1);
// => '\u001b[42m\u001b[30mt\u001b[39m'

const full = sliceAnsi(str, 0, 4)
// => '\u001b[42m\u001b[30mtest\u001b[39m\u001b[49m'

I'm not super familiar with ansi escape sequences but it looks like sliced is missing the part that ends the bgGreen color, '\u001b[49m'.


Failing test:

https://github.com/chalk/slice-ansi/blob/67699dedbdf3bbe7b05678bf3665baab8f62d9c4/test.js#L61-L65


IssueHunt Summary #### [tiagodanin tiagodanin](https://issuehunt.io/u/tiagodanin) has been rewarded. ### Backers (Total: $60.00) - [issuehunt issuehunt](https://issuehunt.io/u/issuehunt) ($60.00) ### Submitted pull Requests - [#25 [WIP] Get all ansi escape sequences](https://issuehunt.io/r/chalk/slice-ansi/pull/25) --- ### Tips - Checkout the [Issuehunt explorer](https://issuehunt.io/r/chalk/slice-ansi/) to discover more funded issues. - Need some help from other developers? [Add your repositories](https://issuehunt.io/r/new) on IssueHunt to raise funds. --- IssueHunt has been backed by the following sponsors. [Become a sponsor](https://issuehunt.io/membership/members)
IssueHuntBot commented 5 years ago

@issuehunt has funded $60.00 to this issue.


issuehunt-oss[bot] commented 4 years ago

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