Skip to content
Myr

Implemented max_content_width. This fixes #216

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent 4851f7c · Browse files · 3 files+28 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+28 added−6 removed

  • other:+28 added−6 removed

3 files+28 added−6 removed

modified:click/core.py+21 added-4 removed
106 unmodified lines
107 Added the `allow_extra_args` and `allow_interspersed_args`108 parameters.109110 .. versionadded:: 4.0111 Added the `color` and `ignore_unknown_options` parameter.111 Added the `color`, `ignore_unknown_options`, and112 `max_content_width` parameters.113114 :param command: the command class for this context.115 :param parent: the parent context.116 :param info_name: the info name for this invokation. Generally this
12 unmodified lines
129 :param terminal_width: the width of the terminal. The default is130 inherit from parent context. If no context131 defines the terminal width then auto132 detection will be applied.133 :param max_content_width: the maximum width for content rendered by134 Click (this currently only affects help135 pages). This defaults to 80 characters if136 not overridden. In other words: even if the137 terminal is larger than that, Click will not138 format things wider than 80 characters by139 default. In addition to that, formatteres might140 add some safety mapping on the right.141 :param resilient_parsing: if this flag is enabled then Click will142 parse without any interactivity or callback143 invocation. This is useful for implementing144 things such as completion support.
22 unmodified lines
167 """168169 def __init__(self, command, parent=None, info_name=None, obj=None,170 auto_envvar_prefix=None, default_map=None,162 terminal_width=None, resilient_parsing=False,163 allow_extra_args=None, allow_interspersed_args=None,171 terminal_width=None, max_content_width=None,172 resilient_parsing=False, allow_extra_args=None,173 allow_interspersed_args=None,174 ignore_unknown_options=None, help_option_names=None,175 token_normalize_func=None, color=None):176 #: the parent context or `None` if none exists.177 self.parent = parent
33 unmodified lines
211 terminal_width = parent.terminal_width212 #: The width of the terminal (None is autodetection).213 self.terminal_width = terminal_width214215 if max_content_width is None and parent is not None:216 max_content_width = parent.max_content_width217 #: The maximum width of formatted content (None implies a sensible218 #: default which is 80 for most things).219 self.max_content_width = max_content_width220221 if allow_extra_args is None:222 allow_extra_args = command.allow_extra_args223 #: Indicates if the context allows extra args or if it should224 #: fail on parsing.
92 unmodified lines
317 del _get_invoked_subcommands, _set_invoked_subcommands318319 def make_formatter(self):320 """Creates the formatter for the help and usage output."""305 return HelpFormatter(width=self.terminal_width)321 return HelpFormatter(width=self.terminal_width,322 max_width=self.max_content_width)323324 def call_on_close(self, f):325 """This decorator remembers a function as callback that should be326 executed when the context tears down. This is most useful to bind
1303 unmodified lines
modified:click/formatting.py+4 added-2 removed
92 unmodified lines
93 :param width: the width for the text. This defaults to the terminal94 width clamped to a maximum of 78.95 """9697 def __init__(self, indent_increment=2, width=None):97 def __init__(self, indent_increment=2, width=None, max_width=None):98 self.indent_increment = indent_increment99 if max_width is None:100 max_width = 80101 if width is None:100 width = max(min(get_terminal_size()[0], 80) - 2, 50)102 width = max(min(get_terminal_size()[0], max_width) - 2, 50)103 self.width = width104 self.current_indent = 0105 self.buffer = []106
135 unmodified lines
modified:CHANGES+3 added
16 unmodified lines
17- Added `NoSuchOption` and `BadOptionUsage` exceptions for more generic18 handling of errors.19- Added support for handling of unprocessed options which can be useful in20 situations where arguments are forwarded to underlying tools.21- Added `max_content_width` parameter to the context which can be used to22 change the maximum width of help output. By default Click will not format23 content for more than 80 characters width.2425Version 3.326-----------27
176 unmodified lines