Display joined channels in status bar. - irc - IRC client based on c9x.me/irc client
 (HTM) git clone git://git.codemadness.org/irc
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit f8a2a7b155eef7c14cf0f08fb24cb04b46c70fa8
 (DIR) parent 43b2c32a6d4ddbb64edbd7428a7d0a425cab6e96
 (HTM) Author: Quentin Carbonneaux <qcarbonneaux@gmail.com>
       Date:   Wed, 14 Mar 2012 23:46:13 +0100
       
       Display joined channels in status bar.
       
       The status bar was not useful, now it displays the list of joined
       channels. The function tdrawbar will redraw the whole bar (no clever
       refreshing here, it does not worth the complexity). Tdrawbar tries to
       keep the current channel in the middle of the bar to maximize the
       context on both sides.
       
       Diffstat:
         M irc.c                               |      37 +++++++++++++++++++++++++++----
       
       1 file changed, 33 insertions(+), 4 deletions(-)
       ---
 (DIR) diff --git a/irc.c b/irc.c
       @@ -48,6 +48,7 @@ int nch, ch; /* Current number of channels, and current channel. */
        char outb[BufSz], *outp=outb; /* Output buffer. */
        
        static void scmd(char *, char *, char *, char *);
       +static void tdrawbar(void);
        static void tredraw(void);
        static void treset(void);
        
       @@ -149,8 +150,9 @@ chadd(char *name)
                        panic("Out of memory.");
                chl[nch].eol=chl[nch].buf;
                chl[nch].n=0;
       -        ch=nch;
       -        return nch++;
       +        ch=nch++;
       +        tdrawbar();
       +        return nch;
        }
        
        static inline int
       @@ -175,6 +177,7 @@ chdel(char *name)
                free(chl[n].buf);
                memmove(&chl[n], &chl[n+1], (nch-n)*sizeof(struct Chan));
                ch=nch-1;
       +        tdrawbar();
                return 1;
        }
        
       @@ -242,6 +245,7 @@ scmd(char *usr, char *cmd, char *par, char *data)
                        if (!ch || !fch || !(s=chfind(ch))) return;
                        chl[s].name[0] = 0;
                        strncat(chl[s].name, fch, ChanLen-1);
       +                tdrawbar();
                } else if (!strcmp(cmd, "471") || !strcmp(cmd, "473")
                       || !strcmp(cmd, "474") || !strcmp(cmd, "475")) { /* Join error. */
                        if ((pm=strtok(0, " "))) {
       @@ -361,6 +365,7 @@ tresize(void)
                wresize(scr.sw, 1, scr.x);
                mvwin(scr.iw, scr.y-1, 0);
                tredraw();
       +        tdrawbar();
        }
        
        static void
       @@ -407,6 +412,30 @@ tredraw(void)
        }
        
        static void
       +tdrawbar(void)
       +{
       +        size_t l;
       +        int fst=ch;
       +
       +        for (l=0; fst>0 && l<scr.x/2; fst--)
       +                l+=strlen(chl[fst].name)+3;
       +
       +        werase(scr.sw);
       +        for (l=0; fst<nch && l<scr.x; fst++) {
       +                char *p=chl[fst].name;
       +
       +                if (fst==ch) wattron(scr.sw, A_BOLD);
       +                waddch(scr.sw, '['), l++;
       +                for (; *p && l<scr.x; p++, l++)
       +                        waddch(scr.sw, *p);
       +                if (l<scr.x-1)
       +                        waddstr(scr.sw, "] "), l+=2;
       +                if (fst==ch) wattroff(scr.sw, A_BOLD);
       +        }
       +        wrefresh(scr.sw);
       +}
       +
       +static void
        tgetch(void)
        {
                static char l[BufSz];
       @@ -418,10 +447,12 @@ tgetch(void)
                switch (c) {
                case CTRL('n'): //0xe:
                        ch=(ch+1)%nch;
       +                tdrawbar();
                        tredraw();
                        return;
                case CTRL('p'): //0x10:
                        ch=(ch+nch-1)%nch;
       +                tdrawbar();
                        tredraw();
                        return;
                case KEY_PPAGE:
       @@ -509,8 +540,6 @@ main(void)
                if (!user) user="Unknown";
                tinit();
                chadd("*server*");
       -        waddstr(scr.sw, "Welcome in irc.");
       -        wrefresh(scr.sw);
                strcpy(nick, "_mpu");
                sfd = dial("chat.freenode.org", 6667);
                sndf("NICK %s", nick);