don't use console instance anymore

This commit is contained in:
Sina Atalay 2024-02-10 20:32:16 +01:00
parent 017cba42fc
commit 5825abf908
1 changed files with 11 additions and 9 deletions

View File

@ -1,20 +1,17 @@
from typing import Callable, Optional from typing import Callable, Optional
import re import re
import rich from rich import print
import rich.console import rich.console
import rich.panel import rich.panel
import rich.live import rich.live
import rich.table import rich.table
import rich.text import rich.text
import rich.progress import rich.progress
import pydantic_core
import pydantic import pydantic
import ruamel.yaml import ruamel.yaml
import ruamel.yaml.parser import ruamel.yaml.parser
console = rich.console.Console()
def welcome(): def welcome():
"""Print a welcome message to the terminal.""" """Print a welcome message to the terminal."""
@ -31,22 +28,27 @@ def welcome():
table.add_row("Bug reports", "https://github.com/sinaatalay/rendercv/issues/") table.add_row("Bug reports", "https://github.com/sinaatalay/rendercv/issues/")
table.add_row("Feature requests", "https://github.com/sinaatalay/rendercv/issues/") table.add_row("Feature requests", "https://github.com/sinaatalay/rendercv/issues/")
console.print(table) print(table)
def warning(text): def warning(text):
"""Print a warning message to the terminal.""" """Print a warning message to the terminal."""
console.print(f"[bold yellow]{text}") print(f"[bold yellow]{text}")
def error(text, exception=None): def error(text, exception=None):
"""Print an error message to the terminal.""" """Print an error message to the terminal."""
console.print(f"\n[bold red]{text}[/bold red]\n\n[orange4]{exception}") if exception is not None:
exception_messages = exception.args
exception_message = "\n\n".join(exception_messages)
print(f"\n[bold red]{text}[/bold red]\n\n[orange4]{exception_message}[/orange4]")
else:
print(f"[bold red]{text}")
def information(text): def information(text):
"""Print an information message to the terminal.""" """Print an information message to the terminal."""
console.print(f"[bold green]{text}") print(f"[bold green]{text}")
def get_error_message_and_location_and_value_from_a_custom_error( def get_error_message_and_location_and_value_from_a_custom_error(
@ -119,7 +121,7 @@ def handle_validation_error(exception: pydantic.ValidationError):
error_object["msg"], error_object["msg"],
) )
console.print(table) print(table)
def handle_exceptions(function: Callable) -> Callable: def handle_exceptions(function: Callable) -> Callable: