# HG changeset patch # User mikael # Date 1111011534 0 # Node ID da1fb510081ed60450c74bc3f2ef85dac00f28f0 # Parent b3b2332715fb2a25a3b5e4e7f635457dbd0531a6 [/trunk] Changeset 16 by mikael * Start using an "input line" at the bottom. Only "/quit" is understood at the moment... :) diff -r b3b2332715fb -r da1fb510081e mcabber/main.c --- a/mcabber/main.c Thu Jun 30 21:39:31 2005 +0000 +++ b/mcabber/main.c Wed Mar 16 22:18:54 2005 +0000 @@ -77,6 +77,7 @@ int key; unsigned int port; unsigned int ping; + int ret = 0; credits(); @@ -187,8 +188,8 @@ ut_WriteLog("Entering into main loop...\n\n"); ut_WriteLog("Ready to send/receive messages...\n"); - key = 0; - while (key != 'x') { + + while (ret != 255) { int x; alarm(ping); x = check_io(sock, 0); @@ -214,6 +215,8 @@ if ((x & 2) == 2) { keypad(scr_GetRosterWindow(), TRUE); key = scr_Getch(); + ret = process_key(key); + /* switch (key) { case KEY_IC: bud_AddBuddy(sock); @@ -275,6 +278,7 @@ scr_ShowBuddyWindow(); break; } + */ } } diff -r b3b2332715fb -r da1fb510081e mcabber/screen.c --- a/mcabber/screen.c Thu Jun 30 21:39:31 2005 +0000 +++ b/mcabber/screen.c Wed Mar 16 22:18:54 2005 +0000 @@ -30,11 +30,16 @@ LIST_HEAD(window_list); /* Variables globales a SCREEN.C */ -WINDOW *rosterWnd, *chatWnd; -PANEL *rosterPanel, *chatPanel; +WINDOW *rosterWnd, *chatWnd, *inputWnd; +WINDOW *logWnd, *logWnd_border; +PANEL *rosterPanel, *chatPanel, *inputPanel; +PANEL *logPanel, *logPanel_border; int maxY, maxX; window_entry_t *ventanaActual; +char inputLine[INPUTLINE_LENGTH]; +char *ptr_inputline; + /* Funciones */ @@ -45,9 +50,8 @@ return x; } -void -scr_draw_box(WINDOW * win, int y, int x, int height, int width, int Color, - chtype box, chtype border) +void scr_draw_box(WINDOW * win, int y, int x, int height, int width, + int Color, chtype box, chtype border) { int i, j; @@ -173,9 +177,8 @@ } -void -scr_CreatePopup(char *title, char *texto, int corte, int type, - char *returnstring) +void scr_CreatePopup(char *title, char *texto, int corte, int type, + char *returnstring) { WINDOW *popupWin; PANEL *popupPanel; @@ -336,7 +339,7 @@ waddch(tmp->win, ' '); mvwprintw(tmp->win, n + 1, 1, "%s", tmp->texto[n]); } - move(maxY - 2, maxX - 1); + move(CHAT_WIN_HEIGHT - 1, maxX - 1); update_panels(); doupdate(); } @@ -360,9 +363,9 @@ tmp = scr_SearchWindow(nombreVentana); if (tmp == NULL) { - tmp = scr_CreatePanel(nombreVentana, 20, 0, maxY-1, maxX - 20); - tmp->texto = (char **) calloc(maxY * 3, sizeof(char *)); - for (n = 0; n < (maxY-1) * 3; n++) + tmp = scr_CreatePanel(nombreVentana, 20, 0, CHAT_WIN_HEIGHT, maxX - 20); + tmp->texto = (char **) calloc((CHAT_WIN_HEIGHT+1) * 3, sizeof(char *)); + for (n = 0; n < CHAT_WIN_HEIGHT * 3; n++) tmp->texto[n] = (char *) calloc(1, 1024); if (TimeStamp) { @@ -375,7 +378,7 @@ } tmp->nlines++; } else { - if (tmp->nlines < maxY - 3) { + if (tmp->nlines < CHAT_WIN_HEIGHT - 2) { if (TimeStamp) { ahora = time(NULL); strftime(tmp->texto[tmp->nlines], 1024, @@ -425,28 +428,49 @@ ParseColors(); getmaxyx(stdscr, maxY, maxX); + inputLine[0] = 0; + ptr_inputline = inputLine; return; } void scr_DrawMainWindow(void) { - /* Dibujamos los paneles principales */ + /* Draw main panels */ rosterWnd = newwin(maxY-1, 20, 0, 0); rosterPanel = new_panel(rosterWnd); scr_draw_box(rosterWnd, 0, 0, maxY-1, 20, COLOR_GENERAL, 0, 0); mvwprintw(rosterWnd, 0, (20 - strlen(i18n("Roster"))) / 2, i18n("Roster")); - chatWnd = newwin(maxY-1, maxX - 20, 0, 20); + chatWnd = newwin(CHAT_WIN_HEIGHT, maxX - 20, 0, 20); chatPanel = new_panel(chatWnd); - scr_draw_box(chatWnd, 0, 0, maxY-1, maxX - 20, COLOR_GENERAL, 0, 0); + scr_draw_box(chatWnd, 0, 0, CHAT_WIN_HEIGHT, maxX - 20, COLOR_GENERAL, 0, 0); mvwprintw(chatWnd, 0, ((maxX - 20) - strlen(i18n("Status Window"))) / 2, i18n("Status Window")); + logWnd_border = newwin(LOG_WIN_HEIGHT, maxX - 20, CHAT_WIN_HEIGHT, 20); + logPanel_border = new_panel(logWnd_border); + scr_draw_box(logWnd_border, 0, 0, LOG_WIN_HEIGHT, maxX - 20, COLOR_GENERAL, 0, 0); +// mvwprintw(logWnd_border, 0, +// ((maxX - 20) - strlen(i18n("Log Window"))) / 2, +// i18n("Log Window")); + //logWnd = newwin(LOG_WIN_HEIGHT - 2, maxX-20 - 2, CHAT_WIN_HEIGHT+1, 20+1); + logWnd = derwin(logWnd_border, LOG_WIN_HEIGHT-2, maxX-20-2, 1, 1); + logPanel = new_panel(logWnd); + wbkgd(logWnd, COLOR_PAIR(COLOR_GENERAL)); + //wattrset(logWnd, COLOR_PAIR(COLOR_GENERAL)); + wprintw(logWnd, "Here we are\n"); + + scrollok(logWnd,TRUE); + idlok(logWnd,TRUE); // XXX Necessary? + + inputWnd = newwin(1, maxX, maxY-1, 0); + inputPanel = new_panel(inputWnd); + //wbkgd(inputWnd, COLOR_PAIR(COLOR_GENERAL)); + bud_DrawRoster(rosterWnd); - update_panels(); doupdate(); return; @@ -517,7 +541,7 @@ free(submsgs[i]); free(submsgs); - move(maxY - 2, maxX - 1); + move(CHAT_WIN_HEIGHT - 1, maxX - 1); refresh(); sprintf(buffer2, "%s@%s/%s", cfg_read("username"), cfg_read("server"), cfg_read("resource")); @@ -544,3 +568,56 @@ { return chatWnd; } + +int process_key(int key) +{ + if (isprint(key)) { + char tmpLine[INPUTLINE_LENGTH]; + strcpy(tmpLine, ptr_inputline); + *ptr_inputline++ = key; + strcpy(ptr_inputline, tmpLine); + } else { + switch(key) { + case KEY_BACKSPACE: + if (ptr_inputline != (char*)&inputLine) { + *--ptr_inputline = 0; + } + break; + case KEY_LEFT: + if (ptr_inputline != (char*)&inputLine) { + ptr_inputline--; + } + break; + case KEY_RIGHT: + if (*ptr_inputline) + ptr_inputline++; + break; + case 9: // Tab + wprintw(logWnd, "\nI'm unable to complete yet"); + break; + case '\n': // Enter + // XXX Test: + if (!strcasecmp(inputLine, "/quit")) { + return 255; + } + // TODO processing + ptr_inputline = inputLine; + *ptr_inputline = 0; + break; + case KEY_UP: + bud_RosterUp(); + break; + case KEY_DOWN: + bud_RosterDown(); + break; + } + } + mvwprintw(inputWnd, 0,0, "%s", inputLine); + wclrtoeol(inputWnd); + if (*ptr_inputline) { + wmove(inputWnd, 0, ptr_inputline - (char*)&inputLine); + } + update_panels(); + doupdate(); + return 0; +} diff -r b3b2332715fb -r da1fb510081e mcabber/screen.h --- a/mcabber/screen.h Thu Jun 30 21:39:31 2005 +0000 +++ b/mcabber/screen.h Wed Mar 16 22:18:54 2005 +0000 @@ -10,6 +10,11 @@ #define COLOR_BD_DESSEL 6 #define COLOR_BD_DES 7 +#define LOG_WIN_HEIGHT (5+2) +#define CHAT_WIN_HEIGHT (maxY-1-LOG_WIN_HEIGHT) + +#define INPUTLINE_LENGTH 1024 + void scr_InitCurses(void); void scr_DrawMainWindow(void); void scr_TerminateCurses(void); @@ -26,5 +31,6 @@ int scr_Getch(void); +int process_key(int); #endif