mirror of
https://github.com/Zeal-Operating-System/ZealOS.git
synced 2024-12-25 23:10:32 +00:00
16 colors
This commit is contained in:
parent
85b5eca553
commit
56fc4020ac
1 changed files with 107 additions and 54 deletions
|
@ -2,15 +2,15 @@
|
||||||
// Public Domain
|
// Public Domain
|
||||||
|
|
||||||
#define TELNET_PORT 23
|
#define TELNET_PORT 23
|
||||||
#define BUF_SIZE 16384 // way too big?
|
#define BUF_SIZE 8192 // way too big?
|
||||||
#define TIMEOUT_DURATION 50000
|
#define TIMEOUT_DURATION 5000
|
||||||
|
|
||||||
#define NEGOTIATE 0xFF
|
#define NEGOTIATE 0xFF
|
||||||
|
|
||||||
#define ANSI_ESC 0x1B
|
#define ANSI_ESC 0x1B
|
||||||
#define ANSI_CSI 0x5B // [
|
#define ANSI_CSI 0x5B // [
|
||||||
|
|
||||||
#define MAX_ANSI_PARAMS 256
|
#define MAX_ANSI_PARAMS 32
|
||||||
|
|
||||||
CTask *input_task = NULL;
|
CTask *input_task = NULL;
|
||||||
Bool force_disconnect = FALSE;
|
Bool force_disconnect = FALSE;
|
||||||
|
@ -228,7 +228,10 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
|
||||||
ptr++;
|
ptr++;
|
||||||
if (*ptr == ANSI_CSI) {
|
if (*ptr == ANSI_CSI) {
|
||||||
ptr++;
|
ptr++;
|
||||||
I64 ansi_code[MAX_ANSI_PARAMS];
|
I64 ansi_code[MAX_ANSI_PARAMS], counter;
|
||||||
|
for (counter = 0; counter < MAX_ANSI_PARAMS; counter++) {
|
||||||
|
ansi_code[counter] = 0; // Initialize all elements to 0
|
||||||
|
}
|
||||||
I64 ansi_param_count = 0;
|
I64 ansi_param_count = 0;
|
||||||
while (IsDigit(*ptr) || *ptr == ';') {
|
while (IsDigit(*ptr) || *ptr == ';') {
|
||||||
if (IsDigit(*ptr)) {
|
if (IsDigit(*ptr)) {
|
||||||
|
@ -251,6 +254,7 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
|
||||||
// Handle specific ANSI escape sequences
|
// Handle specific ANSI escape sequences
|
||||||
switch (*ptr) {
|
switch (*ptr) {
|
||||||
case 'n':
|
case 'n':
|
||||||
|
SysLog("Case n\n");
|
||||||
if (ansi_code[0] == 5) {
|
if (ansi_code[0] == 5) {
|
||||||
// Respond with terminal readiness
|
// Respond with terminal readiness
|
||||||
SysLog("reported terminal readiness\n");
|
SysLog("reported terminal readiness\n");
|
||||||
|
@ -274,10 +278,14 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
|
||||||
// colors might be printed in the wrong order?
|
// colors might be printed in the wrong order?
|
||||||
// like, <Esc>[1;40m and now <Esc>[40m;1m
|
// like, <Esc>[1;40m and now <Esc>[40m;1m
|
||||||
I64 m;
|
I64 m;
|
||||||
|
Bool isBright = FALSE;
|
||||||
for (m = 0; m < ansi_param_count; m++) {
|
for (m = 0; m < ansi_param_count; m++) {
|
||||||
if (ansi_code[m] <= 10) {
|
if (ansi_code[m] <= 10) {
|
||||||
|
if (ansi_param_count == 0)
|
||||||
|
{
|
||||||
switch (ansi_code[m]) {
|
switch (ansi_code[m]) {
|
||||||
case 0: "$$BG$$$$FG$$"; break; // reset
|
case 0: "$$BG$$$$FG$$"; break; // reset
|
||||||
|
// case 0: "$$BG,TRANSPARENT$$$$WHITE$$"; break; // reset
|
||||||
// case 1: ""; break; // TODO: bold
|
// case 1: ""; break; // TODO: bold
|
||||||
// case 2: ""; break; // TODO: dim
|
// case 2: ""; break; // TODO: dim
|
||||||
// case 3: ""; break; // TODO: italic
|
// case 3: ""; break; // TODO: italic
|
||||||
|
@ -290,9 +298,16 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
|
||||||
// case 10: ""; break; // TODO: primary font
|
// case 10: ""; break; // TODO: primary font
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
switch (ansi_code[m]) {
|
||||||
|
case 1: isBright = TRUE; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (ansi_code[m] >= 30 && ansi_code[m] <= 37) {
|
else if (ansi_code[m] >= 30 && ansi_code[m] <= 37) {
|
||||||
// Set foreground color
|
// Set foreground color
|
||||||
// SysLog("ansi_code[%d] = %d\n", m, ansi_code[m]);
|
// SysLog("ansi_code[%d] = %d\n", m, ansi_code[m]);
|
||||||
|
if(!isBright){
|
||||||
switch (ansi_code[m]) {
|
switch (ansi_code[m]) {
|
||||||
case 30: "$$BLACK$$"; break;
|
case 30: "$$BLACK$$"; break;
|
||||||
case 31: "$$RED$$"; break;
|
case 31: "$$RED$$"; break;
|
||||||
|
@ -302,15 +317,32 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
|
||||||
case 35: "$$PURPLE$$"; break;
|
case 35: "$$PURPLE$$"; break;
|
||||||
case 36: "$$CYAN$$"; break;
|
case 36: "$$CYAN$$"; break;
|
||||||
case 37: "$$WHITE$$"; break;
|
case 37: "$$WHITE$$"; break;
|
||||||
case 39: "$$FG$$"; break; // reset
|
case 39: "$$WHITE$$"; break; // reset
|
||||||
|
// case 39: "$$FG$$"; break; // would normally call $$FG$$ but telnet actually resets to white
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
switch (ansi_code[m]) {
|
||||||
|
case 30: "$$DKGRAY$$"; break;
|
||||||
|
case 31: "$$LTRED$$"; break;
|
||||||
|
case 32: "$$LTGREEN$$"; break;
|
||||||
|
case 33: "$$YELLOW$$"; break;
|
||||||
|
case 34: "$$LTBLUE$$"; break;
|
||||||
|
case 35: "$$LTPURPLE$$"; break;
|
||||||
|
case 36: "$$LTCYAN$$"; break;
|
||||||
|
case 37: "$$LTGRAY$$"; break;
|
||||||
|
case 39: "$$LTGRAY$$"; break; // reset
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// this is a dumb approach, just do a CatPrint or something
|
// this is a dumb approach, just do a CatPrint or something
|
||||||
// until we properly catch the `;` it will stay fucked
|
// until we properly catch the `;` it will stay buggy
|
||||||
else if (ansi_code[m] >= 40 && ansi_code[m] <= 47) {
|
else if (ansi_code[m] >= 40 && ansi_code[m] <= 47) {
|
||||||
// Set background color
|
// Set background color
|
||||||
// SysLog("ansi_code[%d] = %d\n", m, ansi_code[m]);
|
// SysLog("ansi_code[%d] = %d\n", m, ansi_code[m]);
|
||||||
|
if(!isBright){
|
||||||
switch (ansi_code[m]) {
|
switch (ansi_code[m]) {
|
||||||
case 40: "$$BG,BLACK$$"; break;
|
case 40: "$$BG,BLACK$$"; break;
|
||||||
case 41: "$$BG,RED$$"; break;
|
case 41: "$$BG,RED$$"; break;
|
||||||
|
@ -320,10 +352,27 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
|
||||||
case 45: "$$BG,PURPLE$$"; break;
|
case 45: "$$BG,PURPLE$$"; break;
|
||||||
case 46: "$$BG,CYAN$$"; break;
|
case 46: "$$BG,CYAN$$"; break;
|
||||||
case 47: "$$BG,WHITE$$"; break;
|
case 47: "$$BG,WHITE$$"; break;
|
||||||
case 49: "$$BG$$"; break; // reset
|
case 49: "$$BG,BLACK$$"; break; // reset
|
||||||
|
// case 49: "$$BG$$"; break; // would normally call $$BG$$ but telnet actually resets to black
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
switch (ansi_code[m]) {
|
||||||
|
case 40: "$$BG,DKGRAY$$"; break;
|
||||||
|
case 41: "$$BG,LTRED$$"; break;
|
||||||
|
case 42: "$$BG,LTGREEN$$"; break;
|
||||||
|
case 43: "$$BG,YELLOW$$"; break;
|
||||||
|
case 44: "$$BG,LTBLUE$$"; break;
|
||||||
|
case 45: "$$BG,LTPURPLE$$"; break;
|
||||||
|
case 46: "$$BG,LTCYAN$$"; break;
|
||||||
|
case 47: "$$BG,LTGRAY$$"; break;
|
||||||
|
case 49: "$$BG,DKGRAY$$"; break; // reset
|
||||||
|
// case 49: "$$BG$$"; break; // would normally call $$BG$$ but telnet actually resets to black
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ptr++;
|
ptr++;
|
||||||
break;
|
break;
|
||||||
|
@ -343,7 +392,7 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
|
||||||
break;
|
break;
|
||||||
case 'C':
|
case 'C':
|
||||||
// Cursor Right
|
// Cursor Right
|
||||||
// SysLog("Cursor Right %d %d\n", ansi_param_count, ansi_code[0]);
|
SysLog("Cursor Right %d %d\n", ansi_param_count, ansi_code[0]);
|
||||||
// "$$CM+LX,+%d,0$$", ansi_code[0];
|
// "$$CM+LX,+%d,0$$", ansi_code[0];
|
||||||
// "$$CM,%d,0$$", ansi_code[0];
|
// "$$CM,%d,0$$", ansi_code[0];
|
||||||
I64 C;
|
I64 C;
|
||||||
|
@ -389,15 +438,19 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
|
||||||
if(ansi_code[1] != 1)
|
if(ansi_code[1] != 1)
|
||||||
col = ansi_code[1];
|
col = ansi_code[1];
|
||||||
|
|
||||||
// Not sure if really should do -1...
|
// if (row == 0 && col == 0) {
|
||||||
if (row > window_height)
|
// ptr++;
|
||||||
row = window_height-1;
|
// break;
|
||||||
if (col > window_width)
|
// }
|
||||||
col = window_width-1;
|
|
||||||
|
|
||||||
SysLog("H or f AFTER row:%d, col:%d, cnt:%d\n", row, col, ansi_param_count);
|
SysLog("H or f AFTER row:%d, col:%d, cnt:%d\n", row, col, ansi_param_count);
|
||||||
// "$$CM,%d,%d$$", row, col;
|
|
||||||
"$$CM,LE=%d,RE=%d$$", row, col;
|
if (row > window_height)
|
||||||
|
row = window_height-2;
|
||||||
|
if (col > window_width)
|
||||||
|
col = window_width;
|
||||||
|
|
||||||
|
"$$CM,%d,%d$$", row, col;
|
||||||
|
// "$$CM,LE=%d,RE=%d$$", row, col;
|
||||||
ptr++;
|
ptr++;
|
||||||
break;
|
break;
|
||||||
case 'J':
|
case 'J':
|
||||||
|
@ -518,11 +571,11 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
|
||||||
ptr++;
|
ptr++;
|
||||||
}
|
}
|
||||||
// Reset ansi_param_count and ansi_code
|
// Reset ansi_param_count and ansi_code
|
||||||
ansi_param_count = 0;
|
// ansi_param_count = 0;
|
||||||
I64 wtv;
|
// I64 wtv;
|
||||||
for (wtv = 0; wtv < MAX_ANSI_PARAMS; wtv++) {
|
// for (wtv = 0; wtv < MAX_ANSI_PARAMS; wtv++) {
|
||||||
ansi_code[wtv] = 0;
|
// ansi_code[wtv] = 0;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue