|
3 | 3 | style = Style.from_dict( |
4 | 4 | {"green": "#a0d762 bold", "red": "#e67061 bold", "command": "#f78ae0 bold"} |
5 | 5 | ) |
| 6 | + |
| 7 | + |
| 8 | +class Ansi: |
| 9 | + """ |
| 10 | + This class contains the ANSI escape codes for printing to the console as |
| 11 | + well as commonly used combinations of these codes. |
| 12 | + """ |
| 13 | + |
| 14 | + reset = "\033[0m" |
| 15 | + bold = "\033[1m" |
| 16 | + faint = "\033[2m" |
| 17 | + italic = "\033[3m" |
| 18 | + underline = "\033[4m" |
| 19 | + blink = "\033[5m" |
| 20 | + inverse = "\033[7m" |
| 21 | + |
| 22 | + class fg: |
| 23 | + black = "\033[30m" |
| 24 | + red = "\033[31m" |
| 25 | + green = "\033[32m" |
| 26 | + yellow = "\033[33m" |
| 27 | + blue = "\033[34m" |
| 28 | + magenta = "\033[35m" |
| 29 | + cyan = "\033[36m" |
| 30 | + white = "\033[37m" |
| 31 | + |
| 32 | + grey = "\033[90m" |
| 33 | + bright_red = "\033[91m" |
| 34 | + bright_green = "\033[92m" |
| 35 | + bright_yellow = "\033[93m" |
| 36 | + bright_blue = "\033[94m" |
| 37 | + bright_magenta = "\033[95m" |
| 38 | + bright_cyan = "\033[96m" |
| 39 | + bright_white = "\033[97m" |
| 40 | + |
| 41 | + class bg: |
| 42 | + black = "\033[40m" |
| 43 | + red = "\033[41m" |
| 44 | + green = "\033[42m" |
| 45 | + yellow = "\033[43m" |
| 46 | + blue = "\033[44m" |
| 47 | + magenta = "\033[45m" |
| 48 | + cyan = "\033[46m" |
| 49 | + white = "\033[47m" |
| 50 | + |
| 51 | + grey = "\033[100m" |
| 52 | + bright_red = "\033[101m" |
| 53 | + bright_green = "\033[102m" |
| 54 | + bright_yellow = "\033[103m" |
| 55 | + bright_blue = "\033[104m" |
| 56 | + bright_magenta = "\033[105m" |
| 57 | + bright_cyan = "\033[106m" |
| 58 | + bright_white = "\033[107m" |
| 59 | + |
| 60 | + @classmethod |
| 61 | + def colour(cls, *args): |
| 62 | + """Combines all args into string. Should pass colour modifiers in first followed by the string. Does not need reset sequence at the end.""" |
| 63 | + return "".join(args) + cls.reset |
| 64 | + |
| 65 | + @classmethod |
| 66 | + def b_green(cls, content): |
| 67 | + return cls.fg.bright_green + cls.bold + str(content) + cls.reset |
| 68 | + |
| 69 | + @classmethod |
| 70 | + def b_red(cls, content): |
| 71 | + return cls.fg.bright_red + cls.bold + str(content) + cls.reset |
| 72 | + |
| 73 | + @classmethod |
| 74 | + def b_yellow(cls, content): |
| 75 | + return cls.fg.bright_yellow + cls.bold + str(content) + cls.reset |
| 76 | + |
| 77 | + @classmethod |
| 78 | + def b_blue(cls, content): |
| 79 | + return cls.fg.bright_blue + cls.bold + str(content) + cls.reset |
| 80 | + |
| 81 | + @classmethod |
| 82 | + def print_ok(cls, content, end="\n"): |
| 83 | + print(cls.b_green(content), end=end) |
| 84 | + |
| 85 | + @classmethod |
| 86 | + def print_error(cls, content, end="\n"): |
| 87 | + print(cls.b_red(content), end=end) |
| 88 | + |
| 89 | + @classmethod |
| 90 | + def print_warning(cls, content, end="\n"): |
| 91 | + print(cls.b_yellow(content), end=end) |
| 92 | + |
| 93 | + @classmethod |
| 94 | + def print_info(cls, content, end="\n"): |
| 95 | + print(cls.b_blue(content), end=end) |
0 commit comments