-
-
Notifications
You must be signed in to change notification settings - Fork 42
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
Implement an ANSI-aware string truncation function #22
Conversation
Just noticed a small correction needed on one of my comments; I’ll fix that up in the morning. |
Alright, corrected. Let me know you if you have any thoughts or questions. |
Closing as I'm noticing some odd behavior with this. I'll reopen should I sort the issue out. |
Fixed the odd behavior by adding a reset sequence after performing a truncation. Working great on my end now. |
We should probably also move this into a separate package and provide a writer, as we do for the other operations. I can try to do it this weekend, unless one of you feels up for the task. I hear @kiyonlin has a bit of a routine going at this point 😉 |
@muesli No problem, I can move them into a separate package after this PR is done. But the |
Correct, that sounds reasonable. Thank you @kiyonlin! |
There are still some test cases I'd like to write, but I've otherwise reworked the truncation function using Truncate in mattn/runewidth as a model. |
Thank you @meowgorithm, @kiyonlin! Merged and ready to be extracted into a separate package! |
Tests are also included. Also, I haven't implemented this on
Buffer
yet.I abstracted out the code for detecting ANSI start and end sequences for sake of reuse, which impacts performance very slightly (thanks @kiyonlin for the benchmarking tests). We could instead manually inline that function if we wanted for a slight performance boost.
This closes #21.