RE: feature request #1055954: respect newlines in description
"Laurent Laporte" <[email protected]> Wed, 9 Mar 2005 18:23:53 +0100
| Newsgroups | gmane.comp.python.optik.user |
|---|---|
| Message-ID | <[email protected]> |
Hello,
A solution is to create your own class IndentedHelpFormatter, for example:
| class MyIndentedHelpFormatter (optparse.HelpFormatter):
| def __init__(self, p_indentIncrement = 2, p_maxHelpPosition = 24,
p_width = 100, p_shortFirst = 1):
| optparse.HelpFormatter.__init__(self, p_indentIncrement,
p_maxHelpPosition, p_width, p_shortFirst)
|
| def format_description(self, p_description):
| t_descWidth = self.width - self.current_indent
| t_indent = " " * (self.current_indent + 2)
| return "\n".join(
| [textwrap.fill(descr, t_descWidth, initial_indent = t_indent,
subsequent_indent = t_indent)
| for descr in p_description.split('\n')] )
|
and plug an instance of your class in the constructor of OptionParser(),
like this:
| t_parser = optparse.OptionParser(
| formatter = MyIndentedHelpFormatter(),
| usage = t_yourUsage,
| description = "N lines\nof\ndescription.")
|
Notice: The same problem (of newlines non-interpretation) occurs with
options' help messages -- see help's parameter of the method add_option().
It also uses texwrap() function...
bye.
-----Message d'origine-----
De : [email protected]
[mailto:[email protected]]De la part de Tomi
Mickelsson
Envoye : mercredi 9 mars 2005 09:18
A : [email protected]
Objet : [optik] feature request #1055954: respect newlines in
description
Greg wishes discussion about my feature request. You can see my request as
item #1055954.
In short, I would like to control the linefeeds in the description field.
I do not like the way everything in the description is jammed into a
single paragraph.
For example, here's the usage output of a recent sample app of mine.
---
F:\python>beepclient.py
usage: beepclient.py server:port testcase
beepclient.py is a prototype beep client written in python. The client
provides multiple test cases:
1 - send corrupted packet
2 - send packet without CRLF
3 - send ok packet
4 - no CRLF after END
5 - send 2 ok packets
6 - send 2 packets, garbage between
7 - send 2 auth packets, 1 data
Author: Tomi Mickelsson. Version 0.1, Feb 2, 2005
options:
--version show program's version number and exit
-h, --help show this help message and exit
-v verbose
-fFILENAME filename to merge
-pPORT Listen port
---
To achieve this formatting, I have the following kludge in my code:
---
import new
....code omitted
# use my own description formatter method
parser.format_description = new.instancemethod(lambda self,x :
self.description, parser, parser.__class__)
...now use the parser
---
In the solution I replace a method in the parser with my own method that
just returns the description as it is without any formatting.
While this works ok for my purposes, it's kludgery and looks bad. I'd like
to get rid of the new.instancemethod; it scares the developers looking at
the code and leaves a bad impression of python.
With this solution, I do loose all formatting features of textwrap. Could
we draft a solution where textwrap is used but the user can insert hard
line breaks in the description text?
Tomi Mickelsson, [email protected]
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
optik-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/optik-users
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click