Add support for continuation indent and optimize divide_line #3426
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Type of changes
Checklist
Description
This PR adds an attribute
continuation_indent: int
torich.text.Text
that prefixes wrapped lines with a corresponding number of spaces. A paragraph wrapped to 72 characters might look like:With
continuation_indent=4
, it would look like:This is particularly useful for rendering multiline output that may become ambiguous without some indication of where text wrapping occurred. For example, printing a list of (very contrived) CLI commands:
Might wrap to:
Which has a significantly different meaning. Using
continuation_indent=4
, we instead get:In the process of implementing this I heavily refactored
divide_line
to no longer usechop_cells
. Not only is this much faster (it no longer creates a temporary list of list of substrings), but it is more correct in the degenerate case of wrapping to a single column (though I'm happy to revert this if it's not preferred):