Mercurial > hg
comparison mcabber/screen.c @ 12:70ca5b9c648a
[/trunk] Changeset 27 by mikael
* Begin implementation of pending event
* Implement "chatmode" (FALSE == status mode, no message is displayed)
- ESC leaves chat mode
- Enter enters chat mode (if there is a message -- non-empty line --, it is sent)
* Log window use full terminal width
author | mikael |
---|---|
date | Mon, 21 Mar 2005 22:24:17 +0000 |
parents | b8815158a45d |
children | 4c3d7b8a29c4 |
comparison
equal
deleted
inserted
replaced
11:b8815158a45d | 12:70ca5b9c648a |
---|---|
22 WINDOW *win; | 22 WINDOW *win; |
23 PANEL *panel; | 23 PANEL *panel; |
24 char *name; | 24 char *name; |
25 int nlines; | 25 int nlines; |
26 char **texto; | 26 char **texto; |
27 int pending_msg; | |
27 struct list_head list; | 28 struct list_head list; |
28 } window_entry_t; | 29 } window_entry_t; |
29 | 30 |
30 LIST_HEAD(window_list); | 31 LIST_HEAD(window_list); |
31 | 32 |
34 static WINDOW *logWnd, *logWnd_border; | 35 static WINDOW *logWnd, *logWnd_border; |
35 static PANEL *rosterPanel, *chatPanel, *inputPanel; | 36 static PANEL *rosterPanel, *chatPanel, *inputPanel; |
36 static PANEL *logPanel, *logPanel_border; | 37 static PANEL *logPanel, *logPanel_border; |
37 static int maxY, maxX; | 38 static int maxY, maxX; |
38 static window_entry_t *currentWindow; | 39 static window_entry_t *currentWindow; |
40 | |
41 static int chatmode; | |
39 | 42 |
40 static char inputLine[INPUTLINE_LENGTH]; | 43 static char inputLine[INPUTLINE_LENGTH]; |
41 static char *ptr_inputline; | 44 static char *ptr_inputline; |
42 | 45 |
43 | 46 |
340 int n, width, i; | 343 int n, width, i; |
341 window_entry_t *tmp = scr_SearchWindow(winId); | 344 window_entry_t *tmp = scr_SearchWindow(winId); |
342 if (tmp != NULL) { | 345 if (tmp != NULL) { |
343 top_panel(tmp->panel); | 346 top_panel(tmp->panel); |
344 currentWindow = tmp; | 347 currentWindow = tmp; |
348 chatmode = TRUE; | |
349 tmp->pending_msg = FALSE; | |
345 width = scr_WindowHeight(tmp->win); | 350 width = scr_WindowHeight(tmp->win); |
346 for (n = 0; n < tmp->nlines; n++) { | 351 for (n = 0; n < tmp->nlines; n++) { |
347 mvwprintw(tmp->win, n + 1, 1, ""); | 352 mvwprintw(tmp->win, n + 1, 1, ""); |
348 for (i = 0; i < width - 2; i++) | 353 for (i = 0; i < width - 2; i++) |
349 waddch(tmp->win, ' '); | 354 waddch(tmp->win, ' '); |
377 int dont_show = FALSE; | 382 int dont_show = FALSE; |
378 | 383 |
379 | 384 |
380 tmp = scr_SearchWindow(winId); | 385 tmp = scr_SearchWindow(winId); |
381 | 386 |
382 if ((!force_show) && ((!currentWindow || (currentWindow != tmp)))) | 387 if (!chatmode) |
388 dont_show = TRUE; | |
389 else if ((!force_show) && ((!currentWindow || (currentWindow != tmp)))) | |
383 dont_show = TRUE; | 390 dont_show = TRUE; |
384 scr_LogPrint("dont_show=%d", dont_show); | 391 scr_LogPrint("dont_show=%d", dont_show); |
385 | 392 |
386 if (tmp == NULL) { | 393 if (tmp == NULL) { |
387 tmp = scr_CreatePanel(winId, 20, 0, CHAT_WIN_HEIGHT, maxX - 20, dont_show); | 394 tmp = scr_CreatePanel(winId, 20, 0, CHAT_WIN_HEIGHT, maxX - 20, dont_show); |
425 } | 432 } |
426 } | 433 } |
427 | 434 |
428 if (!dont_show) { | 435 if (!dont_show) { |
429 top_panel(tmp->panel); | 436 top_panel(tmp->panel); |
437 tmp->pending_msg = TRUE; | |
430 width = scr_WindowHeight(tmp->win); | 438 width = scr_WindowHeight(tmp->win); |
431 for (n = 0; n < tmp->nlines; n++) { | 439 for (n = 0; n < tmp->nlines; n++) { |
432 mvwprintw(tmp->win, n + 1, 1, ""); | 440 mvwprintw(tmp->win, n + 1, 1, ""); |
433 for (i = 0; i < width - 2; i++) | 441 for (i = 0; i < width - 2; i++) |
434 waddch(tmp->win, ' '); | 442 waddch(tmp->win, ' '); |
459 } | 467 } |
460 | 468 |
461 void scr_DrawMainWindow(void) | 469 void scr_DrawMainWindow(void) |
462 { | 470 { |
463 /* Draw main panels */ | 471 /* Draw main panels */ |
464 rosterWnd = newwin(maxY-1, 20, 0, 0); | 472 rosterWnd = newwin(CHAT_WIN_HEIGHT, 20, 0, 0); |
465 rosterPanel = new_panel(rosterWnd); | 473 rosterPanel = new_panel(rosterWnd); |
466 scr_draw_box(rosterWnd, 0, 0, maxY-1, 20, COLOR_GENERAL, 0, 0); | 474 scr_draw_box(rosterWnd, 0, 0, CHAT_WIN_HEIGHT, 20, COLOR_GENERAL, 0, 0); |
467 mvwprintw(rosterWnd, 0, (20 - strlen(i18n("Roster"))) / 2, | 475 mvwprintw(rosterWnd, 0, (20 - strlen(i18n("Roster"))) / 2, |
468 i18n("Roster")); | 476 i18n("Roster")); |
469 | 477 |
470 chatWnd = newwin(CHAT_WIN_HEIGHT, maxX - 20, 0, 20); | 478 chatWnd = newwin(CHAT_WIN_HEIGHT, maxX - 20, 0, 20); |
471 chatPanel = new_panel(chatWnd); | 479 chatPanel = new_panel(chatWnd); |
473 //mvwprintw(chatWnd, 0, | 481 //mvwprintw(chatWnd, 0, |
474 // ((maxX - 20) - strlen(i18n("Status Window"))) / 2, | 482 // ((maxX - 20) - strlen(i18n("Status Window"))) / 2, |
475 // i18n("Status Window")); | 483 // i18n("Status Window")); |
476 //wbkgd(chatWnd, COLOR_PAIR(COLOR_GENERAL)); | 484 //wbkgd(chatWnd, COLOR_PAIR(COLOR_GENERAL)); |
477 | 485 |
478 logWnd_border = newwin(LOG_WIN_HEIGHT, maxX - 20, CHAT_WIN_HEIGHT, 20); | 486 logWnd_border = newwin(LOG_WIN_HEIGHT, maxX, CHAT_WIN_HEIGHT, 0); |
479 logPanel_border = new_panel(logWnd_border); | 487 logPanel_border = new_panel(logWnd_border); |
480 scr_draw_box(logWnd_border, 0, 0, LOG_WIN_HEIGHT, maxX - 20, COLOR_GENERAL, 0, 0); | 488 scr_draw_box(logWnd_border, 0, 0, LOG_WIN_HEIGHT, maxX, COLOR_GENERAL, 0, 0); |
481 // mvwprintw(logWnd_border, 0, | 489 // mvwprintw(logWnd_border, 0, |
482 // ((maxX - 20) - strlen(i18n("Log Window"))) / 2, | 490 // ((maxX - 20) - strlen(i18n("Log Window"))) / 2, |
483 // i18n("Log Window")); | 491 // i18n("Log Window")); |
484 //logWnd = newwin(LOG_WIN_HEIGHT - 2, maxX-20 - 2, CHAT_WIN_HEIGHT+1, 20+1); | 492 //logWnd = newwin(LOG_WIN_HEIGHT - 2, maxX-20 - 2, CHAT_WIN_HEIGHT+1, 20+1); |
485 logWnd = derwin(logWnd_border, LOG_WIN_HEIGHT-2, maxX-20-2, 1, 1); | 493 logWnd = derwin(logWnd_border, LOG_WIN_HEIGHT-2, maxX-2, 1, 1); |
486 logPanel = new_panel(logWnd); | 494 logPanel = new_panel(logWnd); |
487 wbkgd(logWnd, COLOR_PAIR(COLOR_GENERAL)); | 495 wbkgd(logWnd, COLOR_PAIR(COLOR_GENERAL)); |
488 //wattrset(logWnd, COLOR_PAIR(COLOR_GENERAL)); | 496 //wattrset(logWnd, COLOR_PAIR(COLOR_GENERAL)); |
489 wprintw(logWnd, "Here we are\n"); | 497 wprintw(logWnd, "Here we are\n"); |
490 scr_LogPrint("Here we are :-)"); | 498 scr_LogPrint("Here we are :-)"); |
665 top_panel(inputPanel); | 673 top_panel(inputPanel); |
666 } | 674 } |
667 | 675 |
668 int process_line(char *line, int sock) | 676 int process_line(char *line, int sock) |
669 { | 677 { |
670 if (*line == 0) // XXX Simple checks should maybe be in process_key() | |
671 return 0; | |
672 if (*line != '/') { | 678 if (*line != '/') { |
673 send_message(sock, line); | 679 send_message(sock, line); |
674 return 0; | 680 return 0; |
675 } | 681 } |
676 if (!strcasecmp(line, "/quit")) { | 682 if (!strcasecmp(line, "/quit")) { |
714 case 9: // Tab | 720 case 9: // Tab |
715 scr_LogPrint("I'm unable to complete yet"); | 721 scr_LogPrint("I'm unable to complete yet"); |
716 break; | 722 break; |
717 case '\n': // Enter | 723 case '\n': // Enter |
718 // XXX Test: | 724 // XXX Test: |
725 chatmode = TRUE; | |
726 if (inputLine[0] == 0) { | |
727 scr_ShowBuddyWindow(); | |
728 break; | |
729 } | |
719 if (process_line(inputLine, sock)) | 730 if (process_line(inputLine, sock)) |
720 return 255; | 731 return 255; |
721 ptr_inputline = inputLine; | 732 ptr_inputline = inputLine; |
722 *ptr_inputline = 0; | 733 *ptr_inputline = 0; |
723 break; | 734 break; |
741 break; | 752 break; |
742 case KEY_END: | 753 case KEY_END: |
743 case 5: | 754 case 5: |
744 for (; *ptr_inputline; ptr_inputline++) ; | 755 for (; *ptr_inputline; ptr_inputline++) ; |
745 break; | 756 break; |
746 case 21: // Ctrl-u | 757 case 21: // Ctrl-u |
747 strcpy(inputLine, ptr_inputline); | 758 strcpy(inputLine, ptr_inputline); |
748 ptr_inputline = inputLine; | 759 ptr_inputline = inputLine; |
749 break; | 760 break; |
750 case KEY_EOL: | 761 case KEY_EOL: |
751 case 11: // Ctrl-k | 762 case 11: // Ctrl-k |
752 *ptr_inputline = 0; | 763 *ptr_inputline = 0; |
764 break; | |
765 case 27: // ESC | |
766 currentWindow = NULL; | |
767 chatmode = FALSE; | |
768 top_panel(chatPanel); | |
769 top_panel(inputPanel); | |
753 break; | 770 break; |
754 default: | 771 default: |
755 scr_LogPrint("Unkown key=%o", key); | 772 scr_LogPrint("Unkown key=%o", key); |
756 } | 773 } |
757 //scr_LogPrint("[%02x]", key); | 774 //scr_LogPrint("[%02x]", key); |