io.py 935 Bytes
Newer Older
Matteo's avatar
Matteo committed
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
43
44
45
46
47
48
49
50
51
52
53
54
from enum import Enum

END = '\033[0m'


class Style(Enum):
    """
    Styles for console output
    """
    BOLD = '\033[1m'
    UNDERLINE = '\033[4m'


class Color(Enum):
    """
    Colors for console output
    """
    PURPLE = '\033[95m'
    CYAN = '\033[96m'
    DARK_CYAN = '\033[36m'
    BLUE = '\033[94m'
    GREEN = '\033[92m'
    YELLOW = '\033[93m'
    RED = '\033[91m'


def prettify(text: str, color: Color = None, styles: list[Style] = None) -> str:
    """
    Formats a string with some styles

    Parameters
    ----------
    text : str
        string to format
    color : Color, optional
        color to use
    styles : list[Style], optional
        styles to use
    
    Returns
    -------
    str
        formatted string
    """

    prepend = ''

    if color:
        prepend += color.value
    if styles:
        for style in styles:
            prepend += style.value

    return prepend + text + END