Skip to content

Multiline shortening #62925

Closed
Closed

Description

@serhiy-storchaka
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']

    Activity

    1. serhiy-storchaka commented on Aug 13, 2013

      @serhiy-storchaka
      MemberAuthor

      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.

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-featureA feature request or enhancement
      on Aug 13, 2013
    3. pitrou commented on Aug 13, 2013

      @pitrou
      Member

      Sounds like a reasonable enhancement to me.

    4. vajrasky commented on Aug 13, 2013

      vajraskymannequin
      Mannequin

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

    5. serhiy-storchaka commented on Aug 13, 2013

      @serhiy-storchaka
      MemberAuthor

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

    6. serhiy-storchaka commented on Sep 13, 2013

      @serhiy-storchaka
      MemberAuthor

      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.

    7. serhiy-storchaka commented on Oct 3, 2013

      @serhiy-storchaka
      MemberAuthor

      Could anyone please review the patch?

    8. serhiy-storchaka commented on Oct 6, 2013

      @serhiy-storchaka
      MemberAuthor

      In updated patch fixed a bug with final spaces.

    9. python-dev commented on Oct 15, 2013

      python-devmannequin
      Mannequin

      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

    10. serhiy-storchaka commented on Oct 15, 2013

      @serhiy-storchaka
      MemberAuthor

      Antoine has approved this on IRC.

      Thank you Ezio and Antoine for your reviews.

    11. vajrasky commented on Oct 16, 2013

      vajraskymannequin
      Mannequin

      Serhiy, you forgot to add shorten to __all__.

    12. python-dev commented on Oct 16, 2013

      python-devmannequin
      Mannequin

      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

    13. serhiy-storchaka commented on Oct 16, 2013

      @serhiy-storchaka
      MemberAuthor

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

    14. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions