Skip to content

Commit

Permalink
Refactor warning display with Rich formatting.
Browse files Browse the repository at this point in the history
Replace plain click-based warnings with styled Rich panels for better visibility. This enhances user experience by providing clearer and more visually organized warnings.
  • Loading branch information
coordt committed Dec 14, 2024
1 parent 39fed07 commit 2b7c905
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion bumpversion/ui.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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),
)
)

0 comments on commit 2b7c905

Please sign in to comment.