ctrl to alt keys

This commit is contained in:
y4my4my4m 2023-05-26 01:42:18 +09:00
parent dd34198592
commit 13fb4e8bbd
2 changed files with 181 additions and 180 deletions

View file

@ -70,8 +70,8 @@ U0 HandleControlCodes(U8 ch) {
// DocPrint(term.doc, "\f"); // DocPrint(term.doc, "\f");
break; break;
case 13: // CR (Carriage Return) case 13: // CR (Carriage Return)
DocPrint(term.doc, "\r"); // DocPrint(term.doc, "\r");
// DocPrint(term.doc, "$$CM+LX+PRY,LE=0,RE=1$$"); DocPrint(term.doc, "$$CM+LX+PRY,LE=0,RE=1$$");
break; break;
case 14: // SO (Shift Out) - Switch to an alternate character set case 14: // SO (Shift Out) - Switch to an alternate character set
case 15: // SI (Shift In) - Switch back to the default character set case 15: // SI (Shift In) - Switch back to the default character set
@ -99,7 +99,7 @@ U0 HandleControlCodes(U8 ch) {
SysLog("Fs\n"); SysLog("Fs\n");
break; break;
case 29: case 29:
SysLog("Gs\n"); SysLog("Gs\n");
break; break;
case 30: case 30:
SysLog("Rs\n"); SysLog("Rs\n");
@ -486,7 +486,7 @@ U0 ANSIParse()
// break; // break;
// } // }
// 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);
// Adjust the position based on the window size // Adjust the position based on the window size
@ -523,7 +523,6 @@ U0 ANSIParse()
term.current_col = col; term.current_col = col;
DocPrint(term.doc, "$$CM+LX+TY,LE=%d,RE=%d$$", term.current_col-1, term.current_row-1); DocPrint(term.doc, "$$CM+LX+TY,LE=%d,RE=%d$$", term.current_col-1, term.current_row-1);
//DocCursorPosSet(term.doc, col, row);
ptr++; ptr++;
break; break;
case 'J': case 'J':
@ -531,9 +530,11 @@ U0 ANSIParse()
// Erase in Display // Erase in Display
if (ansi_code[0] == 0) { if (ansi_code[0] == 0) {
// Erase from cursor to end of display // Erase from cursor to end of display
// TODO: dont think this is working
// DocDelToNum(Fs->display_doc, Fs->display_doc->cur_entry->line_num); // DocDelToNum(Fs->display_doc, Fs->display_doc->cur_entry->line_num);
} else if (ansi_code[0] == 1) { } else if (ansi_code[0] == 1) {
// Erase from cursor to beginning of display // Erase from cursor to beginning of display
// TODO: dont think this is working
// DocDelToEntry(Fs->display_doc, Fs->display_doc->cur_entry, FALSE); // DocDelToEntry(Fs->display_doc, Fs->display_doc->cur_entry, FALSE);
} else if (ansi_code[0] == 2) { } else if (ansi_code[0] == 2) {
// Erase entire display // Erase entire display
@ -547,17 +548,21 @@ U0 ANSIParse()
break; break;
case 'K': case 'K':
// TODO: I have no idea if this actually works // TODO: I have no idea if this actually works
SysLog("K code, %d %d\n", ansi_param_count, ansi_code[0]);
// if (ansi_param_count == 0 || ansi_code[0] == 0) { if (ansi_param_count == 0 || ansi_code[0] == 0) {
// // Erase from cursor to end of line // Erase from cursor to end of line
// LineDeleteToEnd(term.doc->cur_entry, doc.term->cur_col); // LineDeleteToEnd(term.doc->cur_entry, doc.term->cur_col);
// } else if (ansi_code[0] == 1) { // DocDelToEntry(term.doc, term.doc->cur_entry, TRUE);
// // Erase from cursor to beginning of line
// DocDelToNum(term.doc, 80);
// DocRecalc(term.doc);
} else if (ansi_code[0] == 1) {
// Erase from cursor to beginning of line
// LineDeleteToStart(term.doc->cur_entry, doc.term->cur_col); // LineDeleteToStart(term.doc->cur_entry, doc.term->cur_col);
// } else if (ansi_code[0] == 2) { } else if (ansi_code[0] == 2) {
// // Erase entire line // Erase entire line
// LineDeleteEntire(term.doc->cur_entry); // LineDeleteEntire(term.doc->cur_entry);
// } }
ptr++; ptr++;
break; break;
case 'L': case 'L':
@ -567,12 +572,12 @@ U0 ANSIParse()
break; break;
case 'S': case 'S':
// TODO: Scroll Up // TODO: Scroll Up
SysLog("Scroll Up"); SysLog("S Scroll Up");
ptr++; ptr++;
break; break;
case 'T': case 'T':
// TODO: Scroll Down // TODO: Scroll Down
SysLog("Scroll Down"); SysLog("T Scroll Down");
ptr++; ptr++;
break; break;
case 'M': case 'M':
@ -705,7 +710,6 @@ U0 Telnet(U8 *host=NULL, U16 port=TELNET_PORT) {
term.window_width = 80; term.window_width = 80;
term.window_height = 25; term.window_height = 25;
term.doc = Fs->display_doc; term.doc = Fs->display_doc;
// IsEditableText(term.doc->cur_entry);
term.waiting_for_input = TRUE; term.waiting_for_input = TRUE;
term.sock_ready = 0; term.sock_ready = 0;
I64 art_path = "::/Home/Net/Programs/Telnet/Art/TelnetSplash.ans"; I64 art_path = "::/Home/Net/Programs/Telnet/Art/TelnetSplash.ans";
@ -713,21 +717,24 @@ U0 Telnet(U8 *host=NULL, U16 port=TELNET_PORT) {
GrPaletteGet(original_palette); GrPaletteGet(original_palette);
AutoComplete(OFF); AutoComplete(OFF);
DocMax;
DocCursor(OFF);
SettingsPush; SettingsPush;
MenuPush( MenuPush(
"Telnet {" "Telnet {"
" Connect(,CH_CTRLN);" " Connect(,SCF_ALT+'n');"
" Exit(,CH_SHIFT_ESC);" " Exit(,CH_SHIFT_ESC);"
"}" "}"
"Load {" "Load {"
" ANSIArt(,CH_CTRLO);" " ANSIArt(,SCF_ALT);"
"}" "}"
"Config {" "Config {"
" ToggleDarkMode(,CH_CTRLD);" " ToggleDarkMode(,SCF_ALT);"
" SetDarkColors(,CH_CTRLT);" " SetDarkColors(,SCF_ALT);"
"}" "}"
"About {" "About {"
" Info(,CH_CTRLL);" " Info(,SCF_ALT);"
"}" "}"
); );
@ -750,15 +757,15 @@ U0 Telnet(U8 *host=NULL, U16 port=TELNET_PORT) {
(Fs->win_height - 1), (Fs->win_height - 1),
Fs); Fs);
// this flag will make the term auto-size to the content (ish)
// term.doc->flags |= DOCEG_DONT_EDIT;
show_splash: show_splash:
// SplashScreen // SplashScreen
Fs->border_attr = WHITE << 4 + LTRED; Fs->border_attr = WHITE << 4 + LTRED;
DocMax;
DocClear; DocClear;
// probably should use word wrap? // probably should use word wrap? dunno if it actually changes anything in this context...
DocPrint(, "$$WW,1$$"); DocPrint(, "$$WW,1$$");
DocCursor(OFF);
// Load the file into the buffer and get its size // Load the file into the buffer and get its size
term.buffer_len = ANSIArtLoad(art_path, term.buffer); term.buffer_len = ANSIArtLoad(art_path, term.buffer);
if (term.buffer_len > 0) { if (term.buffer_len > 0) {
@ -804,43 +811,69 @@ init_connection:
{ {
while (!force_disconnect) { while (!force_disconnect) {
U8 key = KeyGet(&sc); U8 key = KeyGet(&sc);
// fix the bug of holding Ctrl triggers all the CH_CTRL, needs to be handled like in Demo/Graphics/FontEd.ZC:104
// ALT
if (sc & SCF_ALT && !(sc & SCF_CTRL))
{
switch (key)
{
// case 0:
// switch (sc.u8[0])
// {
// }
case 'n':
TelnetPrompt(&form);
host = form.host;
port = form.port;
DocClear;
term.waiting_for_input = FALSE;
goto init_connection;
break;
case 'o':
art_path = ANSIArtBrowser;
if (art_path != NULL) {
term.sock_ready = 0;
term.waiting_for_input = TRUE;
// SysLog("%s\n", art_path);
goto show_splash;
}
else {
"Error: Could not load art.\n";
}
break;
case 's':
// Save as DD image.
StrCopy(term.doc->filename.name, "::/Home/Wallpapers/1024/Default.DD");
DocWrite(term.doc, TRUE);
break;
case 'd':
dark_mode = !dark_mode;
if (dark_mode) Fs->text_attr = WHITE << 4 + BLACK;
else Fs->text_attr = BLACK << 4 + WHITE;
break;
case 't':
original_colors = !original_colors;
if (original_colors) PaletteSetStd(FALSE);
else {
GrPaletteSet(original_palette);
LFBFlush;
}
break;
case 'l':
PopUpOk("\n\n Not all BBS will work perfectly (yet). \n\n You can load ANSi artwork with Ctrl+O","\n\n\n\t\tMade by y4my4m\n\n");
break;
}
}
else { // fix the bug of holding Ctrl triggers all the CH_CTRL, needs to be handled like in Demo/Graphics/FontEd.ZC:104
switch (key) switch (key)
{ {
case 0: case 0:
switch (sc.u8[0]) switch (sc.u8[0])
{ {
case SC_CURSOR_LEFT: case SC_CURSOR_LEFT: if (term.sock_ready) TCPSocketSendString(term.sock, "\x1B[D"); break;
if (term.sock_ready) TCPSocketSendString(term.sock, "\x1B[D"); case SC_CURSOR_RIGHT: if (term.sock_ready) TCPSocketSendString(term.sock, "\x1B[C"); break;
break; case SC_CURSOR_UP: if (term.sock_ready) TCPSocketSendString(term.sock, "\x1B[A"); break;
case SC_CURSOR_DOWN: if (term.sock_ready) TCPSocketSendString(term.sock, "\x1B[B"); break;
case SC_CURSOR_RIGHT:
if (term.sock_ready) TCPSocketSendString(term.sock, "\x1B[C");
break;
case SC_CURSOR_UP:
if (term.sock_ready) TCPSocketSendString(term.sock, "\x1B[A");
break;
case SC_CURSOR_DOWN:
if (term.sock_ready) TCPSocketSendString(term.sock, "\x1B[B");
break;
default:
break;
}
break;
case 9:
switch (sc.u8[0])
{
case SC_TAB:
if (term.sock_ready) TCPSocketSendString(term.sock, "\x09");
break;
default:
break;
}
case 255:
switch (sc.u8[0])
{
case SC_PAGE_UP: if (term.sock_ready) TCPSocketSendString(term.sock, "\033[V"); break; case SC_PAGE_UP: if (term.sock_ready) TCPSocketSendString(term.sock, "\033[V"); break;
case SC_PAGE_DOWN:if (term.sock_ready) TCPSocketSendString(term.sock, "\033[U"); break; case SC_PAGE_DOWN:if (term.sock_ready) TCPSocketSendString(term.sock, "\033[U"); break;
case SC_HOME: if (term.sock_ready) TCPSocketSendString(term.sock, "\033[H"); break; case SC_HOME: if (term.sock_ready) TCPSocketSendString(term.sock, "\033[H"); break;
@ -861,7 +894,16 @@ init_connection:
default: default:
break; break;
} }
break;
case 9:
switch (sc.u8[0])
{
case SC_TAB:
if (term.sock_ready) TCPSocketSendString(term.sock, "\x09");
break;
default:
break;
}
case CH_BACKSPACE: case CH_BACKSPACE:
if (term.sock_ready) TCPSocketSendString(term.sock, "\x08\x7F"); if (term.sock_ready) TCPSocketSendString(term.sock, "\x08\x7F");
break; break;
@ -887,52 +929,9 @@ init_connection:
case '\n': case '\n':
if (term.sock_ready) TCPSocketSendString(term.sock, "\r\n"); if (term.sock_ready) TCPSocketSendString(term.sock, "\r\n");
break; break;
case CH_CTRLN:
TelnetPrompt(&form);
host = form.host;
port = form.port;
DocClear;
term.waiting_for_input = FALSE;
goto init_connection;
break;
case CH_CTRLO:
art_path = ANSIArtBrowser;
if (art_path != NULL) {
term.sock_ready = 0;
term.waiting_for_input = TRUE;
// SysLog("%s\n", art_path);
goto show_splash;
}
else {
"Error: Could not load art.\n";
}
break;
case CH_CTRLS:
// Save as DD image.
StrCopy(term.doc->filename.name, "::/Home/Wallpapers/1024/Default.DD");
DocWrite(term.doc, TRUE);
break;
case CH_CTRLD:
dark_mode = !dark_mode;
if (dark_mode) Fs->text_attr = WHITE << 4 + BLACK;
else Fs->text_attr = BLACK << 4 + WHITE;
break;
case CH_CTRLT:
original_colors = !original_colors;
if (original_colors) PaletteSetStd(FALSE);
else {
GrPaletteSet(original_palette);
LFBFlush;
}
break;
case CH_CTRLU: case CH_CTRLU:
if(term.sock_ready) TCPSocketSendString(term.sock, "\x15"); if(term.sock_ready) TCPSocketSendString(term.sock, "\x15");
break; break;
// case CH_CTRLP:
// DocFlagsToggle(doc, DOCF_PLAIN_TEXT);
case CH_CTRLL:
PopUpOk("\n\n Not all BBS will work perfectly (yet). \n\n You can load ANSi artwork with Ctrl+O","\n\n\n\t\tMade by y4my4m\n\n");
break;
default: default:
if (key >= ' ' && key <= '~') { if (key >= ' ' && key <= '~') {
// Handle regular keys // Handle regular keys
@ -944,6 +943,8 @@ init_connection:
break; break;
} }
} }
}
} }
catch catch
PutExcept; PutExcept;

View file

@ -118,24 +118,24 @@ U0 DocRelCursorPosSet(CDoc *doc, I64 dx, I64 dy) {
} }
// function to increase/decrease col or row // function to increase/decrease col or row
U0 SetPos(I64 col, I64 row, Bool relativeCol=TRUE) { // U0 SetPos(I64 col, I64 row, Bool relativeCol=TRUE) {
if (col < 0) { // if (col < 0) {
if (relativeCol) // if (relativeCol)
term.current_col += col; // term.current_col += col;
else // else
term.current_col = col; // term.current_col = col;
if (term.current_col > term.window_width) // if (term.current_col > term.window_width)
term.current_col = 1; // term.current_col = 1;
} // }
if (row < 0) { // if (row < 0) {
if (relativeCol) // if (relativeCol)
term.current_row += row; // term.current_row += row;
else // else
term.current_row = row; // term.current_row = row;
if (term.current_row > term.window_height) // if (term.current_row > term.window_height)
term.current_row = 1; // term.current_row = 1;
} // }
} // }
// public I64 ANSIArtBrowser() // public I64 ANSIArtBrowser()
// { // {