Re: Long help lines and wrapping

David Goodger <[email protected]> Fri, 15 Nov 2002 18:25:04 -0500
Newsgroups gmane.comp.python.optik.user
Message-ID <B9FAEC7F.2BCD4%[email protected]>
Bob van der Poel wrote:
> Here's a reworked function for help.py.

Your changes were made to an old version of the file, pre-textwrap.
Please use the latest sources from CVS.

> All I've done is to split the option string into chucks at the
> newlines. The rest for the code is unchanged (umm, did have to
> change a variable name in the "help_lines=" line. I did some simple
> tests and it seems to work just fine :)

I think the changes are too simple.  Please take a look at my post of
Nov. 11.  What should the wrapping behavior be for indented
paragraphs?  Should list items be recognized?  I have my own answers
to these questions, but I'd like to see yours and Greg's.  The final
answers will determine what has to happen in the code.

This was your example setup code::

        parser.add_option("-p", "--pattern", type="string",
           action="store", dest="pattern",
           help="Set Pattern. Available patterns are:\n" +
                "   xx use the xx pattern\n" +
                "   yy use the yy pattern")

By the indentation in the example and the spaces in the setup code, I
infer that you want to indent the second and third lines.  The changed
code won't do that.  Try your version with very long option strings
(like "--a-very-very-very-long-option-string") and help text
consisting of multiple long paragraphs (so each paragraph will have to
be wrapped).  I think you'll see some unwanted behavior.  For example::

        extra = " x" * 80
        parser.add_option("-p", "--pattern", type="string",
           action="store", dest="pattern",
           help=("Set Pattern. Available patterns are%s:\n" +
                "   xx use the xx pattern%s\n" +
                "   yy use the yy pattern%s") % (extra, extra, extra))

> Advantage is that I didn't need to hack on the wrapping routines.

The textwrap.wrap routine should be able to handle everything we need.
We just need to pass it the correct parameters (initial_indent and
subsequent_indent).

> BTW, it also effects the 'usage' line, so at least that is
> consistent.

I don't follow.  Please explain what you mean.

-- 
David Goodger  <[email protected]>  Open-source projects:
  - Python Docutils: http://docutils.sourceforge.net/
    (includes reStructuredText: http://docutils.sf.net/rst.html)
  - The Go Tools Project: http://gotools.sourceforge.net/



-------------------------------------------------------
This sf.net email is sponsored by: To learn the basics of securing 
your web site with SSL, click here to get a FREE TRIAL of a Thawte 
Server Certificate: http://www.gothawte.com/rd524.html