-
-
Notifications
You must be signed in to change notification settings - Fork 132
Implement measure_text_width with no allocation #246
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
Conversation
3d9295a to
7329c4b
Compare
7329c4b to
c47485b
Compare
djc
left a comment
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.
Thanks, this mostly looks good!
src/utils.rs
Outdated
| .filter(|(_, is_ansi)| !is_ansi) | ||
| .map(|(sub, _)| str_width(sub)) |
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.
Nit: suggest spelling it like this:
.filter_map(|(s, is_ansi)| (!is_ansi).then(|| str_width(s)))
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.
I find it less readable, but that's your project 👍
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.
Actuallyyyy, clippy doesn't like it either! 🤓
https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_bool_then
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.
Fair enough. In that case, I'd like it to be written like this (assuming clippy is okay with it):
.filter_map(|(s, is_ansi)| match is_ansi {
false => Some(str_width(s)),
true => None,
})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.
Clippy is okay with that 👍
c47485b to
0b56d9c
Compare
|
I'll investigate on why the tests fails later, I start to realy suspects some behavior change in unicode_width (I know this sounds cliché but it worked on my computer 😢) |
I implemented that while working on optimizing something I don't remember, it might still be useful.
83970ac to
7a4ad64
Compare
|
Tests are fixed. This was just a rooky mistake of forgetting to put |
|
Nice, thanks! |
Bumps console from 0.15.11 to 0.16.1. Release notes Sourced from console's releases. 0.16.1 What's Changed Add WithoutAnsi struct that implements Display by @ChocolateLoverRaj in console-rs/console#258 Tweak style for new WithAnsi code by @djc in console-rs/console#266 Fix QNX 7.1 patch for libc::cfmakeraw by @rafaeling in console-rs/console#267 Upgrade windows-sys to 0.61 by @djc in console-rs/console#272 0.16.0 What's Changed The 0.15.12 release was yanked after it turned out to be semver-incompatible with existing usage by several of the most popular dependent crates, because it introduced a std feature -- and those crates used default-features = false but relied on the std-guarded features. The 0.16.0 API should be semver-compatible with the 0.15.x API except for the need for the std feature. Prepare 0.16.0 by @djc in console-rs/console#265 Refer to the 0.15.12 release notes for more information. 0.15.12 What's Changed Use EnumSet instead of a full-blown btreemap for the attributes by @jwiesler in console-rs/console#244 Tweak Attributes bit set API by @djc in console-rs/console#245 Implement measure_text_width with no allocation by @remi-dupre in console-rs/console#246 fix(utils): surprising behavior in truncate_str when tail is larger than width by @remi-dupre in console-rs/console#250 fix spelling mistake by @Axlefublr in console-rs/console#253 feat(part): add NO_COLOR env support for windows terminal by @L-Chao in console-rs/console#254 Update windows-sys requirement from 0.59 to 0.60 by @dependabot in console-rs/console#259 Add features to work with no_std, and with alloc in no_std by @ChocolateLoverRaj in console-rs/console#256 Fix CI badge and license URL by @atouchet in console-rs/console#261 Bump version to 0.15.12 by @felstead in console-rs/console#262 Commits f35b2e4 Bump version to 0.16.1 900379f Upgrade windows-sys to 0.61 174b8a4 Bump MSRV to 1.71 (for windows-sys 0.61) 208928e Fix lint warning for elided lifetimes a51fcea Fix QNX patch for libc::cfmakeraw 90ea08d Tweak style for new WithAnsi code 903df6d Add WithoutAnsi struct that implements Display bda6a6e Add FUNDING metadata 87ace80 Remove authors from Cargo metadata (per RFC 3052) 6e30bfd Bump version to 0.16.0 Additional commits viewable in compare view Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase. Dependabot commands and options You can trigger Dependabot actions by commenting on this PR: @dependabot rebase will rebase this PR @dependabot recreate will recreate this PR, overwriting any edits that have been made to it @dependabot merge will merge this PR after your CI passes on it @dependabot squash and merge will squash and merge this PR after your CI passes on it @dependabot cancel merge will cancel a previously requested merge and block automerging @dependabot reopen will reopen this PR if it is closed @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually @dependabot show <dependency name> ignore conditions will show all of the ignore conditions of the specified dependency @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
I implemented that while working on optimizing something I don't remember, it might still be useful.
Also, I noticed that the test for this function was wrong when only using the
unicode-widthfeature (probably due to some update in the corresponding?).I've completed the Makefile so that all possible sets of feature are tested, as the project is not too big I don't think it's too heavy.