From 43b2c32a6d4ddbb64edbd7428a7d0a425cab6e96 Mon Sep 17 00:00:00 2001 From: Quentin Carbonneaux Date: Mon, 12 Mar 2012 09:40:37 +0100 Subject: Heavy surgery on tgetch. The code layout used in the main switch was unified. The printer was re written from scratch to handle long input lines. The code is supposed to resist to terminal resizes (with some slight refresh problems). --- irc.c | 62 ++++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 20 deletions(-) diff --git a/irc.c b/irc.c index 9e5f1af..a5e3c0a 100644 --- a/irc.c +++ b/irc.c @@ -410,14 +410,20 @@ static void tgetch(void) { static char l[BufSz]; - static size_t cu=0, len=0; + static size_t shft, cu, len; size_t dirty=len+1, i; int c; c=wgetch(scr.iw); switch (c) { - case 0xe: ch=(ch+1)%nch; tredraw(); return; - case 0x10: ch=(ch+nch-1)%nch; tredraw(); return; + case CTRL('n'): //0xe: + ch=(ch+1)%nch; + tredraw(); + return; + case CTRL('p'): //0x10: + ch=(ch+nch-1)%nch; + tredraw(); + return; case KEY_PPAGE: chl[ch].n+=SCROLL; tredraw(); @@ -427,14 +433,24 @@ tgetch(void) if (chl[ch].n<0) chl[ch].n=0; tredraw(); return; - case 0x1: cu=0; break; - case 0x5: cu=len; break; - case 0x2: - case KEY_LEFT: if (cu) cu--; break; - case 0x6: - case KEY_RIGHT: if (cu=scr.x/2 ? scr.x/2 : shft; + while (cu>=scr.x+shft) + dirty=0, shft += scr.x/2; + if (dirty<=shft) + i=shft; + else if (dirty>scr.x+shft || dirty>len) + goto mvcur; + else + i=dirty; + wmove(scr.iw, 0, i-shft); + wclrtoeol(scr.iw); + for (; i-shft