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

Draft: added ansi slice function #105

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sukus21
Copy link
Contributor

@sukus21 sukus21 commented Jun 28, 2024

Re-apply features from #101, reopened per request from @aymanbagabas.

Original description:
Based on the truncate function.
Specify a start point (inclusive) and end point (exclusive) in cell-width units, and get a string back at that exact size.
Handles ansi-codes and multi-length characters.

@sukus21
Copy link
Contributor Author

sukus21 commented Jun 28, 2024

The reason I made this code in the first place, was in an attempt to recreate the example shown for Bubble Tea on the Charmbracelet website. While truncate can cut off the end of a string, I saw no code that could cut the beginning off a string. So I decided to make the Slice function.

As for the decision to pad with whitespace when splitting on wide characters, that was for my own usecase. I did not see the point of the user manually having to check if the character that was split on was wide, and them then having to insert padding themselves. That would mean essentially recreating the functionality of the Slice function, after it has already been called.
I am not trying to argue that this is the best solution, but it was the one that fit the use case I had in mind when writing it.

An alternative could be to let the user choose how wide characters are handled:

  • Include the wide character
  • Exclude the wide character
  • Pad the string with whitespace, to match expected length

@sukus21 sukus21 marked this pull request as draft June 28, 2024 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant