12using namespace MaxOS::common;
13using namespace MaxOS::console;
15Console::Console() =
default;
17Console::~Console() =
default;
88 return ConsoleColour::Green;
99 return ConsoleColour::Green;
111void Console::put_character(uint16_t x, uint16_t y,
char c, common::ConsoleColour foreground, common::ConsoleColour background) {
131void Console::put_string(uint16_t x, uint16_t y,
string string, ConsoleColour foreground, ConsoleColour background) {
134 for(
size_t i = 0; i <
string.length(); i++)
157void Console::scroll_up(uint16_t left, uint16_t top, uint16_t width, uint16_t height, common::ConsoleColour foreground, common::ConsoleColour background,
char fill) {
160 for(
int y = top; y < top +
height - 1; y++)
161 for(uint32_t x = left; x < left +
width; x++)
166 for(uint16_t x = left; x < left +
width; x++)
191void Console::clear(uint16_t left, uint16_t top, uint16_t width, uint16_t height, common::ConsoleColour foreground, common::ConsoleColour background,
char fill) {
198 for(uint16_t y = top; y < top +
height; y++)
199 for(uint16_t x = left; x < left +
width; x++)
231 : m_console(console),
250ConsoleArea::ConsoleArea(
Console* console, uint16_t left, uint16_t top, uint16_t width, uint16_t height, common::ConsoleColour foreground, common::ConsoleColour background)
251 : m_console(console),
258 for(uint16_t y = top; y < top +
height; y++)
259 for(uint16_t x = left; x < left +
width; x++) {
266ConsoleArea::~ConsoleArea() =
default;
296 if(x >= m_width || y >= m_height)
314 if(x >= m_width || y >= m_height)
332 if(x >= m_width || y >= m_height)
350 if(x >= m_width || y >= m_height)
367 if(x >= m_width || y >= m_height)
368 return ConsoleColour::LightGrey;
385 if(x >= m_width || y >= m_height)
386 return ConsoleColour::Black;
397 m_console->
scroll_up(m_left, m_top, m_width, m_height);
412 uint16_t height, common::ConsoleColour foreground,
413 common::ConsoleColour background,
char fill) {
424 : m_console(console) {
428ConsoleStream::~ConsoleStream() =
default;
440 if(m_cursor_x >= m_console->
width() && c !=
'\n') {
446 if(c ==
'\033') is_ansi =
true;
453 if(++m_cursor_y >= m_console->
height()) {
457 m_cursor_y = m_console->
height() - 1;
481 spaces = 8 - (m_cursor_x % 8);
482 for(uint16_t i = 0; i < spaces; i++)
499 if(c ==
'm') is_ansi =
false;
char get_character(uint16_t x, uint16_t y) override
Return the character at the given coordinates if the coordinates are within the console area.
ConsoleArea(Console *console, uint16_t left, uint16_t top, uint16_t width, uint16_t height)
Construct a new Console Area object.
common::ConsoleColour get_foreground_color(uint16_t x, uint16_t y) override
Return the foreground color of the character at the given coordinates if the coordinates are within t...
void set_background_color(uint16_t x, uint16_t y, common::ConsoleColour background) override
Change the background color of a character on the console area if the coordinates are within the area...
uint16_t height() override
Return the height of the console area.
void scroll_up() override
Scroll the console area up by 1 line.
void put_character(uint16_t x, uint16_t y, char c) override
Place a character on the console area if the coordinates are within the area.
void set_foreground_color(uint16_t x, uint16_t y, common::ConsoleColour foreground) override
Change the foreground color of a character on the console area if the coordinates are within the area...
common::ConsoleColour get_background_color(uint16_t x, uint16_t y) override
Return the background color of the character at the given coordinates if the coordinates are within t...
uint16_t width() override
Return the width of the console area.
ConsoleStream(Console *)
Construct a new Console Stream object.
void write_char(char c) override
write a character to the console stream
void set_cursor(uint16_t x, uint16_t y)
Set the m_position of the cursor.
Abstract class for a console, allows for the printing of characters and strings with colours.
virtual void put_string(uint16_t x, uint16_t y, string string, common::ConsoleColour foreground=common::ConsoleColour::LightGrey, common::ConsoleColour background=common::ConsoleColour::Black)
Put a string on the console.
virtual void set_foreground_color(uint16_t x, uint16_t y, common::ConsoleColour foreground)
Set the foreground color of a character on the console.
virtual common::ConsoleColour get_background_color(uint16_t x, uint16_t y)
Get the background color of a character on the console.
virtual void scroll_up()
Scroll the entire console up by 1 line.
virtual char get_character(uint16_t x, uint16_t y)
Get the character at a given coordinate on the console.
virtual uint16_t height()
Get the height of the console in characters.
virtual void put_character(uint16_t x, uint16_t y, char c)
Put a character on the console.
virtual void invert_colors(uint16_t x, uint16_t y)
Invert the colors of a character on the console.
virtual uint16_t width()
Get the width of the console in characters.
virtual common::ConsoleColour get_foreground_color(uint16_t x, uint16_t y)
Get the background color of a character on the console.
virtual void set_background_color(uint16_t x, uint16_t y, common::ConsoleColour background)
Set the background color of a character on the console.
Defines a Console class for handling text-based console output with colour support.