-
Notifications
You must be signed in to change notification settings - Fork 113
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
Add utility function ansi::slice_ansi_str
#206
base: master
Are you sure you want to change the base?
Conversation
I also took my chance and suggested an non-allocating version of measure_text_width.
3811bcc
to
3324138
Compare
@@ -56,7 +56,7 @@ pub fn terminal_size(out: &Term) -> Option<(u16, u16)> { | |||
#[allow(clippy::useless_conversion)] | |||
libc::ioctl(out.as_raw_fd(), libc::TIOCGWINSZ.into(), &mut winsize); | |||
if winsize.ws_row > 0 && winsize.ws_col > 0 { | |||
Some((winsize.ws_row as u16, winsize.ws_col as u16)) | |||
Some((winsize.ws_row, winsize.ws_col)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was just a random (new?) clippy lint : these are already u16 🤷
AnsiCodeIterator::new(s) | ||
.filter(|(_, is_ansi)| !is_ansi) | ||
.map(|(sub, _)| str_width(sub)) | ||
.sum() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to the MR, but while implementing a less optimized draft of my fix I thought this could spare a few allocs. This is probably not something to care about so I wouldn't mind if you want to revert this for the sake of simplification.
19d8f2d
to
0f33b85
Compare
0f33b85
to
ce77cc5
Compare
This new implementation also has the benefit of allocating at most once.
ansi::slice_ansi_str
ansi::slice_ansi_str
Can you avoid |
Indeed, that should be good now 👍 |
And format is also a recent-is feature, on it 😬 I'll try to build on 1.56, it didn't work last time I tried it because it fails to resolve EDIT : Ok, got it |
Should be good, |
Hi!
While working on a bug of
indicatif
(cf. console-rs/indicatif#627), I needed an ANSI-aware slicing method. I think it made more sense to add it in this crate.I made this quite similar to
truncate_str
, which enables code reuse 😊I also suggested a non-allocating implementation for
measure_text_width
🤷