Display TTY  1
Customise your terminal's output
Loading...
Searching...
No Matches
colours.py
Go to the documentation of this file.
7
8from typing import Union
9
10
12 """
13 @class LoggerColours
14 @brief Class in charge of containing the colour names and id's that correspond to the allowed colours for the logger library.
15 """
16
17 # Colour constants
18 BLUE = 0 # @brief Colour code for blue.
19 RED = 1 # @brief Colour code for red.
20 CYAN = 2 # @brief Colour code for cyan.
21 BLACK = 3 # @brief Colour code for black.
22 GREEN = 4 # @brief Colour code for green.
23 WHITE = 5 # @brief Colour code for white.
24 YELLOW = 6 # @brief Colour code for yellow.
25 PURPLE = 7 # @brief Colour code for purple.
26 LIGHT_RED = 8 # @brief Colour code for light red.
27 LIGHT_BLUE = 9 # @brief Colour code for light blue.
28 LIGHT_CYAN = 10 # @brief Colour code for light cyan.
29 LIGHT_WHITE = 11 # @brief Colour code for light white.
30 LIGHT_BLACK = 12 # @brief Colour code for light black.
31 LIGHT_GREEN = 13 # @brief Colour code for light green.
32 LIGHT_YELLOW = 14 # @brief Colour code for light yellow.
33 LIGHT_PURPLE = 15 # @brief Colour code for light purple.
34 BOLD_BLUE = 16 # @brief Colour code for bold blue.
35 BOLD_RED = 17 # @brief Colour code for bold red.
36 BOLD_CYAN = 18 # @brief Colour code for bold cyan.
37 BOLD_BLACK = 19 # @brief Colour code for bold black.
38 BOLD_GREEN = 20 # @brief Colour code for bold green.
39 BOLD_WHITE = 21 # @brief Colour code for bold white.
40 BOLD_YELLOW = 22 # @brief Colour code for bold yellow.
41 BOLD_PURPLE = 23 # @brief Colour code for bold purple.
42 BOLD_LIGHT_RED = 24 # @brief Colour code for bold light red.
43 BOLD_LIGHT_BLUE = 25 # @brief Colour code for bold light blue.
44 BOLD_LIGHT_CYAN = 26 # @brief Colour code for bold light cyan.
45 BOLD_LIGHT_WHITE = 27 # @brief Colour code for bold light white.
46 BOLD_LIGHT_BLACK = 28 # @brief Colour code for bold light black.
47 BOLD_LIGHT_GREEN = 29 # @brief Colour code for bold light green.
48 BOLD_LIGHT_YELLOW = 30 # @brief Colour code for bold light yellow.
49 BOLD_LIGHT_PURPLE = 31 # @brief Colour code for bold light purple.
50 THIN_BLUE = 32 # @brief Colour code for thin blue.
51 THIN_RED = 33 # @brief Colour code for thin red.
52 THIN_CYAN = 34 # @brief Colour code for thin cyan.
53 THIN_BLACK = 35 # @brief Colour code for thin black.
54 THIN_GREEN = 36 # @brief Colour code for thin green.
55 THIN_WHITE = 37 # @brief Colour code for thin white.
56 THIN_YELLOW = 38 # @brief Colour code for thin yellow.
57 THIN_PURPLE = 39 # @brief Colour code for thin purple.
58 THIN_LIGHT_RED = 40 # @brief Colour code for thin light red.
59 THIN_LIGHT_BLUE = 41 # @brief Colour code for thin light blue.
60 THIN_LIGHT_CYAN = 42 # @brief Colour code for thin light cyan.
61 THIN_LIGHT_WHITE = 43 # @brief Colour code for thin light white.
62 THIN_LIGHT_BLACK = 44 # @brief Colour code for thin light black.
63 THIN_LIGHT_GREEN = 45 # @brief Colour code for thin light green.
64 THIN_LIGHT_YELLOW = 46 # @brief Colour code for thin light yellow.
65 THIN_LIGHT_PURPLE = 47 # @brief Colour code for thin light purple.
66
67 @staticmethod
68 def get_colour_string(colour_class, colour_code: int) -> str:
69 """
70 @brief Function in charge of returning the name of the colour to use.
71 @param colour_class The class containing the colour definitions.
72 @param colour_code The integer code of the colour.
73 @return The name of the colour as a string, or an empty string if the code is invalid.
74 """
75 if isinstance(colour_code, int) is False or colour_code < 0:
76 return ""
77 for i in dir(colour_class):
78 if colour_code == getattr(colour_class, i):
79 return str(i).lower()
80 return ""
81
82 @staticmethod
83 def get_colour_code(colour_class, colour_name: str) -> Union[int, None]:
84 """
85 @brief Function in charge of returning the code of the colour to use.
86 @param colour_class The class containing the colour definitions.
87 @param colour_name The name of the colour as a string.
88 @return The integer code of the colour, or None if the name is invalid.
89 """
90 if not isinstance(colour_name, str) or not colour_name or len(colour_name) == 0:
91 return None
92 for i in dir(colour_class):
93 if callable(getattr(colour_class, i)):
94 continue
95 if colour_name == i.lower():
96 return getattr(colour_class, i)
97 return None
98
99 @staticmethod
100 def check_if_colour_present(colour_class, colour_name: str) -> bool:
101 """
102 @brief Function in charge of checking if the colour is present in the list of allowed colours.
103 @param colour_class The class containing the colour definitions.
104 @param colour_name The name of the colour as a string.
105 @return True if the colour is present, False otherwise.
106 """
107 if not isinstance(colour_name, str) or not colour_name or len(colour_name) == 0:
108 return None
109 colour_name_lower = colour_name.lower()
110 for i in dir(colour_class):
111 if callable(getattr(colour_class, i)):
112 continue
113 if colour_name_lower == i.lower():
114 return True
115 return False
116
117 @staticmethod
118 def get_all_colours(colour_class) -> list:
119 """
120 @brief Function in charge of returning the list of all the colours.
121 @param colour_class The class containing the colour definitions.
122 @return A list of all the colour names as strings.
123 """
124 colours = []
125 for i in dir(colour_class):
126 if not i.startswith("__") and not callable(getattr(colour_class, i)):
127 continue
128 colours.append(i)
129 return colours
bool check_if_colour_present(colour_class, str colour_name)
Definition colours.py:100
str get_colour_string(colour_class, int colour_code)
Definition colours.py:68
list get_all_colours(colour_class)
Definition colours.py:118
Union[int, None] get_colour_code(colour_class, str colour_name)
Definition colours.py:83