No_Input_test

This commit is contained in:
y4my4my4m 2023-05-02 22:48:54 +09:00
parent ba6f4529dc
commit 62adc69534

View file

@ -35,7 +35,7 @@ I64 TelnetOpen(U8 *host, U16 port) {
return sock; return sock;
} }
//sock(CTCPSocket *)->timeout = TCP_TIMEOUT; sock(CTCPSocket *)->timeout = TCP_TIMEOUT;
return sock; return sock;
} }
@ -91,60 +91,35 @@ U0 SendTerminalType(I64 sock, U8 *terminal_type) {
U0 HandleControlCodes(U8 ch) { U0 HandleControlCodes(U8 ch) {
if (ch < 32 && ch != 20) { // ASCII code below 32 (control character) if (ch < 32 && ch != 20) { // ASCII code below 32 (control character)
switch (ch) { switch (ch) {
case 0: // NUL (Null) case 0: // NUL (Null) - Typically ignored
// Typically ignored
break; break;
case 7: // BEL (Bell) case 7: // BEL (Bell)
// Make a beep sound or flash the screen
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 "%c%c%c", 8, ' ', 8; // Move cursor back, erase character, move cursor back again
break; break;
case 9: // HT (Horizontal Tab) case 9: // HT (Horizontal Tab)
// Move the cursor to the next tab stop (typically 8 spaces) " "; // 8 spaces
break; break;
case 10: // LF (Line Feed) case 10: // LF (Line Feed)
// "%c", ch; "\n";
break; break;
case 11: // VT (Vertical Tab) case 11: // VT (Vertical Tab)
// Move the cursor down one line
break; break;
case 12: // FF (Form Feed) case 12: // FF (Form Feed)
DocClear; DocClear;
break; break;
case 13: // CR (Carriage Return) case 13: // CR (Carriage Return)
"\r\n\0"; "\r";
break;
case 14: // SO (Shift Out)
// Switch to an alternate character set
break;
case 15: // SI (Shift In)
// Switch back to the default character set
break; break;
case 14: // SO (Shift Out) - Switch to an alternate character set
case 15: // SI (Shift In) - Switch back to the default character set
default: default:
break; break;
} }
} }
else { else {
// switch (ch) {
// // if (ch > 126) break;
// // not sure if there's any point looking for these codes here?
// case 0x0A: // Line Feed
// case 0x0C: // Form Feed
// break;
// case 0x0D: // Carriage Return
// "\r\0";
// break;
// case 0x1B: // Escape
// break;
// case 0x24: // FIXME: Need to escape the dollar sign
// ch = "//$$$$";
// break;
// default:
// // SysLog("Code: 0x%02X\n", ch);
// break;
// }
if (ch == 0x24) { if (ch == 0x24) {
ch = "//$$$$"; ch = "//$$$$";
} }
@ -156,14 +131,15 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
I64 sock, bytes_received, input_len, sc = 0; I64 sock, bytes_received, input_len, sc = 0;
U8 buffer[BUF_SIZE], input_buffer[BUF_SIZE], *ptr, ch; U8 buffer[BUF_SIZE], input_buffer[BUF_SIZE], *ptr, ch;
Bool force_disconnect = FALSE; Bool force_disconnect = FALSE;
Bool request_input = FALSE;
I64 window_width = 80; I64 window_width = 80;
I64 window_height = 25; // 25 should be default I64 window_height = 25;
I64 window_left = (GR_WIDTH - window_width) / 2; I64 window_left = (GR_WIDTH - window_width) / 2;
I64 window_top = (Fs->win_bottom - Fs->win_top - window_height) / 2; I64 window_top = (Fs->win_bottom - Fs->win_top - window_height) / 2;
WinHorz(Fs->win_left, Fs->win_left+80, Fs); WinHorz(Fs->win_left, Fs->win_left+window_width, Fs);
WinVert(Fs->win_top + window_top, Fs->win_top + window_top + window_height, Fs); WinVert(Fs->win_top + window_top, Fs->win_top + window_top + window_height, Fs);
WinToTop(Fs); WinToTop(Fs);
WinFocus(Fs); WinFocus(Fs);
@ -213,7 +189,7 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
response[2] = option_code; response[2] = option_code;
response[3] = '\0'; response[3] = '\0';
TCPSocketSendString(sock, response); TCPSocketSendString(sock, response);
SendTerminalType(sock, "ANSI"); SendTerminalType(sock, "ANSI-BBS");
SendWindowSize(sock, 25, 80); SendWindowSize(sock, 25, 80);
} else { } else {
response[1] = WONT; response[1] = WONT;
@ -243,93 +219,35 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
ptr++; ptr++;
} }
// Process ansi_code // Process ansi_code
if (*ptr == ';') { if (*ptr == ' ') {
ptr++; ptr++;
} else if (*ptr == 'A') {
// TODO: Cursor Up
// arg = isNaN(args[0]) ? 1 : args[0];
// self.moveCursor(0, -arg);
ptr++;
break;
} else if (*ptr == 'B') {
// TODO: Cursor Down
// arg = isNaN(args[0]) ? 1 : args[0];
// self.moveCursor(0, arg);
ptr++;
break;
} else if (*ptr == 'C') {
// Cursor Right
I64 i;
for (i = 0; i < ansi_code; i++) {
Print(" ");
} }
// arg = isNaN(args[0]) ? 1 : args[0]; else if (*ptr == ';') {
// self.moveCursor(arg, 0);
ptr++; ptr++;
break; }
} else if (*ptr == 'D') { else {
// TODO: Cursor Left // this helps for ANSI detection
// arg = isNaN(args[0]) ? 1 : args[0]; if (*ptr == 'n') {
// self.moveCursor(-arg, 0); if (ansi_code == 6) {
ptr++; // Respond with cursor position
break; // U8 response[32] = "\x1B[%d;%dR", window_width, window_height;
} else if (*ptr == 'E') { TCPSocketSendString(sock, "\x1B[25;80R");
Print("\n"); } else if (ansi_code == 5) {
ptr++; // Respond with terminal readiness
break; TCPSocketSendString(sock, "\x1B[0n");
} else if (*ptr == 'H' || *ptr == 'f') {
// TODO: Cursor Position
// self.row = isNaN(args[0]) ? 1 : args[0];
// self.column = isNaN(args[1]) ? 1 : args[1];
// self.positionUpdated();
SysLog("H detected");
ptr++;
break;
} else if (*ptr == 'J') {
// TODO: Erase in Display
DocClear;
ptr++;
break;
} else if (*ptr == 'K') {
// TODO: Erase in Line
ptr++;
break;
} else if (*ptr == 'S') {
// TODO: Scroll Up
ptr++;
break;
} else if (*ptr == 'T') {
// TODO: Scroll Down
ptr++;
break;
} else if (*ptr == '?') {
switch (ansi_code) {
case 25:
if (*ptr == 'l') // Hide cursor
break;
if (*ptr == 'h') // Show cursor
break;
SysLog("code 25");
break;
case 1049:
if (*ptr == 'h') // Save screen and switch to alternate screen buffer
break;
if (*ptr == 'l') // Restore screen and switch back to main screen buffer
break;
SysLog("code 1049");
break;
} }
ptr++; ptr++;
break; } else if (*ptr == 'c') {
} else if (*ptr == 's') { // Respond with device attributes
// self.saveCursorPosition(); TCPSocketSendString(sock, "\x1B[?1;0c");
ptr++; ptr++;
break;
} else if (*ptr == 'r') {
// self.restoreCursorPosition();
ptr++;
break;
} else if (*ptr == 'm') { } else if (*ptr == 'm') {
I64 color_code;
if (ansi_code >= 30 && ansi_code <= 37) {
color_code = ansi_code - 30; // Set foreground color
} else if (ansi_code >= 40 && ansi_code <= 47) {
color_code = ansi_code - 40; // Set background color
} else {
switch (ansi_code) { switch (ansi_code) {
case 0: "$$BG$$$$FG$$"; break; // reset case 0: "$$BG$$$$FG$$"; break; // reset
// case 1: ""; break; // TODO: bold // case 1: ""; break; // TODO: bold
@ -343,11 +261,6 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
// case 9: ""; break; // TODO: strikethrough // case 9: ""; break; // TODO: strikethrough
// case 10: ""; break; // TODO: primary font // case 10: ""; break; // TODO: primary font
} }
I64 color_code;
if (ansi_code >= 30 && ansi_code <= 37) {
color_code = ansi_code - 30; // Set foreground color
} else if (ansi_code >= 40 && ansi_code <= 47) {
color_code = ansi_code - 40; // Set background color
} }
switch (color_code) { switch (color_code) {
case 0: "$$BLACK$$"; break; case 0: "$$BLACK$$"; break;
@ -362,13 +275,90 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
} }
ptr++; ptr++;
break; break;
} else if (*ptr == 'A') {
// TODO: Cursor Up
// arg = isNaN(args[0]) ? 1 : args[0];
// self.moveCursor(0, -arg);
ptr++;
} else if (*ptr == 'B') {
// TODO: Cursor Down
// arg = isNaN(args[0]) ? 1 : args[0];
// self.moveCursor(0, arg);
ptr++;
} else if (*ptr == 'C') {
// Cursor Right
I64 i;
for (i = 0; i < ansi_code; i++) {
Print(" ");
}
// arg = isNaN(args[0]) ? 1 : args[0];
// self.moveCursor(arg, 0);
ptr++;
} else if (*ptr == 'D') {
// TODO: Cursor Left
// arg = isNaN(args[0]) ? 1 : args[0];
// self.moveCursor(-arg, 0);
ptr++;
} else if (*ptr == 'E') {
Print("\n");
ptr++;
} else if (*ptr == 'H' || *ptr == 'f') {
// TODO: Cursor Position
// self.row = isNaN(args[0]) ? 1 : args[0];
// self.column = isNaN(args[1]) ? 1 : args[1];
// self.positionUpdated();
ptr++;
} else if (*ptr == 'J') {
// TODO: Erase in Display
DocClear;
ptr++;
} else if (*ptr == 'K') {
// TODO: Erase in Line
ptr++;
} else if (*ptr == 'S') {
// TODO: Scroll Up
ptr++;
} else if (*ptr == 'T') {
// TODO: Scroll Down
ptr++;
} else if (*ptr == '?') {
switch (ansi_code) {
case 2:
SysLog("code 2");
break;
case 25:
if (*ptr == 'l') // Hide cursor
SysLog("code 25l");
break;
if (*ptr == 'h') // Show cursor
SysLog("code 25h");
break;
break;
case 1049:
if (*ptr == 'l') // Save screen and switch to alternate screen buffer
SysLog("code 1049l");
break;
if (*ptr == 'h') // Restore screen and switch back to main screen buffer
SysLog("code 1049h");
break;
break;
default:
break;
}
ptr++;
} else if (*ptr == 's') {
// self.saveCursorPosition();
ptr++;
} else if (*ptr == 'r') {
// self.restoreCursorPosition();
ptr++;
} else if (*ptr == 'h' || *ptr == 'l') { } else if (*ptr == 'h' || *ptr == 'l') {
// TODO: Handle 'h' (set mode) or 'l' (reset mode) codes // TODO: Handle 'h' (set mode) or 'l' (reset mode) codes
ptr++; // Skip 'h' or 'l' ptr++; // Skip 'h' or 'l'
break;
} else { } else {
ptr++; ptr++;
break; // Invalid character, exit loop }
break;
} }
} }
} }
@ -381,6 +371,7 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
} }
// Sleep(500); // Sleep(500);
if (request_input) {
// Prompt user for input and send it to the remote host // Prompt user for input and send it to the remote host
"\n$$RED$$$BK,1$Input$BK,0$$$BLACK$$: "; "\n$$RED$$$BK,1$Input$BK,0$$$BLACK$$: ";
@ -398,17 +389,20 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
input_buffer[input_len++] = ch; input_buffer[input_len++] = ch;
"%c", ch; "%c", ch;
} }
input_buffer[input_len] = '\0'; // input_buffer[input_len] = '\0';
if (!force_disconnect) { if (!force_disconnect) {
input_buffer[input_len++] = '\r'; // input_buffer[input_len++] = '\r';
input_buffer[input_len++] = '\n'; // input_buffer[input_len++] = '\n';
TCPSocketSend(sock, input_buffer, input_len); TCPSocketSend(sock, input_buffer, input_len);
// TCPSocketSend(sock, "\x0D\x0A", 2); // CR followed by LF
} else { } else {
"Force disconnecting...\n"; "Force disconnecting...\n";
goto disconnect; goto disconnect;
break; break;
} }
request_input = FALSE;
}
} else { } else {
// SysLog("Error: %0x%02X\n", ch); // SysLog("Error: %0x%02X\n", ch);
"Error: Connection closed by the remote host.\n"; "Error: Connection closed by the remote host.\n";