msg195065 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2013-08-13 10:12 |
Functions in the textwrap module works with multiline text except a newly added (in ) 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. >>>print(textwrap('Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.', width=40, max_lines=3)) Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore (...) The shorten() function then will be just a particular case of fill() with max_lines=1. |
|
|
msg195066 - (view) |
Author: Antoine Pitrou (pitrou) *  |
Date: 2013-08-13 10:15 |
Sounds like a reasonable enhancement to me. |
|
|
msg195074 - (view) |
Author: Vajrasky Kok (vajrasky) * |
Date: 2013-08-13 13:30 |
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 (' '). |
|
|
msg195075 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2013-08-13 13:49 |
fill(...) is just '\n'.join(wrap(...)). Directly use wrap() if you need nonstandard newlines. |
|
|
msg197557 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2013-09-13 07:47 |
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. |
|
|
msg198891 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2013-10-03 12:08 |
Could anyone please review the patch? |
|
|
msg199046 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2013-10-06 08:29 |
In updated patch fixed a bug with final spaces. |
|
|
msg200010 - (view) |
Author: Roundup Robot (python-dev)  |
Date: 2013-10-15 18:24 |
New changeset 2e8c424dc638 by Serhiy Storchaka in branch 'default': Issue #18725: The textwrap module now supports truncating multiline text. http://hg.python.org/cpython/rev/2e8c424dc638 |
|
|
msg200011 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2013-10-15 18:25 |
Antoine has approved this on IRC. Thank you Ezio and Antoine for your reviews. |
|
|
msg200046 - (view) |
Author: Vajrasky Kok (vajrasky) * |
Date: 2013-10-16 09:47 |
Serhiy, you forgot to add shorten to __all__. |
|
|
msg200049 - (view) |
Author: Roundup Robot (python-dev)  |
Date: 2013-10-16 10:08 |
New changeset 0bd257cd3e88 by Serhiy Storchaka in branch 'default': Add shorten to __all_ (issues #18585 and #18725). http://hg.python.org/cpython/rev/0bd257cd3e88 |
|
|
msg200051 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2013-10-16 10:09 |
Thank you Vajrasky. It's Antoine forgot. ;) |
|
|