chalk / slice-ansi

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

supports fullwidth characters & not specified end #29

Closed sgtrusty closed 4 years ago

sgtrusty commented 4 years ago

Might need some cost-efficiency evaluation to be done. Also, I suggest one of the following libraries to be considered for future revisions:

This, of course, seeing how they are taking into account ISO standards relating to special characters readability and usability. Hope it works now.

P.S.: I looked at the previously cancelled pull, and made sure the tests complied. Hope it works.


IssueHunt Summary ### Referenced issues This pull request has been submitted to: - [#26: Lose characters when fullwidth characters exist and end is not specified](https://issuehunt.io/repos/43191689/issues/26) --- IssueHunt has been backed by the following sponsors. [Become a sponsor](https://issuehunt.io/membership/members)
sindresorhus commented 4 years ago

You need to add tests.

sgtrusty commented 4 years ago

I am sorry I am not very capable with Travis CI ... I am fixing its issues and I will commit again. Hoping I can reclaim the bounty. Thanks @sindresorhus

sindresorhus commented 4 years ago

You don't need Travis to run the tests. Just run npm test locally on your machine.

sgtrusty commented 4 years ago

All done, please check it out again, thanks.

sgtrusty commented 4 years ago

I have been busy lately, but I will do these changes asap. Thanks.

sgtrusty commented 4 years ago

1 test failed 1 known failure

does not lose fullwidth characters

main

C:\Users\s84136469\Desktop\huawei\system\nda\slice-ansi\test.js:32

31: t.is(util.inspect(sliceAnsi(fixture, 0, 10)), a); 32: t.is(util.inspect(sliceAnsi(fixture, 10, 20)), b); 33: t.is(util.inspect(sliceAnsi(fixture, 3, 20)), c);

Difference:

  • '\'\u001b[94mbrown \u001b[39m\u001b[36mfox \u001b[39m\''
  • '\'\u001b[34mbrown \u001b[39m\u001b[36mfox \u001b[39m\''

npm ERR! Test failed. See above for more details.

For some reason this stopped working when npm test'ing... I had to delete my working directory and re-clone it for practice, and then when I retried the procedures (even with current chalk/slice-ansi) sources, it is returning error. Anybody got a clue? I can just do the necessary fixes and re-up, and probably get the necessary approval from Travis, but I am curious. Thanks.

sgtrusty commented 4 years ago

@TiagoDanin @Qix- please check it out guys, and let me know if anything is missing, so that I may recover the bounty. Thanks :)

sindresorhus commented 4 years ago

I just noticed that there are two PR solving the same thing. https://github.com/chalk/slice-ansi/pull/27 was opened a month before this one, so that's the one I'm going with.

sgtrusty commented 4 years ago

@sindresorhus My solutions fixes https://github.com/chalk/slice-ansi/pull/27#issuecomment-533754972 though. Thanks anyway.

sindresorhus commented 4 years ago

But as commented later on, that’s not a bug. We intentionally do not support that. If that should change, it should be discussed in an issue first.