File size: 1,322 Bytes
532f1f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from typing import Any, Dict
from rich.console import Console
from rich.markdown import Markdown
from rich.status import Status


def dict_to_markdown_table(dictionary: Dict[str, Any]) -> str:
    table = "| Key | Value |\n| --- | ----- |\n"
    for key, value in dictionary.items():
        table += f"| {key} | {value} |\n"
    return table


class ConsoleManager:
    def __init__(self) -> None:
        self.console = Console()

    def print_markdown(self, markdown: str) -> None:
        self.console.print(Markdown(markdown))

    def print_success(self, message: str) -> None:
        self.console.print(f"[bold green](success)[/bold green] {message}")

    def print_error(self, message: str) -> None:
        self.console.print(f"[bold red](error)[/bold red] {message}")

    def print_info(self, message: str) -> None:
        self.console.print(f"[bold blue](info)[/bold blue] {message}")

    def print_dict(self, dictionary: Dict[str, Any], header: str = "") -> None:
        markdown_table = dict_to_markdown_table(dictionary)
        if header:
            self.print_markdown(f"# {header}\n")

        self.console.print(Markdown(markdown_table))

    def status(self, message: str) -> Status:
        return self.console.status(f"[bold green]{message}[/bold green]")


console_manager = ConsoleManager()