lchat

A line oriented chat front end for ii.
git clone git://git.suckless.org/lchat
Log | Files | Refs | README

commit c2233eb6bae4c356cd92d71b9173bd3c62fed00e
parent 5ee1873a1ec3bc220efc5e1d1203b6fec97b8b71
Author: shuall <shualloret@gmail.com>
Date:   Tue, 18 Jul 2017 20:37:40 -0400

add some more control codes

Using st, and these are more for my own convenience.
I'm not sure how they translate to other terminals.
- ctrl+u sends NAK, so clear line on NAK
- home and end don't send 'home' and 'end' vt100 codes,
  they send \033[7~ and \033[8~ respectively

Diffstat:
Mslackline.c | 33+++++++++++++++++++++++++++++++++
Mslackline.h | 3++-
2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/slackline.c b/slackline.c @@ -157,9 +157,39 @@ sl_keystroke(struct slackline *sl, int key) sl->last -= ncur - sl->ptr; *sl->last = '\0'; break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + sl->nummod = key; + sl->esc = ESC_BRACKET_NUM; + return 0; } sl->esc = ESC_NONE; return 0; + case ESC_BRACKET_NUM: + switch(key) { + case '~': + switch(sl->nummod) { + case '7': + sl->bcur = sl->rcur = 0; + sl->ptr = sl->buf; + break; + case '8': + sl->rcur = sl->rlen; + sl->bcur = sl_postobyte(sl, sl->rcur); + sl->ptr = sl->buf + sl->bcur; + break; + } + sl->esc = ESC_NONE; + return 0; + } } /* handle ctl keys */ @@ -188,6 +218,9 @@ sl_keystroke(struct slackline *sl, int key) sl->ptr = ncur; return 0; + case 21: /* ctrl+u or clearline, weird that it's a NAK */ + sl_reset(sl); + return 0; } /* byte-wise composing of UTF-8 runes */ diff --git a/slackline.h b/slackline.h @@ -3,7 +3,7 @@ #include <stdbool.h> -enum esc_seq {ESC_NONE, ESC, ESC_BRACKET}; +enum esc_seq {ESC_NONE, ESC, ESC_BRACKET, ESC_BRACKET_NUM}; struct slackline { /* buffer */ @@ -21,6 +21,7 @@ struct slackline { size_t rlen; /* amount of runes */ enum esc_seq esc; + char nummod; /* UTF-8 handling */ char ubuf[6]; /* UTF-8 buffer */