Mercurial > ~mikael > mcabber > hg
comparison mcabber/screen.c @ 1:da1fb510081e
[/trunk] Changeset 16 by mikael
* Start using an "input line" at the bottom.
Only "/quit" is understood at the moment... :)
author | mikael |
---|---|
date | Wed, 16 Mar 2005 22:18:54 +0000 |
parents | b3b2332715fb |
children | 63acb2dcaeea |
comparison
equal
deleted
inserted
replaced
0:b3b2332715fb | 1:da1fb510081e |
---|---|
28 } window_entry_t; | 28 } window_entry_t; |
29 | 29 |
30 LIST_HEAD(window_list); | 30 LIST_HEAD(window_list); |
31 | 31 |
32 /* Variables globales a SCREEN.C */ | 32 /* Variables globales a SCREEN.C */ |
33 WINDOW *rosterWnd, *chatWnd; | 33 WINDOW *rosterWnd, *chatWnd, *inputWnd; |
34 PANEL *rosterPanel, *chatPanel; | 34 WINDOW *logWnd, *logWnd_border; |
35 PANEL *rosterPanel, *chatPanel, *inputPanel; | |
36 PANEL *logPanel, *logPanel_border; | |
35 int maxY, maxX; | 37 int maxY, maxX; |
36 window_entry_t *ventanaActual; | 38 window_entry_t *ventanaActual; |
39 | |
40 char inputLine[INPUTLINE_LENGTH]; | |
41 char *ptr_inputline; | |
37 | 42 |
38 | 43 |
39 /* Funciones */ | 44 /* Funciones */ |
40 | 45 |
41 int scr_WindowHeight(WINDOW * win) | 46 int scr_WindowHeight(WINDOW * win) |
43 int x, y; | 48 int x, y; |
44 getmaxyx(win, y, x); | 49 getmaxyx(win, y, x); |
45 return x; | 50 return x; |
46 } | 51 } |
47 | 52 |
48 void | 53 void scr_draw_box(WINDOW * win, int y, int x, int height, int width, |
49 scr_draw_box(WINDOW * win, int y, int x, int height, int width, int Color, | 54 int Color, chtype box, chtype border) |
50 chtype box, chtype border) | |
51 { | 55 { |
52 int i, j; | 56 int i, j; |
53 | 57 |
54 wattrset(win, COLOR_PAIR(Color)); | 58 wattrset(win, COLOR_PAIR(Color)); |
55 for (i = 0; i < height; i++) { | 59 for (i = 0; i < height; i++) { |
171 | 175 |
172 return tmp; | 176 return tmp; |
173 } | 177 } |
174 | 178 |
175 | 179 |
176 void | 180 void scr_CreatePopup(char *title, char *texto, int corte, int type, |
177 scr_CreatePopup(char *title, char *texto, int corte, int type, | 181 char *returnstring) |
178 char *returnstring) | |
179 { | 182 { |
180 WINDOW *popupWin; | 183 WINDOW *popupWin; |
181 PANEL *popupPanel; | 184 PANEL *popupPanel; |
182 | 185 |
183 int lineas = 0; | 186 int lineas = 0; |
334 mvwprintw(tmp->win, n + 1, 1, ""); | 337 mvwprintw(tmp->win, n + 1, 1, ""); |
335 for (i = 0; i < width - 2; i++) | 338 for (i = 0; i < width - 2; i++) |
336 waddch(tmp->win, ' '); | 339 waddch(tmp->win, ' '); |
337 mvwprintw(tmp->win, n + 1, 1, "%s", tmp->texto[n]); | 340 mvwprintw(tmp->win, n + 1, 1, "%s", tmp->texto[n]); |
338 } | 341 } |
339 move(maxY - 2, maxX - 1); | 342 move(CHAT_WIN_HEIGHT - 1, maxX - 1); |
340 update_panels(); | 343 update_panels(); |
341 doupdate(); | 344 doupdate(); |
342 } | 345 } |
343 } | 346 } |
344 | 347 |
358 int width; | 361 int width; |
359 window_entry_t *tmp; | 362 window_entry_t *tmp; |
360 | 363 |
361 tmp = scr_SearchWindow(nombreVentana); | 364 tmp = scr_SearchWindow(nombreVentana); |
362 if (tmp == NULL) { | 365 if (tmp == NULL) { |
363 tmp = scr_CreatePanel(nombreVentana, 20, 0, maxY-1, maxX - 20); | 366 tmp = scr_CreatePanel(nombreVentana, 20, 0, CHAT_WIN_HEIGHT, maxX - 20); |
364 tmp->texto = (char **) calloc(maxY * 3, sizeof(char *)); | 367 tmp->texto = (char **) calloc((CHAT_WIN_HEIGHT+1) * 3, sizeof(char *)); |
365 for (n = 0; n < (maxY-1) * 3; n++) | 368 for (n = 0; n < CHAT_WIN_HEIGHT * 3; n++) |
366 tmp->texto[n] = (char *) calloc(1, 1024); | 369 tmp->texto[n] = (char *) calloc(1, 1024); |
367 | 370 |
368 if (TimeStamp) { | 371 if (TimeStamp) { |
369 ahora = time(NULL); | 372 ahora = time(NULL); |
370 strftime(tmp->texto[tmp->nlines], 1024, "[%H:%M] ", | 373 strftime(tmp->texto[tmp->nlines], 1024, "[%H:%M] ", |
373 } else { | 376 } else { |
374 sprintf(tmp->texto[tmp->nlines], " %s", texto); | 377 sprintf(tmp->texto[tmp->nlines], " %s", texto); |
375 } | 378 } |
376 tmp->nlines++; | 379 tmp->nlines++; |
377 } else { | 380 } else { |
378 if (tmp->nlines < maxY - 3) { | 381 if (tmp->nlines < CHAT_WIN_HEIGHT - 2) { |
379 if (TimeStamp) { | 382 if (TimeStamp) { |
380 ahora = time(NULL); | 383 ahora = time(NULL); |
381 strftime(tmp->texto[tmp->nlines], 1024, | 384 strftime(tmp->texto[tmp->nlines], 1024, |
382 "[%H:%M] ", localtime(&ahora)); | 385 "[%H:%M] ", localtime(&ahora)); |
383 strcat(tmp->texto[tmp->nlines], texto); | 386 strcat(tmp->texto[tmp->nlines], texto); |
423 use_default_colors(); | 426 use_default_colors(); |
424 | 427 |
425 ParseColors(); | 428 ParseColors(); |
426 | 429 |
427 getmaxyx(stdscr, maxY, maxX); | 430 getmaxyx(stdscr, maxY, maxX); |
431 inputLine[0] = 0; | |
432 ptr_inputline = inputLine; | |
428 | 433 |
429 return; | 434 return; |
430 } | 435 } |
431 | 436 |
432 void scr_DrawMainWindow(void) | 437 void scr_DrawMainWindow(void) |
433 { | 438 { |
434 /* Dibujamos los paneles principales */ | 439 /* Draw main panels */ |
435 rosterWnd = newwin(maxY-1, 20, 0, 0); | 440 rosterWnd = newwin(maxY-1, 20, 0, 0); |
436 rosterPanel = new_panel(rosterWnd); | 441 rosterPanel = new_panel(rosterWnd); |
437 scr_draw_box(rosterWnd, 0, 0, maxY-1, 20, COLOR_GENERAL, 0, 0); | 442 scr_draw_box(rosterWnd, 0, 0, maxY-1, 20, COLOR_GENERAL, 0, 0); |
438 mvwprintw(rosterWnd, 0, (20 - strlen(i18n("Roster"))) / 2, | 443 mvwprintw(rosterWnd, 0, (20 - strlen(i18n("Roster"))) / 2, |
439 i18n("Roster")); | 444 i18n("Roster")); |
440 | 445 |
441 chatWnd = newwin(maxY-1, maxX - 20, 0, 20); | 446 chatWnd = newwin(CHAT_WIN_HEIGHT, maxX - 20, 0, 20); |
442 chatPanel = new_panel(chatWnd); | 447 chatPanel = new_panel(chatWnd); |
443 scr_draw_box(chatWnd, 0, 0, maxY-1, maxX - 20, COLOR_GENERAL, 0, 0); | 448 scr_draw_box(chatWnd, 0, 0, CHAT_WIN_HEIGHT, maxX - 20, COLOR_GENERAL, 0, 0); |
444 mvwprintw(chatWnd, 0, | 449 mvwprintw(chatWnd, 0, |
445 ((maxX - 20) - strlen(i18n("Status Window"))) / 2, | 450 ((maxX - 20) - strlen(i18n("Status Window"))) / 2, |
446 i18n("Status Window")); | 451 i18n("Status Window")); |
447 | 452 |
453 logWnd_border = newwin(LOG_WIN_HEIGHT, maxX - 20, CHAT_WIN_HEIGHT, 20); | |
454 logPanel_border = new_panel(logWnd_border); | |
455 scr_draw_box(logWnd_border, 0, 0, LOG_WIN_HEIGHT, maxX - 20, COLOR_GENERAL, 0, 0); | |
456 // mvwprintw(logWnd_border, 0, | |
457 // ((maxX - 20) - strlen(i18n("Log Window"))) / 2, | |
458 // i18n("Log Window")); | |
459 //logWnd = newwin(LOG_WIN_HEIGHT - 2, maxX-20 - 2, CHAT_WIN_HEIGHT+1, 20+1); | |
460 logWnd = derwin(logWnd_border, LOG_WIN_HEIGHT-2, maxX-20-2, 1, 1); | |
461 logPanel = new_panel(logWnd); | |
462 wbkgd(logWnd, COLOR_PAIR(COLOR_GENERAL)); | |
463 //wattrset(logWnd, COLOR_PAIR(COLOR_GENERAL)); | |
464 wprintw(logWnd, "Here we are\n"); | |
465 | |
466 scrollok(logWnd,TRUE); | |
467 idlok(logWnd,TRUE); // XXX Necessary? | |
468 | |
469 inputWnd = newwin(1, maxX, maxY-1, 0); | |
470 inputPanel = new_panel(inputWnd); | |
471 //wbkgd(inputWnd, COLOR_PAIR(COLOR_GENERAL)); | |
472 | |
448 bud_DrawRoster(rosterWnd); | 473 bud_DrawRoster(rosterWnd); |
449 | |
450 update_panels(); | 474 update_panels(); |
451 doupdate(); | 475 doupdate(); |
452 return; | 476 return; |
453 } | 477 } |
454 | 478 |
515 | 539 |
516 for (i = 0; i < n; i++) | 540 for (i = 0; i < n; i++) |
517 free(submsgs[i]); | 541 free(submsgs[i]); |
518 free(submsgs); | 542 free(submsgs); |
519 | 543 |
520 move(maxY - 2, maxX - 1); | 544 move(CHAT_WIN_HEIGHT - 1, maxX - 1); |
521 refresh(); | 545 refresh(); |
522 sprintf(buffer2, "%s@%s/%s", cfg_read("username"), | 546 sprintf(buffer2, "%s@%s/%s", cfg_read("username"), |
523 cfg_read("server"), cfg_read("resource")); | 547 cfg_read("server"), cfg_read("resource")); |
524 srv_sendtext(sock, tmp->jid, buffer, buffer2); | 548 srv_sendtext(sock, tmp->jid, buffer, buffer2); |
525 } | 549 } |
542 | 566 |
543 WINDOW *scr_GetStatusWindow(void) | 567 WINDOW *scr_GetStatusWindow(void) |
544 { | 568 { |
545 return chatWnd; | 569 return chatWnd; |
546 } | 570 } |
571 | |
572 int process_key(int key) | |
573 { | |
574 if (isprint(key)) { | |
575 char tmpLine[INPUTLINE_LENGTH]; | |
576 strcpy(tmpLine, ptr_inputline); | |
577 *ptr_inputline++ = key; | |
578 strcpy(ptr_inputline, tmpLine); | |
579 } else { | |
580 switch(key) { | |
581 case KEY_BACKSPACE: | |
582 if (ptr_inputline != (char*)&inputLine) { | |
583 *--ptr_inputline = 0; | |
584 } | |
585 break; | |
586 case KEY_LEFT: | |
587 if (ptr_inputline != (char*)&inputLine) { | |
588 ptr_inputline--; | |
589 } | |
590 break; | |
591 case KEY_RIGHT: | |
592 if (*ptr_inputline) | |
593 ptr_inputline++; | |
594 break; | |
595 case 9: // Tab | |
596 wprintw(logWnd, "\nI'm unable to complete yet"); | |
597 break; | |
598 case '\n': // Enter | |
599 // XXX Test: | |
600 if (!strcasecmp(inputLine, "/quit")) { | |
601 return 255; | |
602 } | |
603 // TODO processing | |
604 ptr_inputline = inputLine; | |
605 *ptr_inputline = 0; | |
606 break; | |
607 case KEY_UP: | |
608 bud_RosterUp(); | |
609 break; | |
610 case KEY_DOWN: | |
611 bud_RosterDown(); | |
612 break; | |
613 } | |
614 } | |
615 mvwprintw(inputWnd, 0,0, "%s", inputLine); | |
616 wclrtoeol(inputWnd); | |
617 if (*ptr_inputline) { | |
618 wmove(inputWnd, 0, ptr_inputline - (char*)&inputLine); | |
619 } | |
620 update_panels(); | |
621 doupdate(); | |
622 return 0; | |
623 } |