Is there a way to do this like textwrap.fill does?
See original GitHub issueI am wondering if there is a way to do this in rich (sort of how textwrap does):
MyStr = textwrap.fill(line, width=xxx, initial_indent=“”, subsequent_indent=" ")
I love how rich handles the width of the screen, especially with colors, but it doesn’t have an option for subsequent wraps.
I’d like the output to look something like this:
definition: this is a short definition
another here: this is a longer definition of
things here, that just keeps on going
and going
some other term: you get the idea now
Rather than what I get now:
definition: this is a short definition
another here: this is a longer definition of
things here, that just keeps on going and going
some other term: you get the idea now
Colors help, but I would like the extra indent to differentiate as well.
A way around this would be if there was a function that would return the (colorized) string WITHOUT printing it. Then I could call the textwrap functions myself. I looked, and if there is one, I missed it.
Anyway, thanks for the great software. Really like using it!
Thanks! Mike
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top Results From Across the Web
textwrap — Text wrapping and filling — Python 3.11.1 ...
wrap() , fill() and shorten() work by creating a TextWrapper instance and calling a single method on it. That instance is not reused,...
Read more >How do textwrap.wrap() & textwrap.fill() exactly work in python ...
Wraps the single paragraph in text (a string) so every line is at most width characters long. Returns a list of output lines,...
Read more >Textwrap – Text wrapping and filling in Python - GeeksforGeeks
This function wraps the input paragraph such that each line in the paragraph is at most width characters long. The wrap method returns...
Read more >Wrap and truncate a string with textwrap in Python - nkmk note
Wrap a string: wrap() , fill() ... With the wrap() function of the textwrap module, you can get a list divided by word...
Read more >Python Text Wrapping and Filling - Tutorialspoint
The fill() method is similar to the wrap method, but it does not generate a list. It generates a string. It adds the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@willmcgugan Thanks for the info.
That’s unfortunate with textwrap though. Good to know that it can be done though!
I do like the solution with the table/grid solutions. Those worked great!
Thanks for the quick turnaround!
You can render to a string with the following pattern:
Unfortunately you won’t be able to use the result with textwrap, which won’t handle the invisible control codes correctly.