Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slice fails when ANSI string and ordinary string are mixed #14

Closed
kjirou opened this issue Dec 15, 2017 · 7 comments · Fixed by #25
Closed

Slice fails when ANSI string and ordinary string are mixed #14

kjirou opened this issue Dec 15, 2017 · 7 comments · Fixed by #25
Labels
bug 🎁 Rewarded on Issuehunt This issue has been rewarded on Issuehunt help wanted

Comments

@kjirou
Copy link
Contributor

kjirou commented Dec 15, 2017

Issuehunt badges

Hello, the following behaviors looked like a bug.

node
> chalk = require('chalk')
> sliceAnsi = require('slice-ansi')
> str = 'a' + chalk.red('bc') + 'd'
'a\u001b[31mbc\u001b[39md'
> sliceAnsi(str, 0, 1) === 'a'
false  # I expected true
> sliceAnsi(str, 1, 2) === chalk.red('b')
true
> sliceAnsi(str, 2, 3) === chalk.red('c')
false  # I expected true
> sliceAnsi(str, 3, 4) === 'd'
false  # I expected true

As a supplement, the example described in the README appeared to be working properly.

node
> str2 = 'The quick brown ' + chalk.red('fox jumped over ') + 'the lazy ' + chalk.green('dog and then ran away with the unicorn.');
'The quick brown \u001b[31mfox jumped over \u001b[39mthe lazy \u001b[32mdog and then ran away with the unicorn.\u001b[39m'
> sliceAnsi(str2, 20, 30) === chalk.red('jumped ove')
true

Thanks.

Environments

  • node v6.8.0
  • chalk v2.3.0
  • slice-ansi v1.0.0

IssueHunt Summary

tiagodanin tiagodanin has been rewarded.

Backers (Total: $60.00)

Submitted pull Requests


Tips


IssueHunt has been backed by the following sponsors. Become a sponsor

@sindresorhus
Copy link
Member

Would you be able to submit a pull request with a failing test? :)

@kjirou
Copy link
Contributor Author

kjirou commented Dec 16, 2017

@sindresorhus Pull-requested!

@kjirou
Copy link
Contributor Author

kjirou commented Dec 20, 2017

Pull-requireted again with #16

@IssueHuntBot
Copy link

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

@sindresorhus
Copy link
Member

// @stroncium This one has a bounty too, in case you're interested ;)

@stroncium
Copy link

stroncium commented Mar 18, 2019

Haha, don't think of me as so materialistic. I actually don't think I will be able to even use bounties except
funding some more issues(don't think paypal will allow me to accept any money due to my country of residence).

Anyhow, I actually wrote all the code for this issue already. The problem is the code is much bigger than whole this library as it required implementing first proper escape sequence tokenizer, then a virtual machine to process SGR commands, compare states and a compiler of state changes to commands which introduce them, plus I'd like to also implement a few other escape sequences which would make sense in terms of string manipulations. I also reckon this code would allow to implement a much simpler and correct version of wrap-ansi too. So, I'm thinking what to do with this code now.

@issuehunt-oss issuehunt-oss bot added the 💵 Funded on Issuehunt This issue has been funded on Issuehunt label May 10, 2019
@issuehunt-oss
Copy link

issuehunt-oss bot commented Sep 17, 2019

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

  • 💰 Total deposit: $60.00
  • 🎉 Repository reward(0%): $0.00
  • 🔧 Service fee(10%): $6.00

@issuehunt-oss issuehunt-oss bot added 🎁 Rewarded on Issuehunt This issue has been rewarded on Issuehunt and removed 💵 Funded on Issuehunt This issue has been funded on Issuehunt labels Sep 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🎁 Rewarded on Issuehunt This issue has been rewarded on Issuehunt help wanted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants