@@ -165,6 +165,8 @@ def __init__(self,
165165 self ._prog = prog
166166 self ._indent_increment = indent_increment
167167 self ._max_help_position = max_help_position
168+ self ._max_help_position = min (max_help_position ,
169+ max (width - 20 , indent_increment * 2 ))
168170 self ._width = width
169171
170172 self ._current_indent = 0
@@ -336,7 +338,7 @@ def get_lines(parts, indent, prefix=None):
336338 else :
337339 line_len = len (indent ) - 1
338340 for part in parts :
339- if line_len + 1 + len (part ) > text_width :
341+ if line_len + 1 + len (part ) > text_width and line :
340342 lines .append (indent + ' ' .join (line ))
341343 line = []
342344 line_len = len (indent ) - 1
@@ -476,15 +478,15 @@ def _format_actions_usage(self, actions, groups):
476478 def _format_text (self , text ):
477479 if '%(prog)' in text :
478480 text = text % dict (prog = self ._prog )
479- text_width = self ._width - self ._current_indent
481+ text_width = max ( self ._width - self ._current_indent , 11 )
480482 indent = ' ' * self ._current_indent
481483 return self ._fill_text (text , text_width , indent ) + '\n \n '
482484
483485 def _format_action (self , action ):
484486 # determine the required width and the entry label
485487 help_position = min (self ._action_max_length + 2 ,
486488 self ._max_help_position )
487- help_width = self ._width - help_position
489+ help_width = max ( self ._width - help_position , 11 )
488490 action_width = help_position - self ._current_indent - 2
489491 action_header = self ._format_action_invocation (action )
490492
0 commit comments