Skip to content
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

Closed
serhiy-storchaka opened this issue Aug 13, 2013 · 12 comments
Closed

Multiline shortening #62925

serhiy-storchaka opened this issue Aug 13, 2013 · 12 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@serhiy-storchaka
Copy link
Member

BPO 18725
Nosy @warsaw, @birkenfeld, @pitrou, @ezio-melotti, @stevendaprano, @bitdancer, @serhiy-storchaka, @vajrasky
Files
  • textwrap_max_lines.patch
  • textwrap_max_lines_2.patch
  • 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:

    assignee = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2013-10-15.18:25:55.484>
    created_at = <Date 2013-08-13.10:12:58.179>
    labels = ['type-feature', 'library']
    title = 'Multiline shortening'
    updated_at = <Date 2013-10-16.10:09:30.760>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2013-10-16.10:09:30.760>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2013-10-15.18:25:55.484>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2013-08-13.10:12:58.179>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = ['31736', '31971']
    hgrepos = []
    issue_num = 18725
    keywords = ['patch', 'needs review']
    message_count = 12.0
    messages = ['195065', '195066', '195074', '195075', '197557', '198891', '199046', '200010', '200011', '200046', '200049', '200051']
    nosy_count = 9.0
    nosy_names = ['barry', 'georg.brandl', 'pitrou', 'ezio.melotti', 'steven.daprano', 'r.david.murray', 'python-dev', 'serhiy.storchaka', 'vajrasky']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue18725'
    versions = ['Python 3.4']

    @serhiy-storchaka
    Copy link
    Member Author

    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.

    >>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.

    @serhiy-storchaka serhiy-storchaka added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Aug 13, 2013
    @pitrou
    Copy link
    Member

    pitrou commented Aug 13, 2013

    Sounds like a reasonable enhancement to me.

    @vajrasky
    Copy link
    Mannequin

    vajrasky mannequin commented Aug 13, 2013

    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 />').

    @serhiy-storchaka
    Copy link
    Member Author

    fill(...) is just '\n'.join(wrap(...)). Directly use wrap() if you need nonstandard newlines.

    @serhiy-storchaka
    Copy link
    Member Author

    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.

    @serhiy-storchaka
    Copy link
    Member Author

    Could anyone please review the patch?

    @serhiy-storchaka
    Copy link
    Member Author

    In updated patch fixed a bug with final spaces.

    @serhiy-storchaka serhiy-storchaka self-assigned this Oct 6, 2013
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 15, 2013

    New changeset 2e8c424dc638 by Serhiy Storchaka in branch 'default':
    Issue bpo-18725: The textwrap module now supports truncating multiline text.
    http://hg.python.org/cpython/rev/2e8c424dc638

    @serhiy-storchaka
    Copy link
    Member Author

    Antoine has approved this on IRC.

    Thank you Ezio and Antoine for your reviews.

    @vajrasky
    Copy link
    Mannequin

    vajrasky mannequin commented Oct 16, 2013

    Serhiy, you forgot to add shorten to __all__.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 16, 2013

    New changeset 0bd257cd3e88 by Serhiy Storchaka in branch 'default':
    Add shorten to __all_ (issues bpo-18585 and bpo-18725).
    http://hg.python.org/cpython/rev/0bd257cd3e88

    @serhiy-storchaka
    Copy link
    Member Author

    Thank you Vajrasky. It's Antoine forgot. ;)

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants