Mercurial > ~mikael > mcabber > hg
comparison mcabber/screen.c @ 20:e97f323c8aa2
[/trunk] Changeset 35 by mikael
* Command line improvement (offset, etc.).
author | mikael |
---|---|
date | Thu, 24 Mar 2005 22:02:21 +0000 |
parents | 755a42615cc6 |
children | 7eeda3a06b21 |
comparison
equal
deleted
inserted
replaced
19:0c2d2b79c4b5 | 20:e97f323c8aa2 |
---|---|
3 #include <string.h> | 3 #include <string.h> |
4 #include <ncurses.h> | 4 #include <ncurses.h> |
5 #include <panel.h> | 5 #include <panel.h> |
6 #include <time.h> | 6 #include <time.h> |
7 #include <ctype.h> | 7 #include <ctype.h> |
8 #include <locale.h> | |
8 | 9 |
9 #include "screen.h" | 10 #include "screen.h" |
10 #include "utils.h" | 11 #include "utils.h" |
11 #include "buddies.h" | 12 #include "buddies.h" |
12 #include "parsecfg.h" | 13 #include "parsecfg.h" |
27 static window_entry_t *currentWindow; | 28 static window_entry_t *currentWindow; |
28 | 29 |
29 static int chatmode; | 30 static int chatmode; |
30 int update_roaster; | 31 int update_roaster; |
31 | 32 |
32 static char inputLine[INPUTLINE_LENGTH]; | 33 static char inputLine[INPUTLINE_LENGTH+1]; |
33 static char *ptr_inputline; | 34 static char *ptr_inputline; |
35 static short int inputline_offset; | |
34 | 36 |
35 | 37 |
36 /* Funciones */ | 38 /* Funciones */ |
37 | 39 |
38 int scr_WindowHeight(WINDOW * win) | 40 int scr_WindowHeight(WINDOW * win) |
453 | 455 |
454 getmaxyx(stdscr, maxY, maxX); | 456 getmaxyx(stdscr, maxY, maxX); |
455 inputLine[0] = 0; | 457 inputLine[0] = 0; |
456 ptr_inputline = inputLine; | 458 ptr_inputline = inputLine; |
457 | 459 |
460 //setlocale(LC_CTYPE, ""); | |
461 | |
458 return; | 462 return; |
459 } | 463 } |
460 | 464 |
461 void scr_DrawMainWindow(void) | 465 void scr_DrawMainWindow(void) |
462 { | 466 { |
515 { | 519 { |
516 char **submsgs; | 520 char **submsgs; |
517 int n, i; | 521 int n, i; |
518 char *buffer = (char *) malloc(5 + strlen(text)); | 522 char *buffer = (char *) malloc(5 + strlen(text)); |
519 | 523 |
520 sprintf(buffer, "<-- %s", text); | 524 sprintf(buffer, "<== %s", text); |
521 | 525 |
522 submsgs = | 526 submsgs = |
523 ut_SplitMessage(buffer, &n, maxX - scr_WindowHeight(rosterWnd) - 20); | 527 ut_SplitMessage(buffer, &n, maxX - scr_WindowHeight(rosterWnd) - 20); |
524 | 528 |
525 for (i = 0; i < n; i++) { | 529 for (i = 0; i < n; i++) { |
681 | 685 |
682 scr_LogPrint("Unrecognised command, sorry."); | 686 scr_LogPrint("Unrecognised command, sorry."); |
683 return 0; | 687 return 0; |
684 } | 688 } |
685 | 689 |
690 // check_offset(int direction) | |
691 // Check inputline_offset value, and make sure the cursor is inside the | |
692 // screen. | |
693 inline void check_offset(int direction) | |
694 { | |
695 // Left side | |
696 if (inputline_offset && direction <= 0) { | |
697 while (ptr_inputline <= (char*)&inputLine + inputline_offset) { | |
698 if (inputline_offset) { | |
699 inputline_offset -= 5; | |
700 if (inputline_offset < 0) | |
701 inputline_offset = 0; | |
702 } | |
703 } | |
704 } | |
705 // Right side | |
706 if (direction >= 0) { | |
707 while (ptr_inputline >= inputline_offset + (char*)&inputLine + maxX) | |
708 inputline_offset += 5; | |
709 } | |
710 } | |
711 | |
686 int process_key(int key, int sock) | 712 int process_key(int key, int sock) |
687 { | 713 { |
688 if (isprint(key)) { | 714 if (isprint(key)) { |
689 char tmpLine[INPUTLINE_LENGTH]; | 715 char tmpLine[INPUTLINE_LENGTH+1]; |
716 | |
717 // Check the line isn't too long | |
718 if (strlen(inputLine) >= INPUTLINE_LENGTH) | |
719 return 0; | |
720 | |
721 // Insert char | |
690 strcpy(tmpLine, ptr_inputline); | 722 strcpy(tmpLine, ptr_inputline); |
691 *ptr_inputline++ = key; | 723 *ptr_inputline++ = key; |
692 strcpy(ptr_inputline, tmpLine); | 724 strcpy(ptr_inputline, tmpLine); |
725 check_offset(1); | |
693 } else { | 726 } else { |
694 switch(key) { | 727 switch(key) { |
695 case KEY_BACKSPACE: | 728 case KEY_BACKSPACE: |
696 if (ptr_inputline != (char*)&inputLine) { | 729 if (ptr_inputline != (char*)&inputLine) { |
697 *--ptr_inputline = 0; | 730 *--ptr_inputline = 0; |
731 check_offset(-1); | |
698 } | 732 } |
699 break; | 733 break; |
700 case KEY_DC: | 734 case KEY_DC: |
701 if (*ptr_inputline) | 735 if (*ptr_inputline) |
702 strcpy(ptr_inputline, ptr_inputline+1); | 736 strcpy(ptr_inputline, ptr_inputline+1); |
703 break; | 737 break; |
704 case KEY_LEFT: | 738 case KEY_LEFT: |
705 if (ptr_inputline != (char*)&inputLine) { | 739 if (ptr_inputline != (char*)&inputLine) { |
706 ptr_inputline--; | 740 ptr_inputline--; |
741 check_offset(-1); | |
707 } | 742 } |
708 break; | 743 break; |
709 case KEY_RIGHT: | 744 case KEY_RIGHT: |
710 if (*ptr_inputline) | 745 if (*ptr_inputline) |
711 ptr_inputline++; | 746 ptr_inputline++; |
747 check_offset(1); | |
712 break; | 748 break; |
713 case 9: // Tab | 749 case 9: // Tab |
714 scr_LogPrint("I'm unable to complete yet"); | 750 scr_LogPrint("I'm unable to complete yet"); |
715 break; | 751 break; |
716 case '\n': // Enter | 752 case '\n': // Enter |
722 } | 758 } |
723 if (process_line(inputLine, sock)) | 759 if (process_line(inputLine, sock)) |
724 return 255; | 760 return 255; |
725 ptr_inputline = inputLine; | 761 ptr_inputline = inputLine; |
726 *ptr_inputline = 0; | 762 *ptr_inputline = 0; |
763 inputline_offset = 0; | |
727 break; | 764 break; |
728 case KEY_UP: | 765 case KEY_UP: |
729 bud_RosterUp(); | 766 bud_RosterUp(); |
730 if (chatmode) | 767 if (chatmode) |
731 scr_ShowBuddyWindow(); | 768 scr_ShowBuddyWindow(); |
742 scr_LogPrint("PageDown??"); | 779 scr_LogPrint("PageDown??"); |
743 break; | 780 break; |
744 case KEY_HOME: | 781 case KEY_HOME: |
745 case 1: | 782 case 1: |
746 ptr_inputline = inputLine; | 783 ptr_inputline = inputLine; |
784 inputline_offset = 0; | |
747 break; | 785 break; |
748 case KEY_END: | 786 case KEY_END: |
749 case 5: | 787 case 5: |
750 for (; *ptr_inputline; ptr_inputline++) ; | 788 for (; *ptr_inputline; ptr_inputline++) ; |
789 check_offset(1); | |
751 break; | 790 break; |
752 case 21: // Ctrl-u | 791 case 21: // Ctrl-u |
753 strcpy(inputLine, ptr_inputline); | 792 strcpy(inputLine, ptr_inputline); |
754 ptr_inputline = inputLine; | 793 ptr_inputline = inputLine; |
794 inputline_offset = 0; | |
755 break; | 795 break; |
756 case KEY_EOL: | 796 case KEY_EOL: |
757 case 11: // Ctrl-k | 797 case 11: // Ctrl-k |
758 *ptr_inputline = 0; | 798 *ptr_inputline = 0; |
799 break; | |
800 case 16: // Ctrl-p | |
801 scr_LogPrint("Ctrl-p not yet implemented"); | |
802 break; | |
803 case 14: // Ctrl-n | |
804 scr_LogPrint("Ctrl-n not yet implemented"); | |
759 break; | 805 break; |
760 case 27: // ESC | 806 case 27: // ESC |
761 currentWindow = NULL; | 807 currentWindow = NULL; |
762 chatmode = FALSE; | 808 chatmode = FALSE; |
763 top_panel(chatPanel); | 809 top_panel(chatPanel); |
764 top_panel(inputPanel); | 810 top_panel(inputPanel); |
765 break; | 811 break; |
766 default: | 812 default: |
767 scr_LogPrint("Unkown key=%o", key); | 813 scr_LogPrint("Unkown key=%d", key); |
768 } | 814 } |
769 //scr_LogPrint("[%02x]", key); | 815 //scr_LogPrint("[%02x]", key); |
770 } | 816 } |
771 mvwprintw(inputWnd, 0,0, "%s", inputLine); | 817 mvwprintw(inputWnd, 0,0, "%s", inputLine + inputline_offset); |
772 wclrtoeol(inputWnd); | 818 wclrtoeol(inputWnd); |
773 if (*ptr_inputline) { | 819 if (*ptr_inputline) { |
774 wmove(inputWnd, 0, ptr_inputline - (char*)&inputLine); | 820 wmove(inputWnd, 0, ptr_inputline - (char*)&inputLine - inputline_offset); |
775 } | 821 } |
776 update_panels(); | 822 update_panels(); |
777 doupdate(); | 823 doupdate(); |
778 return 0; | 824 return 0; |
779 } | 825 } |