aboutsummaryrefslogtreecommitdiff
path: root/src/edbox.c
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2026-02-20 09:16:53 -0500
committerB. Watson <urchlay@slackware.uk>2026-02-20 09:16:53 -0500
commit0b932be4648d99d57319f597386ec98f4ac4f055 (patch)
treee33e30912f0c179ff3408ff1943139fca7b1df94 /src/edbox.c
parentd8c844c0320f816d5f7235fdc171c3e4d964a737 (diff)
downloadfujinet-chat-0b932be4648d99d57319f597386ec98f4ac4f055.tar.gz
edbox: add editing keys, do NOT include EOL in buffer.
Diffstat (limited to 'src/edbox.c')
-rw-r--r--src/edbox.c48
1 files changed, 41 insertions, 7 deletions
diff --git a/src/edbox.c b/src/edbox.c
index 4492308..9231b50 100644
--- a/src/edbox.c
+++ b/src/edbox.c
@@ -9,6 +9,7 @@
// static int edbox_visible = 0; /* don't think we'll ever need it */
static u16 edbox_pos; /* range 0 to EDBOX_SIZE - 1 */
+static u16 edbox_len; /* idem */
void (*edbox_callback)(void);
@@ -22,7 +23,7 @@ static void show_cursor(void) {
void edbox_clear(void) {
memset(edit_box, 0, EDBOX_SIZE);
- edbox_pos = 0;
+ edbox_pos = edbox_len = 0;
show_cursor();
}
@@ -49,17 +50,20 @@ void edbox_putc(char c) {
return; /* no inserting nulls */
if((c != CH_EOL) && (edbox_pos == EDBOX_SIZE - 1))
return;
+ memmove(edit_box + edbox_pos + 1, edit_box + edbox_pos, EDBOX_SIZE - edbox_pos - 1);
edit_box[edbox_pos++] = c;
+ edbox_len++;
edbox_show();
}
void edbox_append(char *s) {
while(*s)
edit_box[edbox_pos++] = *s++;
+ edbox_len = edbox_pos;
}
void edbox_preset(char *s) {
- edbox_pos = 0;
+ edbox_clear();
edbox_append(s);
}
@@ -96,14 +100,30 @@ static void special_keystroke(char c) {
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);
+ edbox_len--;
+}
+
static void backspace(void) {
if(!edbox_pos) return;
- hide_cursor();
- edit_box[--edbox_pos] = 0;
- edbox_show();
+ edbox_pos--;
+ del_char();
}
static void del_word(void) {
+ if(!edbox_pos) return;
+ edbox_pos--;
+ while(edbox_pos && edit_box[edbox_pos] == ' ') {
+ del_char();
+ edbox_pos--;
+ }
+ while(edbox_pos && edit_box[edbox_pos] != ' ') {
+ del_char();
+ edbox_pos--;
+ }
+ if(!edbox_pos) edit_box[edbox_pos] = ' ';
}
static void normal_keystroke(void) {
@@ -113,7 +133,6 @@ static void normal_keystroke(void) {
switch(c) {
case CH_EOL:
- edbox_putc(c);
hide_cursor();
if(edbox_callback)
(*edbox_callback)();
@@ -131,6 +150,21 @@ static void normal_keystroke(void) {
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_DELCHR:
+ del_char();
+ break;
+ case 0x01: /* ^A */
+ edbox_pos = 0;
+ break;
+ case 0x05: /* ^E */
+ edbox_pos = edbox_len;
+ break;
default:
edbox_putc(c);
break;
@@ -143,8 +177,8 @@ void edbox_keystroke(void) {
while(OS.ch == 0xff)
;
- hide_cursor();
edbox_show();
+ hide_cursor();
OS.invflg = c = 0;