This commit is contained in:
y4my4my4m 2023-05-14 19:17:22 +09:00
parent 5862425d45
commit e231f7d724
3 changed files with 48 additions and 30 deletions

View file

@ -52,11 +52,9 @@ U0 HandleControlCodes(U8 ch) {
Beep; Beep;
break; break;
case 8: // BS (Backspace) case 8: // BS (Backspace)
// "%c%c%c", 8, ' ', 8; // Move cursor back, erase character, move cursor back again
DocPrint(term.doc, "$$CM,-1,0$$"); DocPrint(term.doc, "$$CM,-1,0$$");
break; break;
case 9: // HT (Horizontal Tab) case 9: // HT (Horizontal Tab)
// " "; // 8 spaces
DocPrint(term.doc, "$$CM,8,0$$"); DocPrint(term.doc, "$$CM,8,0$$");
break; break;
case 10: // LF (Line Feed) case 10: // LF (Line Feed)
@ -160,24 +158,25 @@ U0 ANSIParse()
ansi_code[counter] = 0; // Initialize all elements to 0 ansi_code[counter] = 0; // Initialize all elements to 0
} }
I64 ansi_param_count = 0; I64 ansi_param_count = 0;
while (IsDigit(*ptr) || *ptr == ';') { while (*ptr != '\0') {
if (IsDigit(*ptr)) { if (IsDigit(*ptr)) {
ansi_code[ansi_param_count] = ansi_code[ansi_param_count] * 10 + (*ptr - '0'); ansi_code[ansi_param_count] = ansi_code[ansi_param_count] * 10 + (*ptr - '0');
ptr++; ptr++;
} }
else if (*ptr == ';') { else if (*ptr == ';') {
ansi_param_count++; ansi_param_count++;
if (ansi_param_count >= MAX_ANSI_PARAMS) {
// Error handling: too many parameters
break;
}
ptr++; ptr++;
if(!IsDigit(*ptr) || *ptr == ';'){ if (!IsDigit(*ptr) && *ptr != ';') {
break; break;
} }
} }
else {
// If the next character is not a digit or semicolon, break out
break;
}
} }
// Handle specific ANSI escape sequences // Handle specific ANSI escape sequences
switch (*ptr) { switch (*ptr) {
case 'n': case 'n':
@ -439,13 +438,6 @@ U0 ANSIParse()
// 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]);
DocPrint(term.doc, "$$CM,%d,0$$", ansi_code[0]); DocPrint(term.doc, "$$CM,%d,0$$", ansi_code[0]);
// NOTE: this has been "fixed" since we now change the window's background color
// if we just move the cursor,
// you dont get the colored background since we skip over it directly
// I64 C;
// for (C = 0; C < ansi_code[0]; C++) {
// " ";
// }
ptr++; ptr++;
break; break;
case 'D': case 'D':
@ -457,7 +449,6 @@ U0 ANSIParse()
case 'E': case 'E':
// Cursor Next Line // Cursor Next Line
SysLog("Cursor Next Line\n"); SysLog("Cursor Next Line\n");
// "$$CM+TY,0,+%d$$", ansi_code[0];
DocPrint(term.doc, "\n"); DocPrint(term.doc, "\n");
ptr++; ptr++;
break; break;
@ -465,14 +456,12 @@ U0 ANSIParse()
// Cursor Previous Line // Cursor Previous Line
SysLog("Cursor Previous Line\n"); SysLog("Cursor Previous Line\n");
DocPrint(term.doc, "$$CM+LY,0,-%d$$", ansi_code[0]); DocPrint(term.doc, "$$CM+LY,0,-%d$$", ansi_code[0]);
// "\n";
ptr++; ptr++;
break; break;
case 'G': case 'G':
// Cursor Horizontal Absolute // Cursor Horizontal Absolute
SysLog("Cursor Horizontal Absolute\n"); SysLog("Cursor Horizontal Absolute\n");
DocPrint(term.doc, "$$CM,%d,0$$", ansi_code[0]); DocPrint(term.doc, "$$CM,%d,0$$", ansi_code[0]);
// "\n";
ptr++; ptr++;
break; break;
case 'H': case 'H':
@ -483,22 +472,48 @@ U0 ANSIParse()
row = ansi_code[0]; row = ansi_code[0];
if(ansi_code[1] != 1) if(ansi_code[1] != 1)
col = ansi_code[1]; col = ansi_code[1];
// TODO: This is a hack, dont skip row 0, col 0 (maybe?) // TODO: This is a hack, dont skip row 0, col 0 (maybe?)
if (row == 0 && col == 0) { // if (row == 0 && col == 0) {
ptr++; // ptr++;
// break;
// }
if (row == 0) row = 1;
if (col == 0) col = 1;
// If we're already at the right position, no need to move
if (row == term.current_row && col == term.current_col) {
ptr++;
break; break;
} }
// row--; // row--;
// col--; // col--;
SysLog("H or f row:%d, col:%d, cnt:%d\n", row, col, ansi_param_count); SysLog("H or f row:%d, col:%d, cnt:%d\n", row, col, ansi_param_count);
// if (row > term.window_height)
// row = term.window_height-1; // Adjust the position based on the window size
// else if (col > term.window_width) if (row > term.window_height) {
// col = term.window_width-1; row = term.window_height;
// "$$CM,0,0$$"; }
DocPrint(term.doc, "$$CM+LX+TY,LE=%d,RE=%d$$", col-1, row-1); if (col > term.window_width) {
col = term.window_width;
}
// If row or col are at their max value, reset the current position to 1
// if (row == term.window_height || col == term.window_width) {
// if (row == term.window_height) term.current_row = 1;
// if (col == term.window_width) term.current_col = 1;
// ptr++;
// break;
// }
term.current_row = row;
term.current_col = col;
DocPrint(term.doc, "$$CM+LX+TY,LE=%d,RE=%d$$", term.current_col-1, term.current_row-1);
term.current_row = 1;
term.current_col = 1;
ptr++; ptr++;
break; break;
case 'J': case 'J':
@ -681,6 +696,7 @@ U0 Telnet(U8 *host=NULL, U16 port=TELNET_PORT) {
I64 art_path = "Art/TelnetSplash.ans"; I64 art_path = "Art/TelnetSplash.ans";
I64 message_code, arg1, arg2; I64 message_code, arg1, arg2;
GrPaletteGet(original_palette); GrPaletteGet(original_palette);
AutoComplete(OFF);
SettingsPush; SettingsPush;
MenuPush( MenuPush(

View file

@ -9,8 +9,8 @@ class Terminal {
I64 current_color; I64 current_color;
I64 current_bgcolor; I64 current_bgcolor;
I64 cursor_x; I64 current_row;
I64 cursor_y; I64 current_col;
U8 buffer[BUF_SIZE]; U8 buffer[BUF_SIZE];
I64 buffer_len; I64 buffer_len;

View file

@ -5,7 +5,9 @@ Cd(__DIR__);
U8 IsDigit(U8 ch) { U8 IsDigit(U8 ch) {
return '0' <= ch <= '9'; return '0' <= ch <= '9';
} }
U8 IsAlpha(U8 ch) {
return ('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z');
}
class CHostForm { class CHostForm {
U8 host[256] format "\n\n \t$$DA-P,LEN=255,A=\"Host:%s\"$$\t\n"; U8 host[256] format "\n\n \t$$DA-P,LEN=255,A=\"Host:%s\"$$\t\n";
U16 port format "\t$$DA,LEN=255,A=\"Port:%d\"$$\t\n \n\n"; U16 port format "\t$$DA,LEN=255,A=\"Port:%d\"$$\t\n \n\n";