Adds usability methods to Console.

This commit is contained in:
Felix Queißner 2016-05-02 18:45:03 +02:00
parent df83857843
commit e45cd0e40e
3 changed files with 74 additions and 7 deletions

View file

@ -25,6 +25,12 @@ private:
int x; int x;
int y; int y;
Color fg, bg; Color fg, bg;
bool caretEnabled;
private:
/**
* Moves the hardware caret.
*/
void updateCaret();
public: public:
Console(Screen *screen); Console(Screen *screen);
@ -43,6 +49,38 @@ public:
*/ */
void scroll(); void scroll();
/**
* Moves the cursor to the given position
*/
void setCursor(int x, int y);
/**
* Sets the visibility of the caret.
*/
void setCaretVisible(bool visible = true);
/**
* Sets the text foreground color
*/
void setForeground(Color c) {
this->fg = c;
}
/**
* Sets the text background color
*/
void setBackground(Color c) {
this->bg = c;
}
/**
* Sets the text colors.
*/
void setColors(Color bg, Color fg) {
this->fg = fg;
this->bg = bg;
}
inline Console & operator << (char c) inline Console & operator << (char c)
{ {
this->put(c); this->put(c);

View file

@ -9,14 +9,9 @@ const char * numbers[] = {
extern "C" void init(void) extern "C" void init(void)
{ {
//*
Console::main Console::main
<< "Hello World!\n" << "Hello World!\n"
<< FColor(Color::Yellow) << "Hello color!" << FColor() << "\n" << FColor(Color::Yellow) << "Hello color!" << FColor() << "\n"
<< BColor(Color::Blue) << "Hello blue!" << BColor() << "\n" << BColor(Color::Blue) << "Hello blue!" << BColor() << "\n"
<< "Hello default color.\n"; << "Hello default color.\n";
//*/
for(int i = 0; i < 22; i++) {
Console::main << "Line " << numbers[i%10] << "\n";
}
} }

View file

@ -5,9 +5,10 @@ Console Console::main(&Screen::main);
Console::Console(Screen *screen) : Console::Console(Screen *screen) :
screen(screen), screen(screen),
x(0), y(0), x(0), y(0),
fg(Color::White), bg(Color::Black) fg(Color::White), bg(Color::Black),
caretEnabled(true)
{ {
this->updateCaret();
} }
void Console::put(char c) void Console::put(char c)
@ -28,6 +29,7 @@ void Console::put(char c)
if(this->x >= this->screen->height) { if(this->x >= this->screen->height) {
this->newline(); this->newline();
} }
this->updateCaret();
} }
void Console::newline() { void Console::newline() {
@ -37,6 +39,7 @@ void Console::newline() {
if(this->y >= this->screen->height) { if(this->y >= this->screen->height) {
this->scroll(); this->scroll();
} }
this->updateCaret();
} }
void Console::scroll() { void Console::scroll() {
@ -49,4 +52,35 @@ void Console::scroll() {
} }
} }
this->y -= 1; this->y -= 1;
this->updateCaret();
}
void Console::setCursor(int x, int y)
{
if(x < 0)
x = 0;
else if(x >= this->screen->width)
x = this->screen->width - 1;
if(y < 0)
y = 0;
else if(y >= this->screen->height)
y = this->screen->height - 1;
this->x = x;
this->y = y;
this->updateCaret();
}
void Console::updateCaret()
{
if(this->caretEnabled) {
// Move caret to current position.
} else {
// Move caret outside the screen.
}
}
void Console::setCaretVisible(bool visible)
{
this->caretEnabled = visible;
this->updateCaret();
} }