From 2b7c905c792e1cbe22040a5ba890c4440990f99b Mon Sep 17 00:00:00 2001 From: Corey Oordt Date: Sat, 14 Dec 2024 08:37:24 -0600 Subject: [PATCH] Refactor warning display with Rich formatting. Replace plain click-based warnings with styled Rich panels for better visibility. This enhances user experience by providing clearer and more visually organized warnings. --- bumpversion/ui.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/bumpversion/ui.py b/bumpversion/ui.py index 8b8fa110..55dc191e 100644 --- a/bumpversion/ui.py +++ b/bumpversion/ui.py @@ -1,10 +1,14 @@ """Utilities for user interface.""" import logging +import sys import click from click import UsageError, secho from rich.logging import RichHandler +from rich.padding import Padding +from rich.panel import Panel +from rich_click.rich_help_formatter import RichHelpFormatter from bumpversion.indented_logger import IndentedLoggerAdapter @@ -50,4 +54,17 @@ def print_error(msg: str) -> None: def print_warning(msg: str) -> None: """Echo a warning to the console.""" - secho(f"\nWARNING:\n\n{msg}\n", fg="yellow") + formatter = RichHelpFormatter(file=sys.stderr) + config = formatter.config + + formatter.write( + Padding( + Panel( + formatter.highlighter(msg), + border_style="yellow", + title="Warning", + title_align=config.align_errors_panel, + ), + (0, 0, 1, 0), + ) + )