-
Notifications
You must be signed in to change notification settings - Fork 2.4k
fix: Refactor string truncation logic into reusable utility function to avoid panic (#2818) #2819
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
cgwalters
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.
I'm not a maintainer here, just doing a drive by review since I recently submitted a different PR.
| if s.chars().count() <= max_chars { | ||
| s.to_string() | ||
| } else { | ||
| let truncated: String = s.chars().take(max_chars.saturating_sub(3)).collect(); | ||
| format!("{}...", truncated) | ||
| } |
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.
Totally fine as is, just a note this walks the string twice. Hopefully we aren't passing large file data here anyways.
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 also came across https://doc.rust-lang.org/std/primitive.str.html#method.floor_char_boundary which is exactly what we want here, but yeah still experimental.
Extract repeated string truncation code from project.rs and session.rs into a new utils module with safe_truncate function. Also fix trailing whitespace in configure.rs. Signed-off-by: toyamagu2021 <[email protected]>
Signed-off-by: toyamagu2021 <[email protected]>
|
@jamadeo Sorry, I've fixed lint error. |
Signed-off-by: toyamagu2021 <[email protected]>
|
I've forgotten picking up #3243 🙏 ➜ ./bin/cargo clippy
Checking goose-cli v1.0.31 (/Users/tomoki-yamaguchi/github.com/toyamagu-2021/goose/crates/goose-cli)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 5.57s |
jamadeo
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 @toyamagu-2021, looks great.
* main: feat(goose-cli): theme persistence & selection (#1693) chore(release): release version 1.0.32 (#3248) Add fuzzy file search functionality (#3240) update styling of user messages (#3247) Add support for escape key to dismiss settings menu (#3225) fix: Refactor string truncation logic into reusable utility function to avoid panic (#2818) (#2819) fix: Prevent modal from closing on text select. (#3127) fix: Add back lazy_static (#3243) chore: remove unused dependencies (#3049) feat: Add close button (X) to toast notifications (#3197) Adds json schema validation to goose recipe validate cli (#3234)
…to avoid panic (block#2818) (block#2819) Signed-off-by: toyamagu2021 <[email protected]> Signed-off-by: Adam Tarantino <[email protected]>
…to avoid panic (block#2818) (block#2819) Signed-off-by: toyamagu2021 <[email protected]> Signed-off-by: Soroosh <[email protected]>
…to avoid panic (block#2818) (block#2819) Signed-off-by: toyamagu2021 <[email protected]> Signed-off-by: Kyle Santiago <[email protected]>
…to avoid panic (block#2818) (block#2819) Signed-off-by: toyamagu2021 <[email protected]>
Closes #2818
Motivation
Extract repeated string truncation code from project.rs and session.rs into a new utils module with safe_truncate function.
Also fix trailing
whitespace in configure.rs.
Verification
goose psworks well.Signed-off-by: toyamagu2021 [email protected]