Replies: 1 comment 2 replies
-
I think you are talking about Note In this code you can remove the from rich.console import Console
console = Console()
long_string = "This is a really really really long string that needs to be truncated"
# Taking the last 30 characters
truncated_start = long_string[-30:]
console.print(f"Truncated at the start: ...{truncated_start}", overflow='ellipsis')
mid = len(long_string) // 2
truncated_middle = long_string[:15] + "..." + long_string[-15:]
console.print(f"Truncated in the middle: {truncated_middle}", overflow='ellipsis')
truncated_end = long_string[:30] # Taking the first 30 characters
console.print(f"Truncated at the end: {truncated_end}...", overflow='ellipsis') The output is: Truncated at the start: ...ing that needs to be truncated
Truncated in the middle: This is a reall...to be truncated
Truncated at the end: This is a really really really... |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
When using overflow "ellipsis", is there a way of defining where the ellipsis should be placed?
Sometimes I need to print strings in which the most significant information is at the end (eg. A path) or both at end and start but not middle (eg. A URL)
Beta Was this translation helpful? Give feedback.
All reactions