Colors fixed?

This commit is contained in:
y4my4my4m 2023-05-11 21:20:32 +09:00
parent 4d883bbe50
commit 4df07b6447
3 changed files with 34 additions and 35 deletions

View file

@ -1,5 +1,6 @@
// Telnet client for ZealOS by y4my4m // Telnet client for ZealOS by y4my4m
// Public Domain // Public Domain
Cd(__DIR__);;
#define TELNET_PORT 23 #define TELNET_PORT 23
#define BUF_SIZE 8192 // way too big? #define BUF_SIZE 8192 // way too big?
@ -13,13 +14,12 @@
#define MAX_ANSI_PARAMS 32 #define MAX_ANSI_PARAMS 32
#include "TelnetNegotiation"
#include "TelnetHelpers"
CTask *input_task = NULL; CTask *input_task = NULL;
Bool force_disconnect = FALSE; Bool force_disconnect = FALSE;
U8 IsDigit(U8 ch) {
return '0' <= ch <= '9';
}
U0 HandleControlCodes(U8 ch) { U0 HandleControlCodes(U8 ch) {
if (ch < 32) { // ASCII code below 32 (control character) if (ch < 32) { // ASCII code below 32 (control character)
switch (ch) { switch (ch) {
@ -86,15 +86,15 @@ I64 TelnetOpen(U8 *host, U16 port) {
return sock; return sock;
} }
// sock(CTCPSocket *)->timeout = 0;
// sock(CTCPSocket *)->timeout = TCP_TIMEOUT; // sock(CTCPSocket *)->timeout = TCP_TIMEOUT;
return sock; return sock;
} }
U0 InputTask(U0 *args) { U0 InputTask(U0 *args) {
I64 sock = *args; I64 sock = *args;
DocTermNew;
DocTermNew; DocPrint(, "$$WW,1$$");
DocPrint(, "$$WW,1$$");
// DocCursor; // DocCursor;
// WinBorder(OFF); // WinBorder(OFF);
@ -214,7 +214,8 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
DocClear; DocClear;
// probably should use word wrap? // probably should use word wrap?
DocPrint(, "$$WW,1$$"); // DocPrint(, "$$WW,1$$");
DocCursor(OFF);
sock = TelnetOpen(host, port); sock = TelnetOpen(host, port);
if (sock <= 0) { if (sock <= 0) {
@ -245,6 +246,7 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
// Telnet negotiation sequence // Telnet negotiation sequence
if (*ptr == NEGOTIATE) { if (*ptr == NEGOTIATE) {
// include TelnetNegotiation.ZC here i guess // include TelnetNegotiation.ZC here i guess
TelnetNegotiate(sock, ptr);
ptr += 3; ptr += 3;
} }
else if (*ptr == ANSI_ESC) { else if (*ptr == ANSI_ESC) {
@ -334,35 +336,28 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
Bool isBright = FALSE; 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]) {
{ // case 0: "$$BG$$$$FG$$"; break; // reset
switch (ansi_code[m]) { case 0: "$$BG,BLACK$$$$WHITE$$"; break; // reset
// case 0: "$$BG$$$$FG$$"; break; // reset // case 1: ""; break; // TODO: bold
case 0: "$$BG,BLACK$$$$WHITE$$"; break; // reset case 1: isBright = TRUE; break;
// 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 // case 4: "$$UL,1$$" + string + "$$UL,0$$"; break; // TODO: underline
// case 4: "$$UL,1$$" + string + "$$UL,0$$"; break; // TODO: underline // case 5: "$$"; break; // TODO: blink
// case 5: "$$"; break; // TODO: blink // case 6: ""; break; // TODO: fast blink
// case 6: ""; break; // TODO: fast blink // case 7: "$$IV,1$$" + string + "$$IV,0$$"; break; // TODO: invert
// case 7: "$$IV,1$$" + string + "$$IV,0$$"; break; // TODO: invert // case 8: ""; break; // TODO: hide (rare)
// case 8: ""; break; // TODO: hide (rare) // case 9: ""; break; // TODO: strikethrough
// case 9: ""; break; // TODO: strikethrough // 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] <= 39) || (ansi_code[m] >= 90 && ansi_code[m] <= 97)) {
// 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){ if(!isBright){
switch (ansi_code[m]) { switch (ansi_code[m]) {
case 30: "$$DKGRAY$$"; break; case 30: "$$BLACK$$"; break;
case 31: "$$RED$$"; break; case 31: "$$RED$$"; break;
case 32: "$$GREEN$$"; break; case 32: "$$GREEN$$"; break;
case 33: "$$YELLOW$$"; break; case 33: "$$YELLOW$$"; break;
@ -400,7 +395,7 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
} }
// 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 buggy // 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] <= 49) || (ansi_code[m] >= 100 && ansi_code[m] <= 107)) {
// 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){ if(!isBright){
@ -565,7 +560,7 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
ptr++; ptr++;
break; break;
case 'M': case 'M':
// SysLog("Case M\n"); SysLog("Case M\n");
// TODO: is this correct? cursor should go one line up // TODO: is this correct? cursor should go one line up
"$$CM,0,-1$$"; "$$CM,0,-1$$";
ptr++; ptr++;

View file

@ -1,3 +1,7 @@
U8 IsDigit(U8 ch) {
return '0' <= ch <= '9';
}
class CHostForm { class CHostForm {
U8 host[256] format "$$DA-P,LEN=255,A=\"Host:%s\"$$"; U8 host[256] format "$$DA-P,LEN=255,A=\"Host:%s\"$$";
U16 port format "A=\"Port:%d\""; U16 port format "A=\"Port:%d\"";
@ -9,6 +13,6 @@ U0 TelnetPrompt() {
form.host[0] = 0; form.host[0] = 0;
form.port = TELNET_PORT; form.port = TELNET_PORT;
if (PopUpForm(&form)) { if (PopUpForm(&form)) {
Telnet(form.host, form.port); // Telnet(form.host, form.port);
} }
} }

View file

@ -47,7 +47,7 @@ U0 SendTerminalType(I64 sock, U8 *terminal_type) {
TCPSocketSendString(sock, response); TCPSocketSendString(sock, response);
} }
U0 TelnetNegotiate() U0 TelnetNegotiate(I64 sock, U8 *ptr)
{ {
U8 negotiation_code = *(ptr + 1); U8 negotiation_code = *(ptr + 1);
U8 option_code = *(ptr + 2); U8 option_code = *(ptr + 2);