This repository was archived by the owner on Nov 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkcon.hpp
155 lines (128 loc) · 3.67 KB
/
kcon.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __FENNIX_KERNEL_KERNEL_CONSOLE_H__
#define __FENNIX_KERNEL_KERNEL_CONSOLE_H__
#include <display.hpp>
#include <tty.hpp>
namespace KernelConsole
{
enum TerminalColor
{
BLACK,
RED,
GREEN,
YELLOW,
BLUE,
MAGENTA,
CYAN,
GREY
};
struct ANSIArgument
{
int Value = 0;
bool Empty = true;
};
struct ANSIParser
{
enum ParserState
{
Escape,
Bracket,
Attribute,
EndValue
} State = Escape;
ANSIArgument Stack[8] = {};
int Index = 0;
};
struct TerminalAttribute
{
bool Bright = false;
TerminalColor Background = BLACK;
TerminalColor Foreground = GREY;
};
struct TerminalCell
{
char c = '\0';
TerminalAttribute attr{};
};
struct TerminalCursor
{
long X = 0;
long Y = 0;
};
typedef void (*PaintCallback)(TerminalCell *Cell, long X, long Y);
typedef void (*CursorCallback)(TerminalCursor *Cursor);
class FontRenderer
{
public:
Video::Font *CurrentFont = nullptr;
TerminalCursor Cursor = {0, 0};
char Paint(long CellX, long CellY, char Char, uint32_t Foreground, uint32_t Background);
};
class VirtualTerminal : public TTY::TeletypeDriver
{
private:
ANSIParser Parser{};
TerminalAttribute Attribute{};
TerminalCell *Cells = nullptr;
TerminalCursor Cursor{};
PaintCallback PaintCB = nullptr;
CursorCallback CursorCB = nullptr;
std::mutex Mutex;
public:
termios *GetTermios() { return &this->TerminalConfig; }
winsize *GetWinsize() { return &this->TerminalSize; }
int Open(int Flags, mode_t Mode) final;
int Close() final;
ssize_t Read(void *Buffer, size_t Size, off_t Offset) final;
ssize_t Write(const void *Buffer, size_t Size, off_t Offset) final;
int Ioctl(unsigned long Request, void *Argp) final;
void Clear(unsigned short StartX, unsigned short StartY, unsigned short EndX, unsigned short EndY);
void Scroll(unsigned short Lines);
void NewLine();
void Append(char c);
void csi_cup(ANSIArgument *Args, int ArgsCount);
void csi_ed(ANSIArgument *Args, int ArgsCount);
void csi_el(ANSIArgument *Args, int ArgsCount);
void csi_sgr(ANSIArgument *Args, int ArgsCount);
void csi_cuu(ANSIArgument *Args, int ArgsCount);
void csi_cud(ANSIArgument *Args, int ArgsCount);
void csi_cuf(ANSIArgument *Args, int ArgsCount);
void csi_cub(ANSIArgument *Args, int ArgsCount);
void csi_cnl(ANSIArgument *Args, int ArgsCount);
void csi_cpl(ANSIArgument *Args, int ArgsCount);
void csi_cha(ANSIArgument *Args, int ArgsCount);
void Process(char c);
VirtualTerminal(unsigned short Rows, unsigned short Columns,
unsigned short XPixels, unsigned short YPixels,
PaintCallback Paint, CursorCallback Print);
~VirtualTerminal();
};
/**
* 0 - Default
* 1...11 - User
* ...
* 15 - Panic
*/
extern VirtualTerminal *Terminals[16];
extern std::atomic<VirtualTerminal *> CurrentTerminal;
extern int TermColors[];
extern int TermBrightColors[];
bool SetTheme(std::string Theme);
/* Limited in functionality */
void EarlyInit();
/* Full working terminal */
void LateInit();
}
#endif // !__FENNIX_KERNEL_KERNEL_CONSOLE_H__