ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/command.C
(Generate patch)

Comparing rxvt-unicode/src/command.C (file contents):
Revision 1.51 by pcg, Sun Feb 22 08:28:36 2004 UTC vs.
Revision 1.64 by pcg, Wed Mar 3 04:07:52 2004 UTC

110 SET_LOCALE (locale); 110 SET_LOCALE (locale);
111 111
112 if (status_return == XLookupChars 112 if (status_return == XLookupChars
113 || status_return == XLookupBoth) 113 || status_return == XLookupBoth)
114 { 114 {
115 /* make sure the user can type ctrl-@, i.e. NUL */
116 if (len == 1 && *wkbuf == 0)
117 {
118 kbuf[0] = 0;
119 len = 1;
120 }
121 else
122 {
115 wkbuf[len] = 0; 123 wkbuf[len] = 0;
116 len = wcstombs ((char *)kbuf, wkbuf, KBUFSZ); 124 len = wcstombs ((char *)kbuf, wkbuf, KBUFSZ);
117 if (len < 0) 125 if (len < 0)
118 len = 0; 126 len = 0;
127 }
119 } 128 }
120 else 129 else
121 len = 0; 130 len = 0;
122 } 131 }
123 132
282 ^ !!ctrl) ? '\b' : '\177'; 291 ^ !!ctrl) ? '\b' : '\177';
283 kbuf[1] = '\0'; 292 kbuf[1] = '\0';
284 } 293 }
285 else 294 else
286 STRCPY (kbuf, key_backspace); 295 STRCPY (kbuf, key_backspace);
287# ifdef MULTICHAR_SET
288 if ((Options & Opt_mc_hack) && screen.cur.col > 0)
289 {
290 int col, row;
291
292 newlen = STRLEN (kbuf);
293 col = screen.cur.col - 1;
294 row = screen.cur.row + TermWin.saveLines;
295 if (IS_MULTI2 (screen.rend[row][col]))
296 MEMMOVE (kbuf + newlen, kbuf, newlen + 1);
297 }
298# endif
299 break; 296 break;
300#endif 297#endif
301#ifndef NO_DELETE_KEY 298#ifndef NO_DELETE_KEY
302 case XK_Delete: 299 case XK_Delete:
303 STRCPY (kbuf, key_delete); 300 STRCPY (kbuf, key_delete);
304# ifdef MULTICHAR_SET
305 if (Options & Opt_mc_hack)
306 {
307 int col, row;
308
309 newlen = STRLEN (kbuf);
310 col = screen.cur.col;
311 row = screen.cur.row + TermWin.saveLines;
312 if (IS_MULTI1 (screen.rend[row][col]))
313 MEMMOVE (kbuf + newlen, kbuf, newlen + 1);
314 }
315# endif
316 break; 301 break;
317#endif 302#endif
318 case XK_Tab: 303 case XK_Tab:
319 if (shft) 304 if (shft)
320 STRCPY (kbuf, "\033[Z"); 305 STRCPY (kbuf, "\033[Z");
362 kbuf[1] = 'O'; 347 kbuf[1] = 'O';
363 kbuf[2] = "dacb"[keysym - XK_Left]; 348 kbuf[2] = "dacb"[keysym - XK_Left];
364 } 349 }
365 else if (PrivateModes & PrivMode_aplCUR) 350 else if (PrivateModes & PrivMode_aplCUR)
366 kbuf[1] = 'O'; 351 kbuf[1] = 'O';
367#ifdef MULTICHAR_SET
368 //TODO: ??
369 if (Options & Opt_mc_hack)
370 {
371 int col, row, m;
372
373 col = screen.cur.col;
374 row = screen.cur.row + TermWin.saveLines;
375 m = 0;
376 if (keysym == XK_Right
377 && IS_MULTI1 (screen.rend[row][col]))
378 m = 1;
379 else if (keysym == XK_Left)
380 {
381 if (col > 0)
382 {
383 if (IS_MULTI2 (screen.rend[row][col - 1]))
384 m = 1;
385 }
386 else if (screen.cur.row > 0)
387 {
388 col = screen.tlen[--row];
389 if (col == -1)
390 col = TermWin.ncol - 1;
391 else
392 col--;
393 if (col > 0
394 && IS_MULTI2 (screen.rend[row][col]))
395 m = 1;
396 }
397 }
398 if (m)
399 MEMMOVE (kbuf + 3, kbuf, 3 + 1);
400 }
401#endif
402 break; 352 break;
403 353
404#ifndef UNSHIFTED_SCROLLKEYS 354#ifndef UNSHIFTED_SCROLLKEYS
405# ifdef XK_KP_Prior 355# ifdef XK_KP_Prior
406 case XK_KP_Prior: 356 case XK_KP_Prior:
653 kbuf[len - 1] = (shft ? (ctrl ? '@' : '$') : (ctrl ? '^' : '~')); 603 kbuf[len - 1] = (shft ? (ctrl ? '@' : '$') : (ctrl ? '^' : '~'));
654 604
655 /* escape prefix */ 605 /* escape prefix */
656 if (meta 606 if (meta
657#ifdef META8_OPTION 607#ifdef META8_OPTION
658 && (meta_char == C0_ESC) 608 && meta_char == C0_ESC
659#endif 609#endif
660 ) 610 )
661 { 611 {
662 const unsigned char ch = C0_ESC; 612 const unsigned char ch = C0_ESC;
663
664 tt_write (&ch, 1); 613 tt_write (&ch, 1);
665 } 614 }
615
666#ifdef DEBUG_CMD 616#if defined(DEBUG_CMD)
667 if (debug_key)
668 { /* Display keyboard buffer contents */ 617 /* Display keyboard buffer contents */
669 char *p; 618 unsigned char *p;
670 int i; 619 int i;
671 620
672 fprintf (stderr, "key 0x%04X [%d]: `", (unsigned int)keysym, len); 621 fprintf (stderr, "key 0x%04X [%d]: `", (unsigned int)keysym, len);
673 for (i = 0, p = kbuf; i < len; i++, p++) 622 for (i = 0, p = kbuf; i < len; i++, p++)
674 fprintf (stderr, (*p >= ' ' && *p < '\177' ? "%c" : "\\%03o"), *p); 623 fprintf (stderr, (*p >= ' ' && *p < '\177' ? "%c" : "\\%03o"), *p);
675 fprintf (stderr, "'\n"); 624 fprintf (stderr, "'\n");
676 }
677#endif /* DEBUG_CMD */ 625#endif /* DEBUG_CMD */
678 tt_write (kbuf, (unsigned int)len); 626 tt_write (kbuf, (unsigned int)len);
679} 627}
680/*}}} */ 628/*}}} */
681 629
687{ 635{
688 unsigned int n, s; 636 unsigned int n, s;
689 637
690 n = cmdbuf_ptr - cmdbuf_base; 638 n = cmdbuf_ptr - cmdbuf_base;
691 s = cmdbuf_base + BUFSIZ - 1 - cmdbuf_endp; 639 s = cmdbuf_base + BUFSIZ - 1 - cmdbuf_endp;
640
692 if (n > 0 && s < count) 641 if (n > 0 && s < count)
693 { 642 {
694 MEMMOVE (cmdbuf_base, cmdbuf_ptr, 643 MEMMOVE (cmdbuf_base, cmdbuf_ptr,
695 (unsigned int) (cmdbuf_endp - cmdbuf_ptr)); 644 (unsigned int) (cmdbuf_endp - cmdbuf_ptr));
696 cmdbuf_ptr = cmdbuf_base; 645 cmdbuf_ptr = cmdbuf_base;
697 cmdbuf_endp -= n; 646 cmdbuf_endp -= n;
698 s += n; 647 s += n;
699 } 648 }
649
700 if (count > s) 650 if (count > s)
701 { 651 {
702 rxvt_print_error ("data loss: cmd_write too large"); 652 rxvt_print_error ("data loss: cmd_write too large");
703 count = s; 653 count = s;
704 } 654 }
655
705 for (; count--;) 656 for (; count--;)
706 *cmdbuf_endp++ = *str++; 657 *cmdbuf_endp++ = *str++;
658
659 cmd_parse ();
660
707 return 0; 661 return 0;
708} 662}
709#endif /* MENUBAR_MAX */ 663#endif /* MENUBAR_MAX */
710 664
711void 665void
783 cmdbuf_endp += n; 737 cmdbuf_endp += n;
784 return true; 738 return true;
785 } 739 }
786 else if (n < 0 && errno != EAGAIN) 740 else if (n < 0 && errno != EAGAIN)
787 destroy (); 741 destroy ();
788 742
789 return false; 743 return false;
790} 744}
791 745
792void 746void
793rxvt_term::pty_cb (io_watcher &w, short revents) 747rxvt_term::pty_cb (io_watcher &w, short revents)
810 seen_input = 1; 764 seen_input = 1;
811 /* once we know the shell is running, send the screen size. Again! */ 765 /* once we know the shell is running, send the screen size. Again! */
812 tt_winch (); 766 tt_winch ();
813 } 767 }
814 768
769 if (cmd_parse ())
770 break;
771 }
772 }
773}
774
775bool
776rxvt_term::cmd_parse ()
777{
778 bool flag = false;
815 uint32_t ch = NOCHAR; 779 uint32_t ch = NOCHAR;
780
781 for (;;)
782 {
783 if (ch == NOCHAR)
784 ch = next_char ();
785
786 if (ch == NOCHAR) // TODO: improve
787 break;
788
789 if (ch >= ' ' || ch == '\t' || ch == '\n' || ch == '\r')
790 {
791 /* Read a text string from the input buffer */
792 uint32_t buf[BUFSIZ];
793 bool refreshnow = false;
794 int nlines = 0;
795 uint32_t *str = buf;
796
797 *str++ = ch;
816 798
817 for (;;) 799 for (;;)
818 { 800 {
819 if (ch == NOCHAR)
820 ch = next_char (); 801 ch = next_char ();
821 802
822 if (ch == NOCHAR) // TODO: improve 803 if (ch == NOCHAR || (ch < ' ' && ch != '\t' && ch != '\n' && ch != '\r'))
823 break; 804 break;
824 805 else
825 if (ch >= ' ' || ch == '\t' || ch == '\n' || ch == '\r')
826 { 806 {
827 /* Read a text string from the input buffer */
828 uint32_t buf[BUFSIZ];
829 bool refreshnow = false;
830 int nlines = 0;
831 uint32_t *str = buf;
832
833 *str++ = ch; 807 *str++ = ch;
834 808
835 for (;;) 809 if (ch == '\n')
836 { 810 {
837 ch = next_char ();
838
839 if (ch == NOCHAR || (ch < ' ' && ch != '\t' && ch != '\n' && ch != '\r'))
840 break;
841 else 811 nlines++;
812 refresh_count++;
813
814 if (! (Options & Opt_jumpScroll)
815 || (refresh_count >= (refresh_limit * (TermWin.nrow - 1))))
842 { 816 {
843 *str++ = ch;
844
845 if (ch == '\n')
846 {
847 nlines++;
848 refresh_count++;
849
850 if (! (Options & Opt_jumpScroll)
851 || (refresh_count >= (refresh_limit * (TermWin.nrow - 1))))
852 {
853 refreshnow = true; 817 refreshnow = true;
854 flag = false; 818 flag = false;
855 ch = NOCHAR; 819 ch = NOCHAR;
856 break; 820 break;
857 } 821 }
858 822
859 // scr_add_lines only works for nlines < TermWin.nrow - 1. 823 // scr_add_lines only works for nlines < TermWin.nrow - 1.
860 if (nlines >= TermWin.nrow - 1) 824 if (nlines >= TermWin.nrow - 1)
861 { 825 {
862 scr_add_lines (buf, nlines, str - buf); 826 scr_add_lines (buf, nlines, str - buf);
863 nlines = 0; 827 nlines = 0;
864 str = buf; 828 str = buf;
865 }
866 }
867
868 if (str >= buf + BUFSIZ)
869 {
870 ch = NOCHAR;
871 break;
872 }
873 } 829 }
874 } 830 }
875 831
876 scr_add_lines (buf, nlines, str - buf); 832 if (str >= buf + BUFSIZ)
877
878 /*
879 * If there have been a lot of new lines, then update the screen
880 * What the heck I'll cheat and only refresh less than every page-full.
881 * the number of pages between refreshes is refresh_limit, which
882 * is incremented here because we must be doing flat-out scrolling.
883 *
884 * refreshing should be correct for small scrolls, because of the
885 * time-out
886 */
887 if (refreshnow)
888 { 833 {
889 if ((Options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD) 834 ch = NOCHAR;
890 refresh_limit++; 835 break;
891
892 scr_refresh (refresh_type);
893 } 836 }
894
895 }
896 else
897 {
898 switch (ch)
899 {
900 default:
901 process_nonprinting (ch);
902 break;
903 case C0_ESC: /* escape char */
904 process_escape_seq ();
905 break;
906 /*case 0x9b: */ /* CSI */
907 /* process_csi_seq (); */
908 }
909
910 ch = NOCHAR;
911 } 837 }
912 } 838 }
839
840 scr_add_lines (buf, nlines, str - buf);
841
842 /*
843 * If there have been a lot of new lines, then update the screen
844 * What the heck I'll cheat and only refresh less than every page-full.
845 * the number of pages between refreshes is refresh_limit, which
846 * is incremented here because we must be doing flat-out scrolling.
847 *
848 * refreshing should be correct for small scrolls, because of the
849 * time-out
850 */
851 if (refreshnow)
852 {
853 if ((Options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD)
854 refresh_limit++;
855
856 scr_refresh (refresh_type);
857 }
858
859 }
860 else
913 } 861 {
862 switch (ch)
863 {
864 default:
865 process_nonprinting (ch);
866 break;
867 case C0_ESC: /* escape char */
868 process_escape_seq ();
869 break;
870 /*case 0x9b: */ /* CSI */
871 /* process_csi_seq (); */
872 }
873
874 ch = NOCHAR;
875 }
914 } 876 }
877
878 return flag;
915} 879}
916 880
917// read the next character, currently handles UTF-8 881// read the next character, currently handles UTF-8
918// will probably handle all sorts of other stuff in the future 882// will probably handle all sorts of other stuff in the future
919uint32_t 883uint32_t
920rxvt_term::next_char () 884rxvt_term::next_char ()
921{ 885{
922 while (cmdbuf_ptr < cmdbuf_endp) 886 while (cmdbuf_ptr < cmdbuf_endp)
923 { 887 {
924 if (*cmdbuf_ptr < 0x80) // assume < 0x80 to be ascii ALWAYS (all shift-states etc.) uh-oh 888 // assume 0x20 .. 0x7f to be ascii ALWAYS (all shift-states etc.) uh-oh
889 if ((*cmdbuf_ptr <= 0x7f && 0x20 <= *cmdbuf_ptr)
890 || !*cmdbuf_ptr)
925 return *cmdbuf_ptr++; 891 return *cmdbuf_ptr++;
926 892
927 wchar_t wc; 893 wchar_t wc;
928 size_t len = mbrtowc (&wc, (char *)cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate); 894 size_t len = mbrtowc (&wc, (char *)cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate);
929 895
930 if (len == (size_t)-2) 896 if (len == (size_t)-2)
931 return NOCHAR; 897 {
898 // the mbstate stores incomplete sequences. didn't know this :/
899 cmdbuf_ptr = cmdbuf_endp;
900 break;
901 }
932 902
933 if (len == (size_t)-1) 903 if (len == (size_t)-1)
934 return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through 904 return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through
935 905
936 // assume wchar == unicode 906 // assume wchar == unicode
997 pointer_blank (); 967 pointer_blank ();
998} 968}
999#endif 969#endif
1000 970
1001void 971void
1002rxvt_term::mouse_report (const XButtonEvent &ev) 972rxvt_term::mouse_report (XButtonEvent &ev)
1003{ 973{
1004 int button_number, key_state = 0; 974 int button_number, key_state = 0;
1005 int x, y; 975 int x, y;
1006 976
1007 x = ev.x; 977 x = ev.x;
1008 y = ev.y; 978 y = ev.y;
1009 pixel_position (&x, &y); 979 pixel_position (&x, &y);
1010 980
1415 pointer_unblank (); 1385 pointer_unblank ();
1416#endif 1386#endif
1417#if MENUBAR 1387#if MENUBAR
1418 if (isMenuBarWindow (ev.xany.window)) 1388 if (isMenuBarWindow (ev.xany.window))
1419 { 1389 {
1420 menubar_control (& (ev.xbutton)); 1390 menubar_control (ev.xbutton);
1421 break; 1391 break;
1422 } 1392 }
1423#endif 1393#endif
1424 if ((PrivateModes & PrivMode_mouse_report) && ! (bypass_keystate)) 1394 if ((PrivateModes & PrivMode_mouse_report) && ! (bypass_keystate))
1425 break; 1395 break;
1554#endif 1524#endif
1555 } 1525 }
1556} 1526}
1557 1527
1558void 1528void
1559rxvt_term::button_press (const XButtonEvent &ev) 1529rxvt_term::button_press (XButtonEvent &ev)
1560{ 1530{
1561 int reportmode = 0, clickintime; 1531 int reportmode = 0, clickintime;
1562 1532
1563 bypass_keystate = ev.state & (ModMetaMask | ShiftMask); 1533 bypass_keystate = ev.state & (ModMetaMask | ShiftMask);
1564 if (!bypass_keystate) 1534 if (!bypass_keystate)
1792 menubar_control (ev); 1762 menubar_control (ev);
1793#endif 1763#endif
1794} 1764}
1795 1765
1796void 1766void
1797rxvt_term::button_release (const XButtonEvent &ev) 1767rxvt_term::button_release (XButtonEvent &ev)
1798{ 1768{
1799 int reportmode = 0; 1769 int reportmode = 0;
1800 1770
1801 csrO = 0; /* reset csr Offset */ 1771 csrO = 0; /* reset csr Offset */
1802 if (!bypass_keystate) 1772 if (!bypass_keystate)
2337 scr_charset_set (2, (unsigned int)cmd_getc ()); 2307 scr_charset_set (2, (unsigned int)cmd_getc ());
2338 break; 2308 break;
2339 case '+': 2309 case '+':
2340 scr_charset_set (3, (unsigned int)cmd_getc ()); 2310 scr_charset_set (3, (unsigned int)cmd_getc ());
2341 break; 2311 break;
2342#ifdef MULTICHAR_SET
2343 case '$':
2344 scr_charset_set (-2, (unsigned int)cmd_getc ());
2345 break;
2346#endif
2347#ifndef NO_FRILLS 2312#ifndef NO_FRILLS
2348 case '6': 2313 case '6':
2349 scr_backindex (); 2314 scr_backindex ();
2350 break; 2315 break;
2351#endif 2316#endif
2692 case 7: /* unofficial extension */ 2657 case 7: /* unofficial extension */
2693 tt_printf ("%-.250s\n", rs[Rs_display_name]); 2658 tt_printf ("%-.250s\n", rs[Rs_display_name]);
2694 break; 2659 break;
2695#endif 2660#endif
2696 case 8: /* unofficial extension */ 2661 case 8: /* unofficial extension */
2697 xterm_seq (XTerm_title, APL_NAME "-" VERSION, CHAR_ST); 2662 xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST);
2698 break; 2663 break;
2699 } 2664 }
2700 break; 2665 break;
2701 2666
2702 case CSI_TBC: /* 8.3.155: (0) TABULATION CLEAR */ 2667 case CSI_TBC: /* 8.3.155: (0) TABULATION CLEAR */
3074 case XTerm_logfile: 3039 case XTerm_logfile:
3075 break; 3040 break;
3076 case XTerm_font: 3041 case XTerm_font:
3077 change_font (str); 3042 change_font (str);
3078 break; 3043 break;
3044#ifndef NO_FRILLS
3079 case XTerm_locale: 3045 case XTerm_locale:
3080 /* TODO */ 3046 if (str[0] == '?' && !str[1])
3047 tt_printf ("%-.250s\n", locale);
3048 else
3049 {
3050 set_locale (str);
3051# ifdef USE_XIM
3052 im_cb ();
3053# endif
3054 // TODO: call selection_make with the right values set
3055 // to re-fresh the selection.
3056 if (display->selection_owner == this)
3057 display->set_selection_owner (0);
3058 }
3081 break; 3059 break;
3060#endif
3082#if 0 3061#if 0
3083 case XTerm_dumpscreen: /* no error notices */ 3062 case XTerm_dumpscreen: /* no error notices */
3084 { 3063 {
3085 int fd; 3064 int fd;
3086 if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0) 3065 if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines