Kernel: Make TTY a class
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <BAN/String.h>
|
||||
#include <kernel/Keyboard.h>
|
||||
#include <kernel/TTY.h>
|
||||
|
||||
namespace Kernel
|
||||
{
|
||||
@@ -13,6 +14,8 @@ namespace Kernel
|
||||
|
||||
static Shell& Get();
|
||||
|
||||
void SetTTY(TTY* tty);
|
||||
|
||||
void Run();
|
||||
|
||||
private:
|
||||
@@ -22,7 +25,8 @@ namespace Kernel
|
||||
void KeyEventCallback(Keyboard::KeyEvent);
|
||||
|
||||
private:
|
||||
BAN::String m_buffer;
|
||||
TTY* m_tty;
|
||||
BAN::String m_buffer;
|
||||
};
|
||||
|
||||
}
|
||||
46
kernel/include/kernel/TTY.h
Normal file
46
kernel/include/kernel/TTY.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include <kernel/VESA.h>
|
||||
#include <kernel/Serial.h>
|
||||
|
||||
class TTY
|
||||
{
|
||||
public:
|
||||
TTY();
|
||||
void Clear();
|
||||
void PutChar(char ch);
|
||||
void Write(const char* data, size_t size);
|
||||
void WriteString(const char* data);
|
||||
void SetCursorPos(int x, int y);
|
||||
|
||||
static void PutCharCurrent(char ch);
|
||||
|
||||
private:
|
||||
void ResetAnsiEscape();
|
||||
void HandleAnsiSGR();
|
||||
void HandleAnsiEscape(uint16_t ch);
|
||||
|
||||
private:
|
||||
struct Cell
|
||||
{
|
||||
VESA::Color foreground = VESA::Color::BRIGHT_WHITE;
|
||||
VESA::Color background = VESA::Color::BLACK;
|
||||
uint8_t character = ' ';
|
||||
};
|
||||
|
||||
struct AnsiState
|
||||
{
|
||||
uint8_t mode = '\0';
|
||||
int32_t index = 0;
|
||||
int32_t nums[2] = { -1, -1 };
|
||||
};
|
||||
|
||||
uint32_t m_width { 0 };
|
||||
uint32_t m_height { 0 };
|
||||
uint32_t m_row { 0 };
|
||||
uint32_t m_column { 0 };
|
||||
VESA::Color m_foreground { VESA::Color::BRIGHT_WHITE};
|
||||
VESA::Color m_background { VESA::Color::BLACK };
|
||||
Cell* m_buffer { nullptr };
|
||||
AnsiState m_ansi_state;
|
||||
};
|
||||
@@ -25,8 +25,7 @@ namespace VESA
|
||||
BRIGHT_WHITE = 15,
|
||||
};
|
||||
|
||||
bool PreInitialize();
|
||||
void Initialize();
|
||||
bool Initialize();
|
||||
void PutEntryAt(uint16_t, uint32_t, uint32_t, Color, Color);
|
||||
void Clear(Color);
|
||||
void Scroll();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <BAN/Formatter.h>
|
||||
#include <kernel/tty.h>
|
||||
#include <kernel/TTY.h>
|
||||
|
||||
#define kprint(...) BAN::Formatter::print<TTY::putchar>(__VA_ARGS__)
|
||||
#define kprintln(...) BAN::Formatter::println<TTY::putchar>(__VA_ARGS__)
|
||||
#define kprint(...) BAN::Formatter::print<TTY::PutCharCurrent>(__VA_ARGS__)
|
||||
#define kprintln(...) BAN::Formatter::println<TTY::PutCharCurrent>(__VA_ARGS__)
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
namespace TTY
|
||||
{
|
||||
|
||||
void initialize();
|
||||
void putchar(char c);
|
||||
void clear();
|
||||
void write(const char* data, size_t size);
|
||||
void writestring(const char* data);
|
||||
void set_cursor_pos(int x, int y);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user