Repository: ewels/rich-click

Issue:
MAX_WIDTH setting acts only as fixed width
### Expected behavior
Use the full width of the terminal for output if it is less than the MAX_WIDTH setting

### Actual behavior
The rendered help is always displayed in MAX_WIDTH

### Screenshots
With MAX_WIDTH = 128
![image](https://github.com/ewels/rich-click/assets/15620712/8aac9eea-f8ed-411f-91de-bbc2e49109cc)

With MAX_WIDTH = None
![image](https://github.com/ewels/rich-click/assets/15620712/a617b19f-285b-47f6-9aae-10122ceaff8d)


Discussion:

Patch:
diff --git a/README.md b/README.md
index ce9a70c..07a44ef 100644
--- a/README.md
+++ b/README.md
@@ -224,12 +224,20 @@ click.rich_click.ERRORS_EPILOGUE = "To find out more, visit [link=https://mytool
 The default behaviour of rich-click is to use the full width of the terminal for output.
 However, if you've carefully crafted your help texts for the default narrow click output, you may find that you now have a lot of whitespace at the side of the panels.
 
-To limit the maximum width of the help output, set `MAX_WIDTH` in characters, as follows:
+To limit the maximum width of the help output, regardless of the terminal size, set `WIDTH` in characters as follows:
 
 ```python
-click.rich_click.MAX_WIDTH = 100
+click.rich_click.WIDTH = 128
 ```
 
+To still use the full width of the terminal up to a certain limit, set `MAX_WIDTH` in characters as follows:
+
+```python
+click.rich_click.MAX_WIDTH = 96
+```
+
+Setting `MAX_WIDTH` overrides the effect of `WIDTH`
+
 ### Styling
 
 Most aspects of rich-click formatting can be customised, from colours to alignment.
@@ -411,7 +419,8 @@ STYLE_ERRORS_PANEL_BORDER = "red"
 ALIGN_ERRORS_PANEL = "left"
 STYLE_ERRORS_SUGGESTION = "dim"
 STYLE_ABORTED = "red"
-MAX_WIDTH = None  # Set to an int to limit to that many characters
+WIDTH = None  # Set to int for a fixed character limit regardless of the terminal width
+MAX_WIDTH = None  # Set to int for a max character limit that is less than the terminal width. Overrides WIDTH limit
 COLOR_SYSTEM = "auto"  # Set to None to disable colors
 
 # Fixed strings
diff --git a/src/rich_click/rich_click.py b/src/rich_click/rich_click.py
index da788fc..73ebf2f 100644
--- a/src/rich_click/rich_click.py
+++ b/src/rich_click/rich_click.py
@@ -73,7 +73,8 @@ STYLE_ERRORS_PANEL_BORDER = "red"
 ALIGN_ERRORS_PANEL = "left"
 STYLE_ERRORS_SUGGESTION = "dim"
 STYLE_ABORTED = "red"
-MAX_WIDTH = int(getenv("TERMINAL_WIDTH")) if getenv("TERMINAL_WIDTH") else None  # type: ignore
+WIDTH = int(getenv("TERMINAL_WIDTH")) if getenv("TERMINAL_WIDTH") else None  # type: ignore
+MAX_WIDTH = int(getenv("TERMINAL_WIDTH")) if getenv("TERMINAL_WIDTH") else WIDTH  # type: ignore
 COLOR_SYSTEM: Optional[
     Literal["auto", "standard", "256", "truecolor", "windows"]
 ] = "auto"  # Set to None to disable colors
@@ -798,6 +799,7 @@ def get_module_help_configuration() -> RichHelpConfiguration:
         ALIGN_ERRORS_PANEL,
         STYLE_ERRORS_SUGGESTION,
         STYLE_ABORTED,
+        WIDTH,
         MAX_WIDTH,
         COLOR_SYSTEM,
         FORCE_TERMINAL,
diff --git a/src/rich_click/rich_help_configuration.py b/src/rich_click/rich_help_configuration.py
index 95388cf..3b027a8 100644
--- a/src/rich_click/rich_help_configuration.py
+++ b/src/rich_click/rich_help_configuration.py
@@ -72,6 +72,9 @@ class RichHelpConfiguration:
     align_errors_panel: rich.align.AlignMethod = field(default="left")
     style_errors_suggestion: rich.style.StyleType = field(default="dim")
     style_aborted: rich.style.StyleType = field(default="red")
+    width: Optional[int] = field(
+        default_factory=lambda: (int(getenv("TERMINAL_WIDTH")) if getenv("TERMINAL_WIDTH") else None)  # type: ignore
+    )
     max_width: Optional[int] = field(
         default_factory=lambda: (int(getenv("TERMINAL_WIDTH")) if getenv("TERMINAL_WIDTH") else None)  # type: ignore
     )
diff --git a/src/rich_click/rich_help_formatter.py b/src/rich_click/rich_help_formatter.py
index b3afade..8238da7 100644
--- a/src/rich_click/rich_help_formatter.py
+++ b/src/rich_click/rich_help_formatter.py
@@ -36,7 +36,7 @@ def create_console(config: RichHelpConfiguration, file: Optional[IO[str]] = None
         file: Optional IO stream to write Rich Console output
             Defaults to None.
     """
-    return Console(
+    console = Console(
         theme=rich.theme.Theme(
             {
                 "option": config.style_option,
@@ -51,10 +51,13 @@ def create_console(config: RichHelpConfiguration, file: Optional[IO[str]] = None
         highlighter=config.highlighter,
         color_system=config.color_system,
         force_terminal=config.force_terminal,
-        width=config.max_width,
         file=file,
+        width=config.width,
         legacy_windows=config.legacy_windows,
     )
+    if isinstance(config.max_width, int):
+        console.width = min(config.max_width, console.size.width)
+    return console
 
 
 def get_module_config() -> RichHelpConfiguration:


Test patch:
diff --git a/tests/conftest.py b/tests/conftest.py
index d2f75f1..b8d7072 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -136,13 +136,15 @@ def initialize_rich_click():
     # each test
     reload(rc)
     # default config settings from https://github.com/Textualize/rich/blob/master/tests/render.py
-    rc.MAX_WIDTH = 100
+    rc.WIDTH = 100
+    rc.COLOR_SYSTEM = "truecolor"
 
     # Click <8 tests fail unless we set the COLOR_SYSTEM to None.
     if CLICK_IS_BEFORE_VERSION_8X:
         rc.COLOR_SYSTEM = None
     else:
         rc.COLOR_SYSTEM = "truecolor"
+
     rc.FORCE_TERMINAL = True
 
 
@@ -271,6 +273,7 @@ def assert_rich_format(
             help_config: Optional[RichHelpConfiguration] = command.context_settings.get("rich_help_config")
             if help_config:
                 help_config.color_system = rc.COLOR_SYSTEM
+                help_config.width = rc.WIDTH
                 help_config.max_width = rc.MAX_WIDTH
                 help_config.force_terminal = rc.FORCE_TERMINAL
         result = invoke(command, args)
diff --git a/tests/expectations/test_rich_click[test arguments with rich_config]-click7.config.json b/tests/expectations/test_rich_click[test arguments with rich_config]-click7.config.json
index 02c5b76..a6de6d8 100644
--- a/tests/expectations/test_rich_click[test arguments with rich_config]-click7.config.json
+++ b/tests/expectations/test_rich_click[test arguments with rich_config]-click7.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": null,
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test arguments with rich_config]-click8.config.json b/tests/expectations/test_rich_click[test arguments with rich_config]-click8.config.json
index f0360ec..aa492e1 100644
--- a/tests/expectations/test_rich_click[test arguments with rich_config]-click8.config.json
+++ b/tests/expectations/test_rich_click[test arguments with rich_config]-click8.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": "truecolor",
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test arguments]-click7.config.json b/tests/expectations/test_rich_click[test arguments]-click7.config.json
index 02c5b76..a6de6d8 100644
--- a/tests/expectations/test_rich_click[test arguments]-click7.config.json
+++ b/tests/expectations/test_rich_click[test arguments]-click7.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": null,
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test arguments]-click8.config.json b/tests/expectations/test_rich_click[test arguments]-click8.config.json
index f0360ec..aa492e1 100644
--- a/tests/expectations/test_rich_click[test arguments]-click8.config.json
+++ b/tests/expectations/test_rich_click[test arguments]-click8.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": "truecolor",
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test command column alignment]-click7.config.json b/tests/expectations/test_rich_click[test command column alignment]-click7.config.json
index f9be131..7e69088 100644
--- a/tests/expectations/test_rich_click[test command column alignment]-click7.config.json
+++ b/tests/expectations/test_rich_click[test command column alignment]-click7.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": null,
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test command column alignment]-click8.config.json b/tests/expectations/test_rich_click[test command column alignment]-click8.config.json
index 08dc753..a98c6a0 100644
--- a/tests/expectations/test_rich_click[test command column alignment]-click8.config.json
+++ b/tests/expectations/test_rich_click[test command column alignment]-click8.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": "truecolor",
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test context_settings]-click7.config.json b/tests/expectations/test_rich_click[test context_settings]-click7.config.json
index 958e0fc..11f4382 100644
--- a/tests/expectations/test_rich_click[test context_settings]-click7.config.json
+++ b/tests/expectations/test_rich_click[test context_settings]-click7.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": null,
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test context_settings]-click8.config.json b/tests/expectations/test_rich_click[test context_settings]-click8.config.json
index 977bf39..87e1859 100644
--- a/tests/expectations/test_rich_click[test context_settings]-click8.config.json
+++ b/tests/expectations/test_rich_click[test context_settings]-click8.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": "truecolor",
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test custom errors help]-click7.config.json b/tests/expectations/test_rich_click[test custom errors help]-click7.config.json
index 6611a14..1321688 100644
--- a/tests/expectations/test_rich_click[test custom errors help]-click7.config.json
+++ b/tests/expectations/test_rich_click[test custom errors help]-click7.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "magenta italic",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": null,
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test custom errors help]-click8.config.json b/tests/expectations/test_rich_click[test custom errors help]-click8.config.json
index 6742d55..aeaf7fb 100644
--- a/tests/expectations/test_rich_click[test custom errors help]-click8.config.json
+++ b/tests/expectations/test_rich_click[test custom errors help]-click8.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "magenta italic",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": "truecolor",
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test custom errors with rich_config]-click7.config.json b/tests/expectations/test_rich_click[test custom errors with rich_config]-click7.config.json
index 6611a14..1321688 100644
--- a/tests/expectations/test_rich_click[test custom errors with rich_config]-click7.config.json
+++ b/tests/expectations/test_rich_click[test custom errors with rich_config]-click7.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "magenta italic",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": null,
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test custom errors with rich_config]-click8.config.json b/tests/expectations/test_rich_click[test custom errors with rich_config]-click8.config.json
index 6742d55..aeaf7fb 100644
--- a/tests/expectations/test_rich_click[test custom errors with rich_config]-click8.config.json
+++ b/tests/expectations/test_rich_click[test custom errors with rich_config]-click8.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "magenta italic",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": "truecolor",
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test declarative with rich_config]-click7.config.json b/tests/expectations/test_rich_click[test declarative with rich_config]-click7.config.json
index 958e0fc..11f4382 100644
--- a/tests/expectations/test_rich_click[test declarative with rich_config]-click7.config.json
+++ b/tests/expectations/test_rich_click[test declarative with rich_config]-click7.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": null,
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test declarative with rich_config]-click8.config.json b/tests/expectations/test_rich_click[test declarative with rich_config]-click8.config.json
index d531c08..e7919f4 100644
--- a/tests/expectations/test_rich_click[test declarative with rich_config]-click8.config.json
+++ b/tests/expectations/test_rich_click[test declarative with rich_config]-click8.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": "truecolor",
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test declarative]-click7.config.json b/tests/expectations/test_rich_click[test declarative]-click7.config.json
index 958e0fc..11f4382 100644
--- a/tests/expectations/test_rich_click[test declarative]-click7.config.json
+++ b/tests/expectations/test_rich_click[test declarative]-click7.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": null,
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test declarative]-click8.config.json b/tests/expectations/test_rich_click[test declarative]-click8.config.json
index d531c08..e7919f4 100644
--- a/tests/expectations/test_rich_click[test declarative]-click8.config.json
+++ b/tests/expectations/test_rich_click[test declarative]-click8.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": "truecolor",
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test environment variables with rich_config]-click7.config.json b/tests/expectations/test_rich_click[test environment variables with rich_config]-click7.config.json
index 958e0fc..11f4382 100644
--- a/tests/expectations/test_rich_click[test environment variables with rich_config]-click7.config.json
+++ b/tests/expectations/test_rich_click[test environment variables with rich_config]-click7.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": null,
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test environment variables with rich_config]-click8.config.json b/tests/expectations/test_rich_click[test environment variables with rich_config]-click8.config.json
index d531c08..e7919f4 100644
--- a/tests/expectations/test_rich_click[test environment variables with rich_config]-click8.config.json
+++ b/tests/expectations/test_rich_click[test environment variables with rich_config]-click8.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": "truecolor",
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test envvar]-click7.config.json b/tests/expectations/test_rich_click[test envvar]-click7.config.json
index 958e0fc..11f4382 100644
--- a/tests/expectations/test_rich_click[test envvar]-click7.config.json
+++ b/tests/expectations/test_rich_click[test envvar]-click7.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": null,
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test envvar]-click8.config.json b/tests/expectations/test_rich_click[test envvar]-click8.config.json
index d531c08..e7919f4 100644
--- a/tests/expectations/test_rich_click[test envvar]-click8.config.json
+++ b/tests/expectations/test_rich_click[test envvar]-click8.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": "truecolor",
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test group sorting]-click7.config.json b/tests/expectations/test_rich_click[test group sorting]-click7.config.json
index 0b4d110..9735d65 100644
--- a/tests/expectations/test_rich_click[test group sorting]-click7.config.json
+++ b/tests/expectations/test_rich_click[test group sorting]-click7.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": null,
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test group sorting]-click8.config.json b/tests/expectations/test_rich_click[test group sorting]-click8.config.json
index 04d6e43..037947e 100644
--- a/tests/expectations/test_rich_click[test group sorting]-click8.config.json
+++ b/tests/expectations/test_rich_click[test group sorting]-click8.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": "truecolor",
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test groups sorting with rich_config]-click7.config.json b/tests/expectations/test_rich_click[test groups sorting with rich_config]-click7.config.json
index 0b4d110..9735d65 100644
--- a/tests/expectations/test_rich_click[test groups sorting with rich_config]-click7.config.json
+++ b/tests/expectations/test_rich_click[test groups sorting with rich_config]-click7.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": null,
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test groups sorting with rich_config]-click8.config.json b/tests/expectations/test_rich_click[test groups sorting with rich_config]-click8.config.json
index 04d6e43..037947e 100644
--- a/tests/expectations/test_rich_click[test groups sorting with rich_config]-click8.config.json
+++ b/tests/expectations/test_rich_click[test groups sorting with rich_config]-click8.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": "truecolor",
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test markdown with rich_config]-click7.config.json b/tests/expectations/test_rich_click[test markdown with rich_config]-click7.config.json
index 7349c51..36ad339 100644
--- a/tests/expectations/test_rich_click[test markdown with rich_config]-click7.config.json
+++ b/tests/expectations/test_rich_click[test markdown with rich_config]-click7.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": null,
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test markdown with rich_config]-click8.config.json b/tests/expectations/test_rich_click[test markdown with rich_config]-click8.config.json
index 6f31667..c55a5c0 100644
--- a/tests/expectations/test_rich_click[test markdown with rich_config]-click8.config.json
+++ b/tests/expectations/test_rich_click[test markdown with rich_config]-click8.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": "truecolor",
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test markdown]-click7.config.json b/tests/expectations/test_rich_click[test markdown]-click7.config.json
index 7349c51..36ad339 100644
--- a/tests/expectations/test_rich_click[test markdown]-click7.config.json
+++ b/tests/expectations/test_rich_click[test markdown]-click7.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": null,
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test markdown]-click8.config.json b/tests/expectations/test_rich_click[test markdown]-click8.config.json
index 6f31667..c55a5c0 100644
--- a/tests/expectations/test_rich_click[test markdown]-click8.config.json
+++ b/tests/expectations/test_rich_click[test markdown]-click8.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": "truecolor",
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test metavars default with rich_config]-click7.config.json b/tests/expectations/test_rich_click[test metavars default with rich_config]-click7.config.json
index 958e0fc..11f4382 100644
--- a/tests/expectations/test_rich_click[test metavars default with rich_config]-click7.config.json
+++ b/tests/expectations/test_rich_click[test metavars default with rich_config]-click7.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": null,
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test metavars default with rich_config]-click8.config.json b/tests/expectations/test_rich_click[test metavars default with rich_config]-click8.config.json
index d531c08..e7919f4 100644
--- a/tests/expectations/test_rich_click[test metavars default with rich_config]-click8.config.json
+++ b/tests/expectations/test_rich_click[test metavars default with rich_config]-click8.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": "truecolor",
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test metavars default]-click7.config.json b/tests/expectations/test_rich_click[test metavars default]-click7.config.json
index 958e0fc..11f4382 100644
--- a/tests/expectations/test_rich_click[test metavars default]-click7.config.json
+++ b/tests/expectations/test_rich_click[test metavars default]-click7.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": null,
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test metavars default]-click8.config.json b/tests/expectations/test_rich_click[test metavars default]-click8.config.json
index d531c08..e7919f4 100644
--- a/tests/expectations/test_rich_click[test metavars default]-click8.config.json
+++ b/tests/expectations/test_rich_click[test metavars default]-click8.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": "truecolor",
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test metavars with rich_config]-click7.config.json b/tests/expectations/test_rich_click[test metavars with rich_config]-click7.config.json
index 27fac2f..53a4cbd 100644
--- a/tests/expectations/test_rich_click[test metavars with rich_config]-click7.config.json
+++ b/tests/expectations/test_rich_click[test metavars with rich_config]-click7.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": null,
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test metavars with rich_config]-click8.config.json b/tests/expectations/test_rich_click[test metavars with rich_config]-click8.config.json
index ba6685b..896be5c 100644
--- a/tests/expectations/test_rich_click[test metavars with rich_config]-click8.config.json
+++ b/tests/expectations/test_rich_click[test metavars with rich_config]-click8.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": "truecolor",
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test metavars]-click7.config.json b/tests/expectations/test_rich_click[test metavars]-click7.config.json
index 27fac2f..53a4cbd 100644
--- a/tests/expectations/test_rich_click[test metavars]-click7.config.json
+++ b/tests/expectations/test_rich_click[test metavars]-click7.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": null,
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test metavars]-click8.config.json b/tests/expectations/test_rich_click[test metavars]-click8.config.json
index ba6685b..896be5c 100644
--- a/tests/expectations/test_rich_click[test metavars]-click8.config.json
+++ b/tests/expectations/test_rich_click[test metavars]-click8.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": "truecolor",
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test rich markup with rich_config]-click7.config.json b/tests/expectations/test_rich_click[test rich markup with rich_config]-click7.config.json
index 6a322b0..df06f0d 100644
--- a/tests/expectations/test_rich_click[test rich markup with rich_config]-click7.config.json
+++ b/tests/expectations/test_rich_click[test rich markup with rich_config]-click7.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": null,
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test rich markup with rich_config]-click8.config.json b/tests/expectations/test_rich_click[test rich markup with rich_config]-click8.config.json
index e3258c4..b64a162 100644
--- a/tests/expectations/test_rich_click[test rich markup with rich_config]-click8.config.json
+++ b/tests/expectations/test_rich_click[test rich markup with rich_config]-click8.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": "truecolor",
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test rich markup]-click7.config.json b/tests/expectations/test_rich_click[test rich markup]-click7.config.json
index 6a322b0..df06f0d 100644
--- a/tests/expectations/test_rich_click[test rich markup]-click7.config.json
+++ b/tests/expectations/test_rich_click[test rich markup]-click7.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": null,
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test rich markup]-click8.config.json b/tests/expectations/test_rich_click[test rich markup]-click8.config.json
index e3258c4..b64a162 100644
--- a/tests/expectations/test_rich_click[test rich markup]-click8.config.json
+++ b/tests/expectations/test_rich_click[test rich markup]-click8.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": "truecolor",
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test simple with rich_config]-click7.config.json b/tests/expectations/test_rich_click[test simple with rich_config]-click7.config.json
index 958e0fc..11f4382 100644
--- a/tests/expectations/test_rich_click[test simple with rich_config]-click7.config.json
+++ b/tests/expectations/test_rich_click[test simple with rich_config]-click7.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": null,
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test simple with rich_config]-click8.config.json b/tests/expectations/test_rich_click[test simple with rich_config]-click8.config.json
index d531c08..e7919f4 100644
--- a/tests/expectations/test_rich_click[test simple with rich_config]-click8.config.json
+++ b/tests/expectations/test_rich_click[test simple with rich_config]-click8.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": "truecolor",
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test simple]-click7.config.json b/tests/expectations/test_rich_click[test simple]-click7.config.json
index 958e0fc..11f4382 100644
--- a/tests/expectations/test_rich_click[test simple]-click7.config.json
+++ b/tests/expectations/test_rich_click[test simple]-click7.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": null,
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test simple]-click8.config.json b/tests/expectations/test_rich_click[test simple]-click8.config.json
index d531c08..e7919f4 100644
--- a/tests/expectations/test_rich_click[test simple]-click8.config.json
+++ b/tests/expectations/test_rich_click[test simple]-click8.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": "truecolor",
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test table styles with rich_config]-click7.config.json b/tests/expectations/test_rich_click[test table styles with rich_config]-click7.config.json
index 881a12f..5cd46c6 100644
--- a/tests/expectations/test_rich_click[test table styles with rich_config]-click7.config.json
+++ b/tests/expectations/test_rich_click[test table styles with rich_config]-click7.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": null,
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test table styles with rich_config]-click8.config.json b/tests/expectations/test_rich_click[test table styles with rich_config]-click8.config.json
index ff6b6f1..03afe68 100644
--- a/tests/expectations/test_rich_click[test table styles with rich_config]-click8.config.json
+++ b/tests/expectations/test_rich_click[test table styles with rich_config]-click8.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": "truecolor",
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test table styles]-click7.config.json b/tests/expectations/test_rich_click[test table styles]-click7.config.json
index cd24c6f..099bb65 100644
--- a/tests/expectations/test_rich_click[test table styles]-click7.config.json
+++ b/tests/expectations/test_rich_click[test table styles]-click7.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": null,
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/expectations/test_rich_click[test table styles]-click8.config.json b/tests/expectations/test_rich_click[test table styles]-click8.config.json
index ff6b6f1..03afe68 100644
--- a/tests/expectations/test_rich_click[test table styles]-click8.config.json
+++ b/tests/expectations/test_rich_click[test table styles]-click8.config.json
@@ -41,7 +41,8 @@
   "align_errors_panel": "left",
   "style_errors_suggestion": "dim",
   "style_aborted": "red",
-  "max_width": 100,
+  "width": 100,
+  "max_width": null,
   "color_system": "truecolor",
   "force_terminal": true,
   "header_text": null,
diff --git a/tests/test_help.py b/tests/test_help.py
index 1253f0d..b79ee06 100644
--- a/tests/test_help.py
+++ b/tests/test_help.py
@@ -7,6 +7,7 @@ from conftest import AssertRichFormat, AssertStr, InvokeCli
 from packaging import version
 from rich.console import Console
 
+import rich_click.rich_click as rc
 from rich_click import command, rich_config, RichContext, RichHelpConfiguration
 from rich_click._compat_click import CLICK_IS_BEFORE_VERSION_8X, CLICK_IS_VERSION_80
 from rich_click.rich_command import RichCommand
@@ -246,6 +247,35 @@ Usage: cli [OPTIONS]
     )
 
 
+def test_rich_config_max_width(invoke: InvokeCli, assert_str: AssertStr):
+    rc.WIDTH = 100
+    rc.MAX_WIDTH = 64
+
+    @command()
+    def cli():
+        """Some help
+
+        # Header
+        """
+        pass
+
+    result = invoke(cli, "--help")
+
+    assert_str(
+        result.stdout,
+        """
+Usage: cli [OPTIONS]                                            
+                                                                
+ Some help                                                      
+ # Header                                                       
+                                                                
+╭─ Options ────────────────────────────────────────────────────╮
+│ --help      Show this message and exit.                      │
+╰──────────────────────────────────────────────────────────────╯
+        """,
+    )
+
+
 @pytest.mark.skipif(CLICK_IS_BEFORE_VERSION_8X, reason="rich_config not supported prior to click v8")
 def test_rich_config_context_settings(invoke: InvokeCli):
     @click.command(