Display TTY  1
Customise your terminal's output
Loading...
Searching...
No Matches
colours.py
Go to the documentation of this file.
1"""
2# +==== BEGIN display_tty =================+
3# LOGO:
4# ..@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
5# .@...........................#@
6# @############################.@
7# @...........................@.@
8# @..#######################..@.@
9# @.#########################.@.@
10# @.##>_#####################.@.@
11# @.#########################.@.@
12# @.#########################.@.@
13# @.#########################.@.@
14# @.#########################.@.@
15# @..#######################..@.@
16# @...........................@.@
17# @..+----+______________.....@.@
18# @..+....+______________+....@.@
19# @..+----+...................@.@
20# @...........................@.#
21# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@#.
22# /STOP
23# PROJECT: display_tty
24# FILE: colours.py
25# CREATION DATE: 06-11-2025
26# LAST Modified: 12:31:22 06-11-2025
27# DESCRIPTION:
28# A module that allows you to display text with a few boilers (i.e. put your text in a square for titles). It also allows to log to the terminal by wrapping around the logging library.
29# /STOP
30# COPYRIGHT: (c) Henry Letellier
31# PURPOSE: File in charge of containing the class that will track logger colours that can be used by the class.
32# // AR
33# +==== END display_tty =================+
34"""
35
36
37from typing import Union
38
39
41 """
42 @class LoggerColours
43 @brief Class in charge of containing the colour names and id's that correspond to the allowed colours for the logger library.
44 """
45
46 # Colour constants
47 BLUE = 0 # @brief Colour code for blue.
48 RED = 1 # @brief Colour code for red.
49 CYAN = 2 # @brief Colour code for cyan.
50 BLACK = 3 # @brief Colour code for black.
51 GREEN = 4 # @brief Colour code for green.
52 WHITE = 5 # @brief Colour code for white.
53 YELLOW = 6 # @brief Colour code for yellow.
54 PURPLE = 7 # @brief Colour code for purple.
55 LIGHT_RED = 8 # @brief Colour code for light red.
56 LIGHT_BLUE = 9 # @brief Colour code for light blue.
57 LIGHT_CYAN = 10 # @brief Colour code for light cyan.
58 LIGHT_WHITE = 11 # @brief Colour code for light white.
59 LIGHT_BLACK = 12 # @brief Colour code for light black.
60 LIGHT_GREEN = 13 # @brief Colour code for light green.
61 LIGHT_YELLOW = 14 # @brief Colour code for light yellow.
62 LIGHT_PURPLE = 15 # @brief Colour code for light purple.
63 BOLD_BLUE = 16 # @brief Colour code for bold blue.
64 BOLD_RED = 17 # @brief Colour code for bold red.
65 BOLD_CYAN = 18 # @brief Colour code for bold cyan.
66 BOLD_BLACK = 19 # @brief Colour code for bold black.
67 BOLD_GREEN = 20 # @brief Colour code for bold green.
68 BOLD_WHITE = 21 # @brief Colour code for bold white.
69 BOLD_YELLOW = 22 # @brief Colour code for bold yellow.
70 BOLD_PURPLE = 23 # @brief Colour code for bold purple.
71 BOLD_LIGHT_RED = 24 # @brief Colour code for bold light red.
72 BOLD_LIGHT_BLUE = 25 # @brief Colour code for bold light blue.
73 BOLD_LIGHT_CYAN = 26 # @brief Colour code for bold light cyan.
74 BOLD_LIGHT_WHITE = 27 # @brief Colour code for bold light white.
75 BOLD_LIGHT_BLACK = 28 # @brief Colour code for bold light black.
76 BOLD_LIGHT_GREEN = 29 # @brief Colour code for bold light green.
77 BOLD_LIGHT_YELLOW = 30 # @brief Colour code for bold light yellow.
78 BOLD_LIGHT_PURPLE = 31 # @brief Colour code for bold light purple.
79 THIN_BLUE = 32 # @brief Colour code for thin blue.
80 THIN_RED = 33 # @brief Colour code for thin red.
81 THIN_CYAN = 34 # @brief Colour code for thin cyan.
82 THIN_BLACK = 35 # @brief Colour code for thin black.
83 THIN_GREEN = 36 # @brief Colour code for thin green.
84 THIN_WHITE = 37 # @brief Colour code for thin white.
85 THIN_YELLOW = 38 # @brief Colour code for thin yellow.
86 THIN_PURPLE = 39 # @brief Colour code for thin purple.
87 THIN_LIGHT_RED = 40 # @brief Colour code for thin light red.
88 THIN_LIGHT_BLUE = 41 # @brief Colour code for thin light blue.
89 THIN_LIGHT_CYAN = 42 # @brief Colour code for thin light cyan.
90 THIN_LIGHT_WHITE = 43 # @brief Colour code for thin light white.
91 THIN_LIGHT_BLACK = 44 # @brief Colour code for thin light black.
92 THIN_LIGHT_GREEN = 45 # @brief Colour code for thin light green.
93 THIN_LIGHT_YELLOW = 46 # @brief Colour code for thin light yellow.
94 THIN_LIGHT_PURPLE = 47 # @brief Colour code for thin light purple.
95
96 @staticmethod
97 def get_colour_string(colour_class, colour_code: int) -> str:
98 """
99 @brief Function in charge of returning the name of the colour to use.
100 @param colour_class The class containing the colour definitions.
101 @param colour_code The integer code of the colour.
102 @return The name of the colour as a string, or an empty string if the code is invalid.
103 """
104 if isinstance(colour_code, int) is False or colour_code < 0:
105 return ""
106 for i in dir(colour_class):
107 if colour_code == getattr(colour_class, i):
108 return str(i).lower()
109 return ""
110
111 @staticmethod
112 def get_colour_code(colour_class, colour_name: str) -> Union[int, None]:
113 """
114 @brief Function in charge of returning the code of the colour to use.
115 @param colour_class The class containing the colour definitions.
116 @param colour_name The name of the colour as a string.
117 @return The integer code of the colour, or None if the name is invalid.
118 """
119 if not isinstance(colour_name, str) or not colour_name or len(colour_name) == 0:
120 return None
121 for i in dir(colour_class):
122 if callable(getattr(colour_class, i)):
123 continue
124 if colour_name == i.lower():
125 return getattr(colour_class, i)
126 return None
127
128 @staticmethod
129 def check_if_colour_present(colour_class, colour_name: str) -> bool:
130 """
131 @brief Function in charge of checking if the colour is present in the list of allowed colours.
132 @param colour_class The class containing the colour definitions.
133 @param colour_name The name of the colour as a string.
134 @return True if the colour is present, False otherwise.
135 """
136 if not isinstance(colour_name, str) or not colour_name or len(colour_name) == 0:
137 return None
138 colour_name_lower = colour_name.lower()
139 for i in dir(colour_class):
140 if callable(getattr(colour_class, i)):
141 continue
142 if colour_name_lower == i.lower():
143 return True
144 return False
145
146 @staticmethod
147 def get_all_colours(colour_class) -> list:
148 """
149 @brief Function in charge of returning the list of all the colours.
150 @param colour_class The class containing the colour definitions.
151 @return A list of all the colour names as strings.
152 """
153 colours = []
154 for i in dir(colour_class):
155 if not i.startswith("__") and not callable(getattr(colour_class, i)):
156 continue
157 colours.append(i)
158 return colours
bool check_if_colour_present(colour_class, str colour_name)
Definition colours.py:129
str get_colour_string(colour_class, int colour_code)
Definition colours.py:97
list get_all_colours(colour_class)
Definition colours.py:147
Union[int, None] get_colour_code(colour_class, str colour_name)
Definition colours.py:112