--- rxvt-unicode/src/command.C 2003/11/27 16:49:45 1.10 +++ rxvt-unicode/src/command.C 2003/12/05 04:05:13 1.12 @@ -1,7 +1,7 @@ /*--------------------------------*-C-*---------------------------------* * File: command.c *----------------------------------------------------------------------* - * $Id: command.C,v 1.10 2003/11/27 16:49:45 pcg Exp $ + * $Id: command.C,v 1.12 2003/12/05 04:05:13 pcg Exp $ * * All portions of code are copyright by their respective author/s. * Copyright (c) 1992 John Bovey, University of Kent at Canterbury @@ -658,6 +658,43 @@ #endif /* MENUBAR_MAX */ void +rxvt_term::flush () +{ +#ifdef TRANSPARENT + if (want_full_refresh) + { + want_full_refresh = 0; + rxvt_scr_clear (this); + rxvt_scr_touch (this, False); + want_refresh = 1; + } +#endif + + if (want_refresh) + { + rxvt_scr_refresh (this, refresh_type); + rxvt_scrollbar_show (this, 1); +#ifdef USE_XIM + rxvt_IMSendSpot (this); +#endif + } + + XFlush (Xdisplay); +#if 0 + if (XPending (Xdisplay)) process_x_events (); + if (XPending (Xdisplay)) process_x_events (); +#endif +} + +void +rxvt_term::check_cb (check_watcher &w) +{ + SET_R (this); + + flush (); +} + +void rxvt_term::process_x_events () { do @@ -711,7 +748,6 @@ w.at += BLINK_INTERVAL; hidden_cursor = !hidden_cursor; want_refresh = 1; - flush (); } void @@ -720,8 +756,144 @@ SET_R (this); process_x_events (); +} - flush (); +bool +rxvt_term::pty_fill () +{ + ssize_t n = cmdbuf_endp - cmdbuf_ptr; + + memmove (cmdbuf_base, cmdbuf_ptr, n); + cmdbuf_ptr = cmdbuf_base; + cmdbuf_endp = cmdbuf_ptr + n; + + n = read (cmd_fd, cmdbuf_endp, BUFSIZ - n); + + if (n > 0) + { + cmdbuf_endp += n; + return true; + } + else if (n < 0 && errno == EAGAIN) + return false; + + destroy (); +} + +void +rxvt_term::pty_cb (io_watcher &w, short revents) +{ + SET_R (this); + + if (revents & EVENT_WRITE) + tt_write (0, 0); + else if (revents & EVENT_READ) + { + bool flag = true; + + // loop, but don't allow a single term to monopolize us + // the number of loops is fully arbitrary, and thus wrong + while (flag && pty_fill ()) + { + if (!seen_input) + { + seen_input = 1; + /* once we know the shell is running, send the screen size. Again! */ + tt_winch (); + } + + uint32_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 */ + uint32_t buf[BUFSIZ]; + bool refreshnow = false; + int nlines = 0; + uint32_t *str = buf; + + *str++ = ch; + + for (;;) + { + ch = next_char (); + + if (ch == NOCHAR || (ch < ' ' && ch != '\t' && ch != '\n' && ch != '\r')) + break; + else + { + *str++ = ch; + + if (ch == '\n') + { + nlines++; + refresh_count++; + + if (!(Options & Opt_jumpScroll) + || (refresh_count >= (refresh_limit * (TermWin.nrow - 1)))) + { + refreshnow = true; + flag = false; + ch = NOCHAR; + break; + } + } + + if (str >= buf + BUFSIZ) + { + ch = NOCHAR; + break; + } + } + } + + rxvt_scr_add_lines (this, 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++; + + rxvt_scr_refresh (this, refresh_type); + } + + } + else + { + switch (ch) + { + default: + rxvt_process_nonprinting (this, ch); + break; + case C0_ESC: /* escape char */ + rxvt_process_escape_seq (this); + break; + /*case 0x9b: */ /* CSI */ + /* rxvt_process_csi_seq (this); */ + } + + ch = NOCHAR; + } + } + } + } } // read the next character, currently handles UTF-8 @@ -779,166 +951,6 @@ return NOCHAR; } -bool -rxvt_term::pty_fill () -{ - ssize_t n = cmdbuf_endp - cmdbuf_ptr; - - memmove (cmdbuf_base, cmdbuf_ptr, n); - cmdbuf_ptr = cmdbuf_base; - cmdbuf_endp = cmdbuf_ptr + n; - - n = read (cmd_fd, cmdbuf_endp, BUFSIZ - n); - - if (n > 0) - { - cmdbuf_endp += n; - return true; - } - else if (n < 0 && errno == EAGAIN) - return false; - - destroy (); -} - -void -rxvt_term::pty_cb (io_watcher &w, short revents) -{ - SET_R (this); - - if (revents & EVENT_WRITE) - tt_write (0, 0); - else if (revents & EVENT_READ) - // loop, but don't allow a single term to monopolize us - // the number of loops is fully arbitrary, and thus wrong - for (int i = 7; i-- && pty_fill (); ) - { - //TODO: - /* once we know the shell is running, send the screen size. Again! */ - //ch = rxvt_cmd_getc(aR); /* wait for something */ - //rxvt_tt_winsize(cmd_fd, TermWin.ncol, TermWin.nrow, cmd_pid); - - uint32_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 */ - uint32_t buf[BUFSIZ]; - bool refreshnow = false; - int nlines = 0; - uint32_t *str = buf; - - *str++ = ch; - - for (;;) - { - ch = next_char (); - - if (ch == NOCHAR || (ch < ' ' && ch != '\t' && ch != '\n' && ch != '\r')) - break; - else - { - *str++ = ch; - - if (ch == '\n') - { - nlines++; - refresh_count++; - - if (!(Options & Opt_jumpScroll) - || (refresh_count >= (refresh_limit * (TermWin.nrow - 1)))) - { - refreshnow = true; - ch = NOCHAR; - break; - } - } - - if (str >= buf + BUFSIZ) - { - ch = NOCHAR; - break; - } - } - } - - rxvt_scr_add_lines (this, 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++; - - rxvt_scr_refresh (this, refresh_type); - } - - } - else - { - switch (ch) - { - default: - rxvt_process_nonprinting (this, ch); - break; - case C0_ESC: /* escape char */ - rxvt_process_escape_seq (this); - break; - /*case 0x9b: */ /* CSI */ - /* rxvt_process_csi_seq (this); */ - } - - ch = NOCHAR; - } - } - } - - flush (); -} - -void -rxvt_term::flush () -{ -#ifdef TRANSPARENT - if (want_full_refresh) - { - want_full_refresh = 0; - rxvt_scr_clear (this); - rxvt_scr_touch (this, False); - want_refresh = 1; - } -#endif - - if (want_refresh) - { - rxvt_scr_refresh (this, refresh_type); - rxvt_scrollbar_show (this, 1); -#ifdef USE_XIM - rxvt_IMSendSpot (this); -#endif - } - - if (XPending (Xdisplay)) process_x_events (); - XFlush (Xdisplay); - if (XPending (Xdisplay)) process_x_events (); -} - /* rxvt_cmd_getc() - Return next input character */ /* * Return the next input character after first passing any keyboard input @@ -2096,15 +2108,15 @@ /* EXTPROTO */ int -rxvt_pclose_printer(FILE *stream) +rxvt_pclose_printer (FILE *stream) { - fflush(stream); + fflush (stream); /* pclose() reported not to work on SunOS 4.1.3 */ # if defined (__sun__) /* TODO: RESOLVE THIS */ /* pclose works provided SIGCHLD handler uses waitpid */ - return pclose(stream); /* return fclose (stream); */ + return pclose (stream); /* return fclose (stream); */ # else - return pclose(stream); + return pclose (stream); # endif }