Re: feature request #1055954: respect newlines in description

"Andrea 'fwyzard' Bocci" <[email protected]> Wed, 09 Mar 2005 17:05:41 +0100
Newsgroups gmane.comp.python.optik.user
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--------------060002030500020502010505
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Tomi Mickelsson wrote:
> 
> 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.

I like the idea - I found it a bit confuasing that newlines in the 
description were actually considered as whitespaces until I read how 
textwrap behaves. Than I lived with it...

How do you like this solution (patch against optparse.py as in Python 
2.4 quoted and attached) ?

> --- optparse.py 2004-10-27 04:20:04.000000000 +0200
> +++ optparse.new.py     2005-03-09 17:00:32.000000000 +0100
> @@ -226,10 +226,12 @@ class HelpFormatter:
>              return ""
>          desc_width = self.width - self.current_indent
>          indent = " "*self.current_indent
> -        return textwrap.fill(description,
> -                             desc_width,
> -                             initial_indent=indent,
> -                             subsequent_indent=indent) + "\n"
> +        lines = description.split("\n")
> +        desc_lines = map(lambda line: textwrap.fill(line,
> +                                                    desc_width,
> +                                                    initial_indent=indent,
> +                                                    subsequent_indent=indent), lines))
> +        return "\n".join(desc_lines) + "\n"
> 
>      def expand_default(self, option):
>          if self.parser is None or not self.default_tag:

.Andrea.

--------------060002030500020502010505
Content-Type: text/x-patch;
 name="newline.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="newline.patch"

--- optparse.py 2004-10-27 04:20:04.000000000 +0200
+++ optparse.new.py     2005-03-09 17:00:32.000000000 +0100
@@ -226,10 +226,12 @@ class HelpFormatter:
             return ""
         desc_width = self.width - self.current_indent
         indent = " "*self.current_indent
-        return textwrap.fill(description,
-                             desc_width,
-                             initial_indent=indent,
-                             subsequent_indent=indent) + "\n"
+        lines = description.split("\n")
+        desc_lines = map(lambda line: textwrap.fill(line,
+                                                    desc_width,
+                                                    initial_indent=indent,
+                                                    subsequent_indent=indent), lines))
+        return "\n".join(desc_lines) + "\n"

     def expand_default(self, option):
         if self.parser is None or not self.default_tag:

--------------060002030500020502010505--


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