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
Multiline shortening #62925
Comments
Functions in the textwrap module works with multiline text except a newly added (in bpo-18585) the shorten() function. Wrapping and shortening a multiline text using existing textwrap function is not a trivial job. I propose to add two new parameters to the TextWrap class and wrap() and fill() functions: max_lines and placeholder. If the max_lines argument is specified then wrapped text truncated to max_lines and the last line shortened to the width argument.
The shorten() function then will be just a particular case of fill() with max_lines=1. |
Sounds like a reasonable enhancement to me. |
What about newline keyword argument? Are we forcing the newline to be '\n'? Alternate newlines will be useful for Windows platform ('\r\n') and HTML platform ('<br />'). |
fill(...) is just '\n'.join(wrap(...)). Directly use wrap() if you need nonstandard newlines. |
Here is a patch. It get rid of TextWrap.shorten() because TextWrap.fill() supersedes it and because "placeholder" now a parameter of TextWrap. Module level shorten() is left but I doubt about it. |
Could anyone please review the patch? |
In updated patch fixed a bug with final spaces. |
New changeset 2e8c424dc638 by Serhiy Storchaka in branch 'default': |
Antoine has approved this on IRC. Thank you Ezio and Antoine for your reviews. |
Serhiy, you forgot to add shorten to __all__. |
New changeset 0bd257cd3e88 by Serhiy Storchaka in branch 'default': |
Thank you Vajrasky. It's Antoine forgot. ;) |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: