freetalk-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Freetalk-dev] Re: curses UI


From: yanis
Subject: [Freetalk-dev] Re: curses UI
Date: Thu, 08 Dec 2005 03:50:25 +0200
User-agent: Mozilla Thunderbird 1.0.7 (X11/20051011)

Hi,
I finally created a simple implementation in ncurses. Although it's very simple, the functionality and the interface is very close to what I have in mind for the final version. One thing I think I should implement soon is the dynamic memory allocation of the wdata struct. I am looking forward for feedback and especially about the API connectivity with freetalk.
   I have attached the source file.

{ tip: use this to compile: $ gcc myui.c -lpanel -lncurses }

yanis


Anand Avati wrote:

Yanis,
We would like to see your initial work. Please do mail it to the mailing
list. You should NOT use readline and ncurses together (you cant).
getch() is the way to go with ncurses. We would like to continue the
discussion about what goes in what language (C and guile) before
something solid happens. We need the code to be well abstracted as API
and control, and fit into the existing freetalk codebase correctly.

Please do forward your attempted work to the mailing list and we can
proceed from there. Other developers too will be happy to give back
their feedback and shape things up.

Happy hacking,
avati
#include <curses.h>
#include <string.h>
#include <panel.h>


struct
wdata
{
        WINDOW *wptr;
        PANEL *pptr;
        int id;
        char name[20];
}wn[20];

int
wcreate(char nm[],int row,int col,int *counterw)
{
        wn[*counterw].wptr = newwin(row-1,col,1,0);
        wn[*counterw].pptr = new_panel(wn[*counterw].wptr);
        wn[*counterw].id = *counterw;
        strcpy(wn[*counterw].name, nm);
        wsetscrreg(wn[*counterw].wptr,0,row);
        scrollok(wn[*counterw].wptr,TRUE);
        return (*counterw)++;
}

int
wtab(int *counterw, int *actw)
{
        if ((*counterw)-1 == *actw)
        {
                *actw=0;
                return 0;
        }
        (*actw)++;
        return 0;
}

int 
main(int argc, char *argv[])
{
        initscr();      /* initialize the curses library */
        cbreak();       /* take input chars one at a time, no wait for \n */
        int row,col,ch,counterw=0,actw,tab_true=0,ignore_enter=1;
        getmaxyx(stdscr,row,col);       /* get max dimensions */
        nonl();
        noecho();
        int wsave(WINDOW *);
        static WINDOW *winput, *wbar;
        winput = newwin(1,col,row-1,0);
        wbar=newwin(1,col,0,0);
        keypad(winput, TRUE);   /* enable keyboard mapping */
        
        actw = wcreate("yanis",row,col,&counterw);
        wcreate("maria",row,col,&counterw);     
        
        while (1)
        {
                while((ch=wgetch(winput))!='\r')
                {
                        if (ch=='\t' && counterw!=0)
                        {       
                                int temp = actw;
                                wtab(&counterw, &actw);
                                top_panel(wn[actw].pptr);
                                mvwprintw(wbar,0,0, "%s",wn[actw].name);
                                wrefresh(wbar);
                                doupdate();
                                tab_true=1;
                                break;
                        }
                        ignore_enter = 0;
                        waddch(winput,ch);
                        waddch(wn[actw].wptr,ch);
                }
                if (tab_true == 0 && !ignore_enter)
                {
                        waddch(wn[actw].wptr,'\n');
                        ignore_enter = 1;
                }
                else
                        tab_true=0;
                waddch(winput,'\r');
                wrefresh(wn[actw].wptr);
                wclrtoeol(winput);
                wrefresh(winput);                               
        }                       
        
        
        endwin();
        exit(0);
}


/*not used yet
int
wsave(WINDOW *w)
{
        FILE *fd;
        fd = fopen("temp","w");
        putwin(w,fd);
}*/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]