diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2014-01-09 21:14:27 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2014-01-09 21:14:27 (GMT) |
commit | f451112413b9ea8940c8c3a902cddf701c62d17f (patch) | |
tree | 385735b78ad865fde1d615d27041c356acefbf00 /Lib/optparse.py | |
parent | 32c4915b239f435fd6c063b7f507b289a7a55f75 (diff) | |
download | cpython-f451112413b9ea8940c8c3a902cddf701c62d17f.zip cpython-f451112413b9ea8940c8c3a902cddf701c62d17f.tar.gz cpython-f451112413b9ea8940c8c3a902cddf701c62d17f.tar.bz2 |
Issue #13107: argparse and optparse no longer raises an exception when output
a help on environment with too small COLUMNS. Based on patch by
Elazar Gershuni.
Diffstat (limited to 'Lib/optparse.py')
-rw-r--r-- | Lib/optparse.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/Lib/optparse.py b/Lib/optparse.py index 22405d5..be0145f 100644 --- a/Lib/optparse.py +++ b/Lib/optparse.py @@ -209,7 +209,6 @@ class HelpFormatter: short_first): self.parser = None self.indent_increment = indent_increment - self.help_position = self.max_help_position = max_help_position if width is None: try: width = int(os.environ['COLUMNS']) @@ -217,6 +216,8 @@ class HelpFormatter: width = 80 width -= 2 self.width = width + self.help_position = self.max_help_position = \ + min(max_help_position, max(width - 20, indent_increment * 2)) self.current_indent = 0 self.level = 0 self.help_width = None # computed later @@ -261,7 +262,7 @@ class HelpFormatter: Format a paragraph of free-form text for inclusion in the help output at the current indentation level. """ - text_width = self.width - self.current_indent + text_width = max(self.width - self.current_indent, 11) indent = " "*self.current_indent return textwrap.fill(text, text_width, @@ -342,7 +343,7 @@ class HelpFormatter: self.dedent() self.dedent() self.help_position = min(max_len + 2, self.max_help_position) - self.help_width = self.width - self.help_position + self.help_width = max(self.width - self.help_position, 11) def format_option_strings(self, option): """Return a comma-separated list of option strings & metavariables.""" |