summaryrefslogtreecommitdiff
path: root/venv/lib/python3.11/site-packages/rich_click/rich_context.py
diff options
context:
space:
mode:
Diffstat (limited to 'venv/lib/python3.11/site-packages/rich_click/rich_context.py')
-rw-r--r--venv/lib/python3.11/site-packages/rich_click/rich_context.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/venv/lib/python3.11/site-packages/rich_click/rich_context.py b/venv/lib/python3.11/site-packages/rich_click/rich_context.py
new file mode 100644
index 0000000..8e5e0a2
--- /dev/null
+++ b/venv/lib/python3.11/site-packages/rich_click/rich_context.py
@@ -0,0 +1,47 @@
+from typing import Any, Optional, Type
+
+import click
+from rich.console import Console
+
+from rich_click.rich_help_configuration import RichHelpConfiguration
+from rich_click.rich_help_formatter import RichHelpFormatter
+
+
+class RichContext(click.Context):
+ """Click Context class endowed with Rich superpowers."""
+
+ formatter_class: Type[RichHelpFormatter] = RichHelpFormatter
+
+ def __init__(
+ self,
+ *args: Any,
+ rich_console: Optional[Console] = None,
+ rich_help_config: Optional[RichHelpConfiguration] = None,
+ **kwargs: Any,
+ ) -> None:
+ """Create Rich Context instance.
+
+ Args:
+ rich_console: Rich Console.
+ Defaults to None.
+ rich_help_config: Rich help configuration.
+ Defaults to None.
+ """
+ super().__init__(*args, **kwargs)
+ parent: Optional[RichContext] = kwargs.pop("parent", None)
+
+ if rich_console is None and hasattr(parent, "console"):
+ rich_console = parent.console # type: ignore[has-type,union-attr]
+
+ self.console = rich_console
+
+ if rich_help_config is None and hasattr(parent, "help_config"):
+ rich_help_config = parent.help_config # type: ignore[has-type,union-attr]
+
+ self.help_config = rich_help_config
+
+ def make_formatter(self) -> RichHelpFormatter:
+ """Create the Rich Help Formatter."""
+ return self.formatter_class(
+ width=self.terminal_width, max_width=self.max_content_width, config=self.help_config
+ )