Is There a Way to Disable Automatic Line Breaks in Rich When Printing Long Lines? #3821
Replies: 2 comments
|
Yes — use from rich.console import Console
console = Console()
console.print("/some/very/long/path/to/a/file.txt", soft_wrap=True, markup=False)
For your list/dict case, use console.out({"paths": ["/some/long/path", "/another/path"]}, highlight=True)That uses the object's string representation without Rich's pretty-print layout, word wrapping, or markup, while retaining highlighting. The terminal can still wrap the display visually; this removes the extra line breaks emitted by Rich. Link detection and copying across visual wraps remain terminal-dependent. Checked both examples on Rich 15.0.0 with a 20-column console captured to |
|
There is an official switch for the string/path case: For example: console.print(long_path, soft_wrap=True, markup=False)
For arbitrary objects such as lists/dicts, |
Uh oh!
There was an error while loading. Please reload this page.
I really like the auto-coloring feature when printing with Rich. However, one thing has been bothering me: Rich automatically inserts line breaks based on the window size.
For example, when displaying a long file path, most modern terminals allow you to click to open the path or file directly. But after Rich adds extra spaces or line breaks, this no longer works. Similarly, if I want to copy a long path, or copy a piece of data like a list or dict, the formatting is incorrect due to the inserted line breaks or spaces.
Right now, I’ve worked around this by overriding print behavior, but it's a bit complicated. I’d like to know: is there an official parameter that controls whether Rich adds these extra line breaks?
All reactions