lchat

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

commit bb7df7358d69a9cdc41ab99469fcc75b36fd12f6
parent 3c88c1a6fece6f3e92dc4876fbc9609394d22f47
Author: Jan Klemkow <j.klemkow@wemelug.de>
Date:   Sat,  9 Jul 2016 22:47:39 +0200

fix some bugs

Diffstat:
Msl_test.c | 27++++++++++++++++++---------
Mslackline.c | 11+++++++++--
2 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/sl_test.c b/sl_test.c @@ -15,11 +15,13 @@ strokes(struct slackline *sl, const char *str) static void print_state(struct slackline *sl) { - printf("rcur: %zu bcur: %zu rlen: %zu blen: %zu buf: \"%s\" ", - sl->rcur, sl->bcur, sl->rlen, sl->blen, sl->buf); + size_t l = sl->last - sl->buf; + + printf("rcur: %zu bcur: %zu rlen: %zu blen: %zu l: %zu buf: \"%s\" ", + sl->rcur, sl->bcur, sl->rlen, sl->blen, l, sl->buf); for (size_t i = 0; i < strlen(sl->buf); i++) - printf("%2x", sl->buf[i]); + printf("%X", sl->buf[i] & 0xff); putchar('\n'); } @@ -65,22 +67,29 @@ check_ascii(struct slackline *sl) static void check_utf8(struct slackline *sl) { - /* ae | oe | ue */ - strokes(sl, "\xC3\xA4\xC3\xBC\xC3\xB6"); + /* ae | oe | ue | ss */ + strokes(sl, "\xC3\xA4\xC3\xBC\xC3\xB6\xC3\x9F"); + assert(sl->blen == 8); + assert(sl->rlen == 4); + assert(sl->bcur == 8); + assert(sl->rcur == 4); + assert(sl->last - sl->buf == sl->blen); + + strokes(sl, "\x08"); /* backspace */ assert(sl->blen == 6); assert(sl->rlen == 3); assert(sl->bcur == 6); assert(sl->rcur == 3); assert(sl->last - sl->buf == sl->blen); - strokes(sl, "\x08"); /* backspace */ - assert(sl->blen == 4); - assert(sl->rlen == 2); + strokes(sl, "\x1b[D"); /* left arrow key */ + assert(sl->blen == 6); + assert(sl->rlen == 3); assert(sl->bcur == 4); assert(sl->rcur == 2); assert(sl->last - sl->buf == sl->blen); - strokes(sl, "\x1b[D"); /* left arrow key */ + strokes(sl, "\x08"); /* backspace */ assert(sl->blen == 4); assert(sl->rlen == 2); assert(sl->bcur == 2); diff --git a/slackline.c b/slackline.c @@ -126,18 +126,22 @@ sl_keystroke(struct slackline *sl, int key) if (sl->rcur < sl->rlen) sl->rcur++; sl->bcur = sl_postobyte(sl, sl->rcur); + sl->ptr = sl->buf + sl->bcur; break; case 'D': /* left */ if (sl->rcur > 0) sl->rcur--; sl->bcur = sl_postobyte(sl, sl->rcur); + sl->ptr = sl->buf + sl->bcur; break; case 'H': /* Home */ sl->bcur = sl->rcur = 0; + sl->ptr = sl->buf; break; case 'F': /* End */ sl->rcur = sl->rlen; sl->bcur = sl_postobyte(sl, sl->rcur); + sl->ptr = sl->buf + sl->bcur; break; } sl->esc = ESC_NONE; @@ -161,11 +165,14 @@ sl_keystroke(struct slackline *sl, int key) sl->rcur--; sl->rlen--; - sl->last -= sl->ptr - ncur; - sl->ptr = ncur; sl->bcur = sl_postobyte(sl, sl->rcur); sl->blen = sl_postobyte(sl, sl->rlen); + + sl->last -= sl->ptr - ncur; *sl->last = '\0'; + + sl->ptr = ncur; + return 0; }