--- rxvt-unicode/src/command.C 2004/02/22 12:58:02 1.54 +++ rxvt-unicode/src/command.C 2004/03/15 00:08:11 1.73 @@ -112,10 +112,19 @@ if (status_return == XLookupChars || status_return == XLookupBoth) { - wkbuf[len] = 0; - len = wcstombs ((char *)kbuf, wkbuf, KBUFSZ); - if (len < 0) - len = 0; + /* make sure the user can type ctrl-@, i.e. NUL */ + if (len == 1 && *wkbuf == 0) + { + kbuf[0] = 0; + len = 1; + } + else + { + wkbuf[len] = 0; + len = wcstombs ((char *)kbuf, wkbuf, KBUFSZ); + if (len < 0) + len = 0; + } } else len = 0; @@ -133,27 +142,6 @@ if (valid_keysym) { - /* for some backwards compatibility */ -#if defined(HOTKEY_CTRL) || defined(HOTKEY_META) -# ifdef HOTKEY_CTRL - if (ctrl) -# else - if (meta) -# endif - { - if (keysym == ks_bigfont) - { - change_font (FONT_UP); - return; - } - else if (keysym == ks_smallfont) - { - change_font (FONT_DN); - return; - } - } -#endif - if (TermWin.saveLines) { #ifdef UNSHIFTED_SCROLLKEYS @@ -254,17 +242,21 @@ { unsigned int l; const unsigned char *kbuf0; - const unsigned char ch = C0_ESC; kbuf0 = (Keysym_map[keysym & 0xFF]); l = (unsigned int)*kbuf0++; /* escape prefix */ - if (meta) + if (meta # ifdef META8_OPTION - if (meta_char == C0_ESC) + && meta_char == C0_ESC # endif + ) + { + const unsigned char ch = C0_ESC; tt_write (&ch, 1); + } + tt_write (kbuf0, l); return; } @@ -284,35 +276,11 @@ } else STRCPY (kbuf, key_backspace); -# ifdef MULTICHAR_SET - if ((Options & Opt_mc_hack) && screen.cur.col > 0) - { - int col, row; - - newlen = STRLEN (kbuf); - col = screen.cur.col - 1; - row = screen.cur.row + TermWin.saveLines; - if (IS_MULTI2 (screen.rend[row][col])) - MEMMOVE (kbuf + newlen, kbuf, newlen + 1); - } -# endif break; #endif #ifndef NO_DELETE_KEY case XK_Delete: STRCPY (kbuf, key_delete); -# ifdef MULTICHAR_SET - if (Options & Opt_mc_hack) - { - int col, row; - - newlen = STRLEN (kbuf); - col = screen.cur.col; - row = screen.cur.row + TermWin.saveLines; - if (IS_MULTI1 (screen.rend[row][col])) - MEMMOVE (kbuf + newlen, kbuf, newlen + 1); - } -# endif break; #endif case XK_Tab: @@ -364,41 +332,6 @@ } else if (PrivateModes & PrivMode_aplCUR) kbuf[1] = 'O'; -#ifdef MULTICHAR_SET - //TODO: ?? - if (Options & Opt_mc_hack) - { - int col, row, m; - - col = screen.cur.col; - row = screen.cur.row + TermWin.saveLines; - m = 0; - if (keysym == XK_Right - && IS_MULTI1 (screen.rend[row][col])) - m = 1; - else if (keysym == XK_Left) - { - if (col > 0) - { - if (IS_MULTI2 (screen.rend[row][col - 1])) - m = 1; - } - else if (screen.cur.row > 0) - { - col = screen.tlen[--row]; - if (col == -1) - col = TermWin.ncol - 1; - else - col--; - if (col > 0 - && IS_MULTI2 (screen.rend[row][col])) - m = 1; - } - } - if (m) - MEMMOVE (kbuf + 3, kbuf, 3 + 1); - } -#endif break; #ifndef UNSHIFTED_SCROLLKEYS @@ -597,6 +530,7 @@ if (newlen) len = STRLEN (kbuf); } + /* * Pass meta for all function keys, if 'meta' option set */ @@ -621,6 +555,7 @@ for (ch = kbuf; ch < kbuf + len; ch++) *ch |= 0x80; + meta = 0; } #endif @@ -655,25 +590,23 @@ /* escape prefix */ if (meta #ifdef META8_OPTION - && (meta_char == C0_ESC) + && meta_char == C0_ESC #endif ) { const unsigned char ch = C0_ESC; - tt_write (&ch, 1); } -#ifdef DEBUG_CMD - if (debug_key) - { /* Display keyboard buffer contents */ - char *p; - int i; - - fprintf (stderr, "key 0x%04X [%d]: `", (unsigned int)keysym, len); - for (i = 0, p = kbuf; i < len; i++, p++) - fprintf (stderr, (*p >= ' ' && *p < '\177' ? "%c" : "\\%03o"), *p); - fprintf (stderr, "'\n"); - } + +#if defined(DEBUG_CMD) + /* Display keyboard buffer contents */ + unsigned char *p; + int i; + + fprintf (stderr, "key 0x%04X [%d]: `", (unsigned int)keysym, len); + for (i = 0, p = kbuf; i < len; i++, p++) + fprintf (stderr, (*p >= ' ' && *p < '\177' ? "%c" : "\\%03o"), *p); + fprintf (stderr, "'\n"); #endif /* DEBUG_CMD */ tt_write (kbuf, (unsigned int)len); } @@ -689,6 +622,7 @@ n = cmdbuf_ptr - cmdbuf_base; s = cmdbuf_base + BUFSIZ - 1 - cmdbuf_endp; + if (n > 0 && s < count) { MEMMOVE (cmdbuf_base, cmdbuf_ptr, @@ -697,13 +631,18 @@ cmdbuf_endp -= n; s += n; } + if (count > s) { rxvt_print_error ("data loss: cmd_write too large"); count = s; } + for (; count--;) *cmdbuf_endp++ = *str++; + + cmd_parse (); + return 0; } #endif /* MENUBAR_MAX */ @@ -785,7 +724,7 @@ } else if (n < 0 && errno != EAGAIN) destroy (); - + return false; } @@ -812,123 +751,139 @@ tt_winch (); } - uint32_t ch = NOCHAR; + if (cmd_parse ()) + break; + } + } +} + +bool +rxvt_term::cmd_parse () +{ + bool flag = false; + unicode_t ch = NOCHAR; + + for (;;) + { + if (ch == NOCHAR) + ch = next_char (); + + if (ch == NOCHAR) // TODO: improve + break; + + if (ch >= ' ' || ch == '\t' || ch == '\n' || ch == '\r') + { + /* Read a text string from the input buffer */ + unicode_t buf[BUFSIZ]; + bool refreshnow = false; + int nlines = 0; + unicode_t *str = buf; + + *str++ = ch; for (;;) { - if (ch == NOCHAR) - ch = next_char (); + ch = next_char (); - if (ch == NOCHAR) // TODO: improve + if (ch == NOCHAR || (ch < ' ' && ch != '\t' && ch != '\n' && ch != '\r')) break; - - if (ch >= ' ' || ch == '\t' || ch == '\n' || ch == '\r') + else { - /* Read a text string from the input buffer */ - uint32_t buf[BUFSIZ]; - bool refreshnow = false; - int nlines = 0; - uint32_t *str = buf; - *str++ = ch; - for (;;) + if (ch == '\n') { - ch = next_char (); + nlines++; + refresh_count++; - if (ch == NOCHAR || (ch < ' ' && ch != '\t' && ch != '\n' && ch != '\r')) - break; - else + if (! (Options & Opt_jumpScroll) + || (refresh_count >= (refresh_limit * (TermWin.nrow - 1)))) { - *str++ = ch; + refreshnow = true; + flag = false; + ch = NOCHAR; + break; + } - if (ch == '\n') - { - nlines++; - refresh_count++; - - if (! (Options & Opt_jumpScroll) - || (refresh_count >= (refresh_limit * (TermWin.nrow - 1)))) - { - refreshnow = true; - flag = false; - ch = NOCHAR; - break; - } - - // scr_add_lines only works for nlines < TermWin.nrow - 1. - if (nlines >= TermWin.nrow - 1) - { - scr_add_lines (buf, nlines, str - buf); - nlines = 0; - str = buf; - } - } - - if (str >= buf + BUFSIZ) - { - ch = NOCHAR; - break; - } + // scr_add_lines only works for nlines < TermWin.nrow - 1. + if (nlines >= TermWin.nrow - 1) + { + scr_add_lines (buf, nlines, str - buf); + nlines = 0; + str = buf; } } - scr_add_lines (buf, nlines, str - buf); - - /* - * If there have been a lot of new lines, then update the screen - * What the heck I'll cheat and only refresh less than every page-full. - * the number of pages between refreshes is refresh_limit, which - * is incremented here because we must be doing flat-out scrolling. - * - * refreshing should be correct for small scrolls, because of the - * time-out - */ - if (refreshnow) + if (str >= buf + BUFSIZ) { - if ((Options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD) - refresh_limit++; - - scr_refresh (refresh_type); + ch = NOCHAR; + break; } - } - else - { - switch (ch) - { - default: - process_nonprinting (ch); - break; - case C0_ESC: /* escape char */ - process_escape_seq (); - break; - /*case 0x9b: */ /* CSI */ - /* process_csi_seq (); */ - } + } - ch = NOCHAR; - } + scr_add_lines (buf, nlines, str - buf); + + /* + * If there have been a lot of new lines, then update the screen + * What the heck I'll cheat and only refresh less than every page-full. + * the number of pages between refreshes is refresh_limit, which + * is incremented here because we must be doing flat-out scrolling. + * + * refreshing should be correct for small scrolls, because of the + * time-out + */ + if (refreshnow) + { + if ((Options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD) + refresh_limit++; + + scr_refresh (refresh_type); + } + + } + else + { + switch (ch) + { + default: + process_nonprinting (ch); + break; + case C0_ESC: /* escape char */ + process_escape_seq (); + break; + /*case 0x9b: */ /* CSI */ + /* process_csi_seq (); */ } + + ch = NOCHAR; } } + + return flag; } // read the next character, currently handles UTF-8 // will probably handle all sorts of other stuff in the future -uint32_t +unicode_t rxvt_term::next_char () { while (cmdbuf_ptr < cmdbuf_endp) { - if (*cmdbuf_ptr < 0x80) // assume < 0x80 to be ascii ALWAYS (all shift-states etc.) uh-oh + // assume 0x20 .. 0x7f to be ascii ALWAYS (all shift-states etc.) uh-oh + if ((*cmdbuf_ptr <= 0x7f && 0x20 <= *cmdbuf_ptr) + || !*cmdbuf_ptr) return *cmdbuf_ptr++; wchar_t wc; size_t len = mbrtowc (&wc, (char *)cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate); if (len == (size_t)-2) - return NOCHAR; + { + // the mbstate stores incomplete sequences. didn't know this :/ + cmdbuf_ptr = cmdbuf_endp; + break; + } if (len == (size_t)-1) return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through @@ -946,12 +901,12 @@ * Return the next input character after first passing any keyboard input * to the command. */ -uint32_t +unicode_t rxvt_term::cmd_getc () { for (;;) { - uint32_t c = next_char (); + unicode_t c = next_char (); if (c != NOCHAR) return c; @@ -999,10 +954,10 @@ #endif void -rxvt_term::mouse_report (const XButtonEvent &ev) +rxvt_term::mouse_report (XButtonEvent &ev) { - int button_number, key_state = 0; - int x, y; + int button_number, key_state = 0; + int x, y; x = ev.x; y = ev.y; @@ -1417,7 +1372,7 @@ #if MENUBAR if (isMenuBarWindow (ev.xany.window)) { - menubar_control (& (ev.xbutton)); + menubar_control (ev.xbutton); break; } #endif @@ -1556,7 +1511,7 @@ } void -rxvt_term::button_press (const XButtonEvent &ev) +rxvt_term::button_press (XButtonEvent &ev) { int reportmode = 0, clickintime; @@ -1794,7 +1749,7 @@ } void -rxvt_term::button_release (const XButtonEvent &ev) +rxvt_term::button_release (XButtonEvent &ev) { int reportmode = 0; @@ -1966,30 +1921,33 @@ /* * Copy display->root pixmap transparency */ - int sx, sy, nx, ny; - unsigned int nw, nh; - Window cr; - XImage *image; - GC gc; - XGCValues gcvalue; + int sx, sy, nx, ny; + unsigned int nw, nh; + Window cr; + XImage *image; + GC gc; + XGCValues gcvalue; XTranslateCoordinates (display->display, TermWin.parent[0], display->root, 0, 0, &sx, &sy, &cr); nw = (unsigned int)szHint.width; nh = (unsigned int)szHint.height; nx = ny = 0; + if (sx < 0) { nw += sx; nx = -sx; sx = 0; } + if (sy < 0) { nh += sy; ny = -sy; sy = 0; } + MIN_IT (nw, (unsigned int) (wrootattr.width - sx)); MIN_IT (nh, (unsigned int) (wrootattr.height - sy)); allowedxerror = -1; @@ -2032,6 +1990,7 @@ am_transparent = am_pixmap_trans = 1; } } + if (!am_pixmap_trans) { unsigned int n; @@ -2056,7 +2015,9 @@ if (oldp != TermWin.parent[i]) pchanged = 1; } + n = 0; + if (pchanged) { for (; n < (unsigned int)i; n++) @@ -2070,6 +2031,7 @@ } } } + if (n > (int) (sizeof (TermWin.parent) / sizeof (TermWin.parent[0]))) { @@ -2102,6 +2064,7 @@ ParentRelative); am_transparent = 1; } + for (; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++) TermWin.parent[i] = None; } @@ -2117,7 +2080,7 @@ FILE * rxvt_term::popen_printer () { - FILE *stream = popen (rs[Rs_print_pipe], "w"); + FILE *stream = popen (rs[Rs_print_pipe], "w"); if (stream == NULL) rxvt_print_error ("can't open printer pipe"); @@ -2339,11 +2302,6 @@ case '+': scr_charset_set (3, (unsigned int)cmd_getc ()); break; -#ifdef MULTICHAR_SET - case '$': - scr_charset_set (-2, (unsigned int)cmd_getc ()); - break; -#endif #ifndef NO_FRILLS case '6': scr_backindex (); @@ -2375,7 +2333,7 @@ /* 8.3.87: NEXT LINE */ case C1_NEL: /* ESC E */ { - uint32_t nlcr[] = { '\n', '\r' }; + unicode_t nlcr[] = { L'\n', L'\r' }; scr_add_lines (nlcr, 1, 2); } break; @@ -2694,7 +2652,7 @@ break; #endif case 8: /* unofficial extension */ - xterm_seq (XTerm_title, APL_NAME "-" VERSION, CHAR_ST); + xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST); break; } break; @@ -2973,12 +2931,13 @@ * 50 = change font * * rxvt extensions: - * 9 = change locale (NYI) * 10 = menu (may change in future) * 20 = bg pixmap * 39 = change default fg color * 49 = change default bg color * 55 = dump scrollback buffer and all of screen + * 701 = change locale + * 702 = find font */ void rxvt_term::xterm_seq (int op, const char *str, unsigned char resp __attribute__ ((unused))) @@ -3076,15 +3035,25 @@ case XTerm_font: change_font (str); break; +#ifndef NO_FRILLS case XTerm_locale: if (str[0] == '?' && !str[1]) tt_printf ("%-.250s\n", locale); else { set_locale (str); +# ifdef USE_XIM im_cb (); +# endif } break; + case XTerm_findfont: + { + int fid = TermWin.fontset->find_font (atoi (str)); + tt_printf ("%d %-.250s\n", fid, (*TermWin.fontset)[fid]->name); + } + break; +#endif #if 0 case XTerm_dumpscreen: /* no error notices */ { @@ -3159,19 +3128,32 @@ #ifdef scrollBar_esc { scrollBar_esc, PrivMode_scrollBar }, #endif + // 18, 19 printing-related { 25, PrivMode_VisibleCursor }, - { 35, PrivMode_ShiftKeys }, + // 30 show scrollbar rxvt. extension + { 35, PrivMode_ShiftKeys }, // rxvt extension { 40, PrivMode_132OK }, + // 41 xterm more fixes NYI + // 45 margin bell NYI + // 46 start logging { 47, PrivMode_Screen }, { 66, PrivMode_aplKP }, #ifndef NO_BACKSPACE_KEY { 67, PrivMode_BackSpace }, #endif { 1000, PrivMode_MouseX11 }, - { 1010, PrivMode_TtyOutputInh }, - { 1011, PrivMode_Keypress }, + // 1001 Use Hilite Mouse Tracking. NYI, TODO + // 1002 Use Cell Motion Mouse Tracking. NYI, TODO + // 1003 Use All Motion Mouse Tracking. NYI, TODO + { 1010, PrivMode_TtyOutputInh }, // rxvt extension + { 1011, PrivMode_Keypress }, // rxvt extension + // 1035 enable modifiers for alt, numlock NYI + // 1036 send ESC for meta keys NYI + // 1037 send DEL for keypad delete NYI { 1047, PrivMode_Screen }, + // 1048 save and restore cursor { 1049, PrivMode_Screen }, /* xterm extension, not fully implemented */ + // 1051, 1052, 1060, 1061 keyboard emulation NYI }; if (nargs == 0) @@ -3196,110 +3178,108 @@ } /* extra handling for values with state unkept */ - if (state == -1) - switch (arg[i]) - { - case 1048: /* alternative cursor save */ - if (mode == 0) - scr_cursor (RESTORE); - else if (mode == 1) - scr_cursor (SAVE); - /* FALLTHROUGH */ - default: - continue; /* for (;i;) */ - } - - /* extra handling for values with valid 0 or 1 state */ switch (arg[i]) { - /* case 1: - application cursor keys */ - case 2: /* VT52 mode */ - /* oddball mode. should be set regardless of set/reset - * parameter. Return from VT52 mode with an ESC < from - * within VT52 mode - */ - PrivMode (1, PrivMode_vt52); - break; - case 3: /* 80/132 */ - if (PrivateModes & PrivMode_132OK) - set_widthheight ( (unsigned int) ((state ? 132 : 80) * TermWin.fwidth), - (unsigned int)TermWin.height); - break; - case 4: /* smooth scrolling */ - if (state) - Options &= ~Opt_jumpScroll; - else - Options |= Opt_jumpScroll; - break; - case 5: /* reverse video */ - scr_rvideo_mode (state); - break; - case 6: /* relative/absolute origins */ - scr_relative_origin (state); - break; - case 7: /* autowrap */ - scr_autowrap (state); - break; - /* case 8: - auto repeat, can't do on a per window basis */ - case 9: /* X10 mouse reporting */ - if (state) /* orthogonal */ - PrivateModes &= ~ (PrivMode_MouseX11); - break; + case 1048: /* alternative cursor save */ + case 1049: + if (mode == 0) + scr_cursor (RESTORE); + else if (mode == 1) + scr_cursor (SAVE); + /* FALLTHROUGH */ + } + + if (state >= 0) + /* extra handling for values with valid 0 or 1 state */ + switch (arg[i]) + { + /* case 1: - application cursor keys */ + case 2: /* VT52 mode */ + /* oddball mode. should be set regardless of set/reset + * parameter. Return from VT52 mode with an ESC < from + * within VT52 mode + */ + PrivMode (1, PrivMode_vt52); + break; + case 3: /* 80/132 */ + if (PrivateModes & PrivMode_132OK) + set_widthheight (((state ? 132 : 80) * TermWin.fwidth), TermWin.height); + break; + case 4: /* smooth scrolling */ + if (state) + Options &= ~Opt_jumpScroll; + else + Options |= Opt_jumpScroll; + break; + case 5: /* reverse video */ + scr_rvideo_mode (state); + break; + case 6: /* relative/absolute origins */ + scr_relative_origin (state); + break; + case 7: /* autowrap */ + scr_autowrap (state); + break; + /* case 8: - auto repeat, can't do on a per window basis */ + case 9: /* X10 mouse reporting */ + if (state) /* orthogonal */ + PrivateModes &= ~ (PrivMode_MouseX11); + break; #ifdef menuBar_esc - case menuBar_esc: + case menuBar_esc: #ifdef MENUBAR - map_menuBar (state); + map_menuBar (state); #endif - break; + break; #endif #ifdef scrollBar_esc - case scrollBar_esc: - if (scrollbar_mapping (state)) - { - resize_all_windows (0, 0, 0); - scr_touch (true); - } - break; + case scrollBar_esc: + if (scrollbar_mapping (state)) + { + resize_all_windows (0, 0, 0); + scr_touch (true); + } + break; #endif - case 25: /* visible/invisible cursor */ - scr_cursor_visible (state); - break; - /* case 35: - shift keys */ - /* case 40: - 80 <--> 132 mode */ - case 47: /* secondary screen */ - scr_change_screen (state); - break; - /* case 66: - application key pad */ - /* case 67: - backspace key */ - case 1000: /* X11 mouse reporting */ - if (state) /* orthogonal */ - PrivateModes &= ~ (PrivMode_MouseX10); - break; + case 25: /* visible/invisible cursor */ + scr_cursor_visible (state); + break; + /* case 35: - shift keys */ + /* case 40: - 80 <--> 132 mode */ + case 47: /* secondary screen */ + scr_change_screen (state); + break; + /* case 66: - application key pad */ + /* case 67: - backspace key */ + case 1000: /* X11 mouse reporting */ + if (state) /* orthogonal */ + PrivateModes &= ~ (PrivMode_MouseX10); + break; #if 0 - case 1001: - break; /* X11 mouse highlighting */ + case 1001: + break; /* X11 mouse highlighting */ #endif - case 1010: /* scroll to bottom on TTY output inhibit */ - if (state) - Options &= ~Opt_scrollTtyOutput; - else - Options |= Opt_scrollTtyOutput; - break; - case 1011: /* scroll to bottom on key press */ - if (state) - Options |= Opt_scrollTtyKeypress; - else - Options &= ~Opt_scrollTtyKeypress; - break; - case 1047: /* secondary screen w/ clearing */ - case 1049: /* better secondary screen w/ clearing, but not fully implemented */ - if (current_screen != PRIMARY) - scr_erase_screen (2); - scr_change_screen (state); - /* FALLTHROUGH */ - default: - break; - } + case 1010: /* scroll to bottom on TTY output inhibit */ + if (state) + Options &= ~Opt_scrollTtyOutput; + else + Options |= Opt_scrollTtyOutput; + break; + case 1011: /* scroll to bottom on key press */ + if (state) + Options |= Opt_scrollTtyKeypress; + else + Options &= ~Opt_scrollTtyKeypress; + break; + case 1047: /* secondary screen w/ clearing */ + case 1049: /* better secondary screen w/ clearing, but not fully implemented */ + if (current_screen != PRIMARY) + scr_erase_screen (2); + scr_change_screen (state); + /* FALLTHROUGH */ + default: + break; + } } } /*}}} */ @@ -3337,6 +3317,9 @@ case 7: rendset = 1, rendstyle = RS_RVid; break; + case 8: + // invisible. NYI + break; case 22: rendset = 0, rendstyle = RS_Bold; break; @@ -3349,7 +3332,11 @@ case 27: rendset = 0, rendstyle = RS_RVid; break; + case 28: + // visible. NYI + break; } + if (rendset != -1) { scr_rendition (rendset, rendstyle); @@ -3366,15 +3353,13 @@ case 35: case 36: case 37: - scr_color ((unsigned int) (minCOLOR + (arg[i] - 30)), - Color_fg); + scr_color ((unsigned int) (minCOLOR + (arg[i] - 30)), Color_fg); break; #ifdef TTY_256COLOR case 38: if (nargs > i + 2 && arg[i + 1] == 5) { - scr_color ((unsigned int) (minCOLOR + arg[i + 2]), - Color_fg); + scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_fg); i += 2; } break; @@ -3391,15 +3376,13 @@ case 45: case 46: case 47: - scr_color ((unsigned int) (minCOLOR + (arg[i] - 40)), - Color_bg); + scr_color ((unsigned int) (minCOLOR + (arg[i] - 40)), Color_bg); break; #ifdef TTY_256COLOR case 48: if (nargs > i + 2 && arg[i + 1] == 5) { - scr_color ((unsigned int) (minCOLOR + arg[i + 2]), - Color_bg); + scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_bg); i += 2; } break;