Max OS 0.3
Loading...
Searching...
No Matches
colour.h
Go to the documentation of this file.
1
9#ifndef MAXOS_COMMON_COLOUR_H
10#define MAXOS_COMMON_COLOUR_H
11
12#include <common/string.h>
13#include <cstdint>
14
15
16namespace MaxOS::common {
17
19 const char* const ANSI_COLOURS[] = {
20 "\033[0;30m", // FG Black
21 "\033[0;31m", // FG Red
22 "\033[0;32m", // FG Green
23 "\033[0;33m", // FG Yellow
24 "\033[0;34m", // FG Blue
25 "\033[0;35m", // FG Magenta
26 "\033[0;36m", // FG Cyan
27 "\033[0;37m", // FG White
28 "\033[0;40m", // BG Black
29 "\033[0;41m", // BG Red
30 "\033[0;42m", // BG Green
31 "\033[0;43m", // BG Yellow
32 "\033[0;44m", // BG Blue
33 "\033[0;45m", // BG Magenta
34 "\033[0;46m", // BG Cyan
35 "\033[0;47m", // BG White
36 "\033[0m" // Reset
37 };
38
44 FG_Black,
45 FG_Red,
46 FG_Green,
47 FG_Yellow,
48 FG_Blue,
49 FG_Magenta,
50 FG_Cyan,
51 FG_White,
52 BG_Black,
53 BG_Red,
54 BG_Green,
55 BG_Yellow,
56 BG_Blue,
57 BG_Magenta,
58 BG_Cyan,
59 BG_White,
60 Reset,
61 };
62
67 enum class ConsoleColour {
68 Uninitialised = 0xFF,
69 Black = 0x00,
70 Blue = 0x01,
71 Green = 0x02,
72 Cyan = 0x03,
73 Red = 0x04,
74 Magenta = 0x05,
75 Brown = 0x06,
76 LightGrey = 0x07,
77 DarkGrey = 0x08,
78 LightBlue = 0x09,
79 LightGreen = 0x0A,
80 LightCyan = 0x0B,
81 LightRed = 0x0C,
82 LightMagenta = 0x0D,
83 Yellow = 0x0E,
84 White = 0x0F
85 };
86
91 class Colour {
92 private:
93 void parse_hex_string(string hex_string);
94 void parse_ansi_string(string ansi_string);
95
96 void parse_console_colour(ConsoleColour colour);
97
98 public:
99 uint8_t red { 0 };
100 uint8_t green { 0 };
101 uint8_t blue { 0 };
102 uint8_t alpha { 0 };
103
104
105 Colour();
106 explicit Colour(ConsoleColour colour);
107 explicit Colour(string string);
108 Colour(uint8_t red, uint8_t green, uint8_t blue);
109 Colour(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha);
110
111 ~Colour();
112
113 [[nodiscard]] ConsoleColour to_console_colour() const;
114 };
115
116}
117
118
119#endif //MAXOS_COMMON_COLOUR_H
Stores the red, green, blue and alpha values of a colour. Can be parsed from a hex string,...
Definition colour.h:91
ConsoleColour to_console_colour() const
Converts the colour to a console colour.
Definition colour.cpp:261
uint8_t alpha
The amount of alpha 0-255 (0 is visible, 255 is invisible) todo: confirm.
Definition colour.h:102
uint8_t green
The amount of green 0-255.
Definition colour.h:100
uint8_t blue
The amount of blue 0-255.
Definition colour.h:101
uint8_t red
The amount of red 0-255.
Definition colour.h:99
ConsoleColour
Enumeration of console colour codes.
Definition colour.h:67
const char *const ANSI_COLOURS[]
ANSI Colour Codes.
Definition colour.h:19
ANSIColour
Enumeration of ANSI colour codes for foreground and background colours.
Definition colour.h:43
Defines a String class for dynamically sized strings with various operations.