diff options
Diffstat (limited to 'src/edbox.c')
| -rw-r--r-- | src/edbox.c | 80 |
1 files changed, 69 insertions, 11 deletions
diff --git a/src/edbox.c b/src/edbox.c index 4847713..6dfaaca 100644 --- a/src/edbox.c +++ b/src/edbox.c @@ -25,7 +25,7 @@ static void show_cursor(void) { void edbox_clear(void) { memset(edit_box, 0, EDBOX_SIZE); edbox_pos = edbox_len = 0; - show_cursor(); + show_cursor(); // not needed? seems it is.. } void edbox_show(void) { @@ -49,6 +49,11 @@ void edbox_hide(void) { scr_refresh(); } +/* note: c will never be an EOL. + idea: when the edbox is completely full (240 chars), go + ahead and pretend the user pressed Return (call edbox_callback, + 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) { if(!c) return; /* no inserting nulls */ @@ -60,7 +65,7 @@ void edbox_putc(char c) { edbox_show(); } -static void special_keystroke(char c) { +static void fake_keystroke(char c) { keyclick(); OS.ch = 0xff; edbox_putc(c); @@ -72,24 +77,49 @@ static void del_char(void) { edbox_len--; } +static void del_to_end(void) { + while(edbox_len > edbox_pos) + del_char(); +} + static void backspace(void) { if(!edbox_pos) return; edbox_pos--; del_char(); } -static void del_word(void) { +static void word_left(char del) { if(!edbox_pos) return; edbox_pos--; while(edbox_pos && edit_box[edbox_pos] == ' ') { - del_char(); + if(del) del_char(); edbox_pos--; } while(edbox_pos && edit_box[edbox_pos] != ' ') { - del_char(); + if(del) del_char(); edbox_pos--; } - if(!edbox_pos) edit_box[edbox_pos] = ' '; + // XXX: what's this good for? + if(del && !edbox_pos) edit_box[edbox_pos] = /* ' ' */ 0; +} + +static void del_word(void) { + word_left(1); +} + +static void back_word(void) { + word_left(0); +} + +static void forward_word(void) { + while(edbox_pos < edbox_len && edit_box[edbox_pos] == ' ') + edbox_pos++; + while(edbox_pos < edbox_len && edit_box[edbox_pos] != ' ') + edbox_pos++; +} + +static void del_to_start(void) { + while(edbox_pos) backspace(); } static void normal_keystroke(void) { @@ -99,7 +129,7 @@ static void normal_keystroke(void) { switch(c) { case CH_EOL: - hide_cursor(); + // hide_cursor(); // already done by the caller if(edbox_callback) (*edbox_callback)(); /* fall thru */ @@ -107,12 +137,23 @@ static void normal_keystroke(void) { edbox_hide(); /* fall thru */ case CH_DELLINE: - case 0x15: /* ^U */ edbox_clear(); break; + case 0x15: /* ^U */ + del_to_start(); + break; + case 0x0b: /* ^K */ + del_to_end(); + break; case CH_DEL: backspace(); break; + case 0x02: /* ^B */ + back_word(); + break; + case 0x06: /* ^F */ + forward_word(); + break; case 0x17: /* ^W */ del_word(); break; @@ -122,6 +163,15 @@ static void normal_keystroke(void) { case CH_CURS_RIGHT: if(edbox_pos < edbox_len) edbox_pos++; break; + case CH_CURS_UP: + if(edbox_pos > 39) edbox_pos -= 40; + break; + case CH_CURS_DOWN: + if(edbox_pos < edbox_len - 40) + edbox_pos += 40; + else + edbox_pos = edbox_len; + break; case CH_DELCHR: del_char(); break; @@ -162,16 +212,24 @@ void edbox_keystroke(void) { c = 0x7e; /* ascii: ~ */ break; case 0x3c: /* caps */ + case 0x7c: /* shift-caps */ + case 0xbc: /* ctrl-caps */ OS.shflok ^= 0x40; keyclick(); OS.ch = 0xff; return; break; - case 0x7c: /* shift-caps */ - case 0xbc: /* ctrl-caps */ case 0x27: /* atari key */ case 0x67: /* ...w/shift */ case 0xa7: /* ...w/ctrl */ + c = 0x02; /* ^B = IRC bold formatting char */ + break; + case 0xce: /* ctrl-shift-up, same as... */ + OS.ch = 0x95; /* ^B = back 1 word */ + break; + case 0xcf: /* ctrl-shift-down, same as... */ + OS.ch = 0xb8; /* ^F = forward 1 word */ + break; case 0x9a: /* ctrl-3 (crash if cgetc() reads it!) */ OS.ch = 0xff; /* ignore it! */ return; @@ -183,7 +241,7 @@ void edbox_keystroke(void) { hide_cursor(); if(c) { - special_keystroke(c); + fake_keystroke(c); } else { normal_keystroke(); } |
