aboutsummaryrefslogtreecommitdiff
path: root/src/edbox.c
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2026-03-25 03:08:11 -0400
committerB. Watson <urchlay@slackware.uk>2026-03-25 03:08:11 -0400
commitb74d292847b22cf282ff8ae7d1b51df34176ce4d (patch)
tree4717814a5390d1672840c2c417ebb4d9606480d8 /src/edbox.c
parent8f19c016edd9f258c1b39eb44647c685b245f2fc (diff)
downloadfujinet-chat-b74d292847b22cf282ff8ae7d1b51df34176ce4d.tar.gz
Banish cgetc(), and all its annoyances. Much more flexible and precise keyboard control, see keytab.[ch] and kgetc.[ch]
Diffstat (limited to 'src/edbox.c')
-rw-r--r--src/edbox.c198
1 files changed, 62 insertions, 136 deletions
diff --git a/src/edbox.c b/src/edbox.c
index 2eaaf78..4adba8d 100644
--- a/src/edbox.c
+++ b/src/edbox.c
@@ -4,10 +4,10 @@
#include "addrs.h"
#include "screen.h"
#include "edbox.h"
-#include "keyclick.h"
#include "complete.h"
+#include "keytab.h"
-/* TODO: tab completion */
+extern void __fastcall__ bell(void);
char *old_edbox[EDBOX_SIZE];
static u16 old_len;
@@ -61,8 +61,6 @@ void edbox_hide(void) {
etc). not sure if this is more or less annoying than just
refusing to accept more input until Return is pressed. */
void edbox_putc(char c) {
- extern void __fastcall__ bell(void);
-
if(!c)
return; /* no inserting nulls */
@@ -92,12 +90,6 @@ static void restore_old(void) {
edbox_pos = edbox_len = old_len;
}
-static void fake_keystroke(char c) {
- keyclick();
- OS.ch = 0xff;
- edbox_putc(c);
-}
-
static void del_char(void) {
if(!edbox_len) return;
memmove(edit_box + edbox_pos, edit_box + edbox_pos + 1, EDBOX_SIZE - edbox_pos - 1);
@@ -167,174 +159,108 @@ static void del_to_start(void) {
while(edbox_pos) backspace();
}
-static void normal_keystroke(void) {
- char c;
+void left(void) {
+ if(edbox_pos) edbox_pos--;
+}
- c = cgetc();
+void right(void) {
+ if(edbox_pos < edbox_len) edbox_pos++;
+}
- if(c != CH_TAB)
+void edbox_keystroke(char c) {
+ extern char start_latch;
+ extern void start_keystroke(char);
+
+ if(c == CH_ESC) {
+ start_latch = 1;
+ return;
+ }
+
+ if(c != XCH_TAB)
comp_complete_done();
+ if(c >= XCH_SCR1 && c <= XCH_SCR7) {
+ start_keystroke(c & 0x7f);
+ return;
+ } else if(c == XCH_ACTIVE) {
+ start_keystroke('a');
+ return;
+ }
+
+ edbox_show();
+ hide_cursor();
+
switch(c) {
case CH_EOL:
- // hide_cursor(); // already done by the caller
copy_to_old();
edbox_hide();
if(edbox_callback)
(*edbox_callback)();
edbox_clear();
break;
- case CH_CLR:
+ case XCH_TAB:
+ comp_complete();
+ break;
+ case XCH_UP:
+ up();
+ break;
+ case XCH_DOWN:
+ down();
+ break;
+ case XCH_LEFT:
+ left();
+ break;
+ case XCH_RIGHT:
+ right();
+ break;
+ case XCH_LWORD:
+ back_word();
+ break;
+ case XCH_RWORD:
+ forward_word();
+ break;
+ case XCH_CLS:
+ edbox_clear();
edbox_hide();
- /* fall thru */
+ return;
+ case CH_DELCHR:
+ case 0x18: /* ^X */
+ del_char();
+ break;
case CH_DELLINE:
edbox_clear();
break;
+ case XCH_INSCHR:
+ typeover = !typeover;
+ break;
case 0x15: /* ^U */
del_to_start();
break;
case 0x0b: /* ^K */
del_to_end();
break;
- case CH_DEL:
- case 0x18: /* ^X */
+ case XCH_BS:
if(!edbox_len)
edbox_hide();
else
backspace();
break;
- case 0x02: /* ^B */
- back_word();
- break;
- case 0x06: /* ^F */
- forward_word();
- break;
case 0x17: /* ^W */
del_word();
break;
- case CH_CURS_LEFT:
- if(edbox_pos) edbox_pos--;
- break;
- case CH_CURS_RIGHT:
- if(edbox_pos < edbox_len) edbox_pos++;
- break;
- case CH_CURS_UP:
- up();
- break;
- case CH_CURS_DOWN:
- down();
- break;
- case CH_DELCHR:
- del_char();
- break;
case 0x01: /* ^A */
edbox_pos = 0;
break;
case 0x05: /* ^E */
edbox_pos = edbox_len;
break;
- case CH_TAB:
- comp_complete();
- break;
- case 0xff: /* ctrl-insert */
- typeover = !typeover;
- break;
default:
edbox_putc(c);
break;
}
-}
-
-void edbox_keystroke(void) {
- extern char start_latch;
- extern void start_keystroke(void);
- char c;
-
- if(OS.ssflag) OS.ch = 0x9f;
- while(OS.ch == 0xff)
- ;
-
- /* filter out all ctrl-shift key combos except the ones
- we actually support */
- if(OS.ch == 0xce) {
- /* ctrl-shift-up, same as ^B = back 1 word */
- OS.ch = 0x95;
- } else if(OS.ch == 0xcf) {
- /* ctrl-shift-down, same as ^F = forward 1 word */
- OS.ch = 0xb8;
- } else if(OS.ch > 0xbf) {
- OS.ch = 0xff;
- return;
- }
-
- /* keys we want to ignore or act on without showing the edbox */
- switch(OS.ch) {
- case 0x1c: /* key: ESC */
- keyclick();
- start_latch = 1;
- return;
- case 0x9f: /* ctrl-1 (XXX: the OS traps this, we never see it!) */
- case 0x9e: /* ctrl-2 */
- case 0x9a: /* ctrl-3 (crash if cgetc() reads it!) */
- case 0x98: /* ctrl-4 */
- case 0x9d: /* ctrl-5 */
- case 0x9b: /* ctrl-6 */
- case 0xb3: /* ctrl-7 */
- OS.ch &= 0x7f;
- start_latch = 1;
- start_keystroke();
- return;
- case 0x6c: /* shift-tab */
- case 0xac: /* ctrl-tab */
- OS.ch = 0xff; /* ignore it! */
- return;
- break;
- }
- edbox_show();
-
- /* keys we want to act on, and show the edbox after */
- c = 0;
- switch(OS.ch) {
- case 0xa0: /* key: ctrl [ */
- c = 0x7b; /* ascii: { */
- break;
- case 0xa2: /* key: ctrl ] */
- c = 0x7d; /* ascii: } */
- break;
- break;
- case 0x5c: /* key: shift ESC */
- c = 0x60; /* ascii: ` */
- break;
- case 0x9c: /* key: ctrl ESC */
- c = 0x7e; /* ascii: ~ */
- break;
- case 0x3c: /* caps */
- case 0x7c: /* shift-caps */
- case 0xbc: /* ctrl-caps */
- OS.shflok ^= 0x40;
- keyclick();
- return;
- break;
- case 0x27: /* atari key */
- case 0x67: /* ...w/shift */
- case 0xa7: /* ...w/ctrl */
- c = 0x02; /* ^B = IRC bold formatting char */
- break;
- default:
- break;
- }
-
- hide_cursor();
-
- if(c) {
- fake_keystroke(c);
- } else {
- normal_keystroke();
- }
-
- if(edbox_visible) edbox_show();
show_cursor();
+ if(edbox_visible) edbox_show();
}
void edbox_addchr(char c) {