Max OS 0.3
Loading...
Searching...
No Matches
console.h
Go to the documentation of this file.
1
9#ifndef MAXOS_DRIVERS_CONSOLE_H
10#define MAXOS_DRIVERS_CONSOLE_H
11
12#include <cstdint>
13#include <common/outputStream.h>
14#include <common/colour.h>
15
16
17namespace MaxOS::drivers::console {
18
19
24 class Console {
25 public:
26 Console();
27 ~Console();
28
29 virtual uint16_t width();
30 virtual uint16_t height();
31
32 virtual void put_character(uint16_t x, uint16_t y, char c);
33 virtual char get_character(uint16_t x, uint16_t y);
34
35 virtual void set_foreground_color(uint16_t x, uint16_t y, common::ConsoleColour foreground);
36 virtual void set_background_color(uint16_t x, uint16_t y, common::ConsoleColour background);
37
38 virtual common::ConsoleColour get_foreground_color(uint16_t x, uint16_t y);
39 virtual common::ConsoleColour get_background_color(uint16_t x, uint16_t y);
40
41
42 virtual void put_character(uint16_t x, uint16_t y, char c, common::ConsoleColour foreground, common::ConsoleColour background);
43 virtual void put_string(uint16_t x, uint16_t y, string s, common::ConsoleColour foreground = common::ConsoleColour::LightGrey, common::ConsoleColour background = common::ConsoleColour::Black);
44
45 virtual void scroll_up();
46 virtual void scroll_up(uint16_t left, uint16_t top, uint16_t width, uint16_t height, common::ConsoleColour foreground = common::ConsoleColour::LightGrey, common::ConsoleColour background = common::ConsoleColour::Black, char fill = ' ');
47
48 virtual void clear();
49 virtual void clear(uint16_t left, uint16_t top, uint16_t width, uint16_t height, common::ConsoleColour foreground = common::ConsoleColour::LightGrey, common::ConsoleColour background = common::ConsoleColour::Black, char fill = ' ');
50
51 virtual void invert_colors(uint16_t x, uint16_t y);
52
53 };
54
59 class ConsoleArea : public Console {
60 private:
61 Console* m_console;
62 uint16_t m_left;
63 uint16_t m_top;
64 uint16_t m_width;
65 uint16_t m_height;
66
67 public:
68 ConsoleArea(Console* console, uint16_t left, uint16_t top, uint16_t width, uint16_t height);
69 ConsoleArea(Console* console, uint16_t left, uint16_t top, uint16_t width, uint16_t height, common::ConsoleColour foreground, common::ConsoleColour background);
71
72 uint16_t width() override;
73 uint16_t height() override;
74
75 void put_character(uint16_t x, uint16_t y, char c) override;
76 void set_foreground_color(uint16_t x, uint16_t y, common::ConsoleColour foreground) override;
77 void set_background_color(uint16_t x, uint16_t y, common::ConsoleColour background) override;
78
79 void scroll_up() override;
80 void scroll_up(uint16_t left, uint16_t top, uint16_t width, uint16_t height, common::ConsoleColour foreground = common::ConsoleColour::LightGrey, common::ConsoleColour background = common::ConsoleColour::Black, char fill = ' ') override;
81
82 char get_character(uint16_t x, uint16_t y) override;
83 common::ConsoleColour get_foreground_color(uint16_t x, uint16_t y) override;
84 common::ConsoleColour get_background_color(uint16_t x, uint16_t y) override;
85 };
86
92 private:
93 Console* m_console;
94
95 common::ConsoleColour m_foreground { common::ConsoleColour::LightGrey };
96 common::ConsoleColour m_background { common::ConsoleColour::Black };
97 bool is_ansi = false;
98
99 uint16_t m_cursor_x { 0 };
100 uint16_t m_cursor_y { 0 };
101
102 public:
103
104 explicit ConsoleStream(Console*);
106
107 void write_char(char c) override;
108 void set_cursor(uint16_t x, uint16_t y);
109 };
110
111}
112
113
114#endif //MAXOS_DRIVERS_CONSOLE_H
A stream that strings can be written to.
A console that is a subsection of another console, limited by a width and height.
Definition console.h:59
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.
Definition console.cpp:348
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...
Definition console.cpp:365
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...
Definition console.cpp:330
uint16_t height() override
Return the height of the console area.
Definition console.cpp:283
void scroll_up() override
Scroll the console area up by 1 line.
Definition console.cpp:396
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.
Definition console.cpp:294
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...
Definition console.cpp:312
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...
Definition console.cpp:383
uint16_t width() override
Return the width of the console area.
Definition console.cpp:274
A stream that can be used to write to a console.
Definition console.h:91
void write_char(char c) override
write a character to the console stream
Definition console.cpp:436
void set_cursor(uint16_t x, uint16_t y)
Set the m_position of the cursor.
Definition console.cpp:510
Abstract class for a console, allows for the printing of characters and strings with colours.
Definition console.h:24
virtual void set_foreground_color(uint16_t x, uint16_t y, common::ConsoleColour foreground)
Set the foreground color of a character on the console.
Definition console.cpp:55
virtual common::ConsoleColour get_background_color(uint16_t x, uint16_t y)
Get the background color of a character on the console.
Definition console.cpp:99
virtual void scroll_up()
Scroll the entire console up by 1 line.
Definition console.cpp:142
virtual char get_character(uint16_t x, uint16_t y)
Get the character at a given coordinate on the console.
Definition console.cpp:77
virtual uint16_t height()
Get the height of the console in characters.
Definition console.cpp:34
virtual void put_string(uint16_t x, uint16_t y, string s, common::ConsoleColour foreground=common::ConsoleColour::LightGrey, common::ConsoleColour background=common::ConsoleColour::Black)
Put a string on the console.
Definition console.cpp:132
virtual void put_character(uint16_t x, uint16_t y, char c)
Put a character on the console.
Definition console.cpp:45
virtual void invert_colors(uint16_t x, uint16_t y)
Invert the colors of a character on the console.
Definition console.cpp:211
virtual uint16_t width()
Get the width of the console in characters.
Definition console.cpp:25
virtual common::ConsoleColour get_foreground_color(uint16_t x, uint16_t y)
Get the background color of a character on the console.
Definition console.cpp:88
virtual void set_background_color(uint16_t x, uint16_t y, common::ConsoleColour background)
Set the background color of a character on the console.
Definition console.cpp:66
Defines a Colour class for representing colours in RGBA format, along with ANSI and console colour en...
ConsoleColour
Enumeration of console colour codes.
Definition colour.h:67
Defines OutputStream and GenericOutputStream classes for writing data to streams.