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

FR: Allow specifying tail for truncate_* template functions #5085

Open
zx8 opened this issue Dec 12, 2024 · 2 comments
Open

FR: Allow specifying tail for truncate_* template functions #5085

zx8 opened this issue Dec 12, 2024 · 2 comments
Labels
good first issue Good for newcomers polish🪒🐃 Make existing features more convenient and more consistent

Comments

@zx8
Copy link

zx8 commented Dec 12, 2024

Describe the solution you'd like

This is a very minor nice-to-have, but would it be possible to add an optional tail to the truncate_* template functions, to indicate that truncation has occurred? Sometimes truncation occurs at a space character, and it's not obvious that there was a longer description available.

Describe alternatives you've considered

Currently, it's possible to do something like:

if(
  description.first_line().substr(0, 80).starts_with(description.first_line()),
  pad_end(80, description.first_line()),
  truncate_end(79, description.first_line()) ++ "…"
)

(After #5072 is released, I can replace this workaround with a length check)

@PhilipMetzger PhilipMetzger added good first issue Good for newcomers polish🪒🐃 Make existing features more convenient and more consistent labels Dec 12, 2024
@yuja
Copy link
Contributor

yuja commented Dec 13, 2024

fwiw, I would call the parameter as ellipsis or something, than fill_char. It shouldn't be repeated to fill the remaining space.

@zx8
Copy link
Author

zx8 commented Dec 13, 2024

https://docs.rs/console/latest/console/fn.truncate_str.html calls it tail - I think that's probably a better fit. Title updated.

@zx8 zx8 changed the title FR: Allow specifying fill_char for truncate_* template functions FR: Allow specifying tail for truncate_* template functions Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers polish🪒🐃 Make existing features more convenient and more consistent
Projects
None yet
Development

No branches or pull requests

3 participants