Implement Virtual Terminal and fix /dev/kcon

This commit is contained in:
EnderIce2
2024-09-22 13:17:19 +03:00
parent 6f8e486740
commit 85b6fdef80
38 changed files with 1447 additions and 871 deletions

View File

@ -184,17 +184,10 @@ namespace Video
{
private:
BootInfo::FramebufferInfo framebuffer;
Font *DefaultFont = nullptr;
Font *CurrentFont = nullptr;
bool ColorIteration = false;
int ColorPickerIteration = 0;
void *Buffer;
size_t Size;
uint32_t Width, Height;
uint32_t Color;
uint32_t CursorX, CursorY;
bool DoNotScroll;
bool DirectWrite;
uint32_t RegionWidth = 64, RegionHeight = 64;
@ -207,9 +200,6 @@ namespace Video
decltype(Height) &GetHeight = Height;
BootInfo::FramebufferInfo GetFramebufferStruct() { return framebuffer; }
Font *GetDefaultFont() { return DefaultFont; }
Font *GetCurrentFont();
void SetCurrentFont(Font *Font);
uint16_t GetBitsPerPixel();
size_t GetPitch();
@ -219,41 +209,12 @@ namespace Video
void DrawRectangle(uint32_t X, uint32_t Y,
uint32_t Width, uint32_t Height,
uint32_t Color);
void Scroll(int Lines);
void SetDoNotScroll(bool Value)
{
this->DoNotScroll = Value;
}
void SetBufferCursor(uint32_t X, uint32_t Y)
{
this->CursorX = X;
this->CursorY = Y;
}
void GetBufferCursor(uint32_t *X, uint32_t *Y)
{
*X = this->CursorX;
*Y = this->CursorY;
}
void UpdateRegion(size_t RegionRow, size_t RegionColumn);
void MarkRegionDirty(size_t RegionRow, size_t RegionCol);
void UpdateBuffer();
char Print(char Char,
Video::Font *Font = nullptr,
bool WriteToUART = false,
bool IgnoreSpecialChars = false);
void PrintString(const char *String,
Video::Font *Font = nullptr,
bool WriteToUART = false,
bool IgnoreSpecialChars = false);
Display(BootInfo::FramebufferInfo Info,
bool LoadDefaultFont = true,
bool DirectWrite = true);
~Display();
};

View File

@ -18,11 +18,130 @@
#ifndef __FENNIX_KERNEL_KERNEL_CONSOLE_H__
#define __FENNIX_KERNEL_KERNEL_CONSOLE_H__
#include <display.hpp>
#include <termios.h>
#include <atomic>
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
{
private:
ANSIParser Parser{};
TerminalAttribute Attribute{};
TerminalCell *Cells = nullptr;
TerminalCursor Cursor{};
PaintCallback PaintCB = nullptr;
CursorCallback CursorCB = nullptr;
public:
termios term;
winsize termSize;
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();
}

View File

@ -75,6 +75,8 @@ typedef __builtin_va_list va_list;
#define offsetof(type, member) __builtin_offsetof(type, member)
#define RGB_TO_HEX(r, g, b) ((r << 16) | (g << 8) | (b))
#define MAX(a, b) \
({ \
__typeof__(a) _a = (a); \