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.10 by pcg, Thu Nov 27 16:49:45 2003 UTC vs.
Revision 1.11 by pcg, Tue Dec 2 21:49:46 2003 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*--------------------------------*-C-*---------------------------------*
2 * File: command.c 2 * File: command.c
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * $Id: command.C,v 1.10 2003/11/27 16:49:45 pcg Exp $ 4 * $Id: command.C,v 1.11 2003/12/02 21:49:46 pcg Exp $
5 * 5 *
6 * All portions of code are copyright by their respective author/s. 6 * All portions of code are copyright by their respective author/s.
7 * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk> 7 * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk>
8 * - original version 8 * - original version
9 * Copyright (c) 1994 Robert Nation <nation@rocket.sanders.lockheed.com> 9 * Copyright (c) 1994 Robert Nation <nation@rocket.sanders.lockheed.com>
656 return 0; 656 return 0;
657} 657}
658#endif /* MENUBAR_MAX */ 658#endif /* MENUBAR_MAX */
659 659
660void 660void
661rxvt_term::flush ()
662{
663#ifdef TRANSPARENT
664 if (want_full_refresh)
665 {
666 want_full_refresh = 0;
667 rxvt_scr_clear (this);
668 rxvt_scr_touch (this, False);
669 want_refresh = 1;
670 }
671#endif
672
673 if (want_refresh)
674 {
675 rxvt_scr_refresh (this, refresh_type);
676 rxvt_scrollbar_show (this, 1);
677#ifdef USE_XIM
678 rxvt_IMSendSpot (this);
679#endif
680 }
681
682 XFlush (Xdisplay);
683#if 0
684 if (XPending (Xdisplay)) process_x_events ();
685 if (XPending (Xdisplay)) process_x_events ();
686#endif
687}
688
689void
690rxvt_term::check_cb (check_watcher &w)
691{
692 SET_R (this);
693
694 flush ();
695}
696
697void
661rxvt_term::process_x_events () 698rxvt_term::process_x_events ()
662{ 699{
663 do 700 do
664 { 701 {
665 XEvent xev; 702 XEvent xev;
709 SET_R (this); 746 SET_R (this);
710 747
711 w.at += BLINK_INTERVAL; 748 w.at += BLINK_INTERVAL;
712 hidden_cursor = !hidden_cursor; 749 hidden_cursor = !hidden_cursor;
713 want_refresh = 1; 750 want_refresh = 1;
714 flush ();
715} 751}
716 752
717void 753void
718rxvt_term::x_cb (io_watcher &w, short revents) 754rxvt_term::x_cb (io_watcher &w, short revents)
719{ 755{
720 SET_R (this); 756 SET_R (this);
721 757
722 process_x_events (); 758 process_x_events ();
759}
723 760
724 flush (); 761bool
762rxvt_term::pty_fill ()
763{
764 ssize_t n = cmdbuf_endp - cmdbuf_ptr;
765
766 memmove (cmdbuf_base, cmdbuf_ptr, n);
767 cmdbuf_ptr = cmdbuf_base;
768 cmdbuf_endp = cmdbuf_ptr + n;
769
770 n = read (cmd_fd, cmdbuf_endp, BUFSIZ - n);
771
772 if (n > 0)
773 {
774 cmdbuf_endp += n;
775 return true;
776 }
777 else if (n < 0 && errno == EAGAIN)
778 return false;
779
780 destroy ();
781}
782
783void
784rxvt_term::pty_cb (io_watcher &w, short revents)
785{
786 SET_R (this);
787
788 if (revents & EVENT_WRITE)
789 tt_write (0, 0);
790 else if (revents & EVENT_READ)
791 // loop, but don't allow a single term to monopolize us
792 // the number of loops is fully arbitrary, and thus wrong
793 for (int i = 1; i-- && pty_fill (); )
794 {
795 if (!seen_input)
796 {
797 seen_input = 1;
798 /* once we know the shell is running, send the screen size. Again! */
799 tt_winch ();
800 }
801
802 uint32_t ch = NOCHAR;
803
804 for (;;)
805 {
806 if (ch == NOCHAR)
807 ch = next_char ();
808
809 if (ch == NOCHAR) // TODO: improve
810 break;
811
812 if (ch >= ' ' || ch == '\t' || ch == '\n' || ch == '\r')
813 {
814 /* Read a text string from the input buffer */
815 uint32_t buf[BUFSIZ];
816 bool refreshnow = false;
817 int nlines = 0;
818 uint32_t *str = buf;
819
820 *str++ = ch;
821
822 for (;;)
823 {
824 ch = next_char ();
825
826 if (ch == NOCHAR || (ch < ' ' && ch != '\t' && ch != '\n' && ch != '\r'))
827 break;
828 else
829 {
830 *str++ = ch;
831
832 if (ch == '\n')
833 {
834 nlines++;
835 refresh_count++;
836
837 if (!(Options & Opt_jumpScroll)
838 || (refresh_count >= (refresh_limit * (TermWin.nrow - 1))))
839 {
840 refreshnow = true;
841 ch = NOCHAR;
842 break;
843 }
844 }
845
846 if (str >= buf + BUFSIZ)
847 {
848 ch = NOCHAR;
849 break;
850 }
851 }
852 }
853
854 rxvt_scr_add_lines (this, buf, nlines, str - buf);
855
856 /*
857 * If there have been a lot of new lines, then update the screen
858 * What the heck I'll cheat and only refresh less than every page-full.
859 * the number of pages between refreshes is refresh_limit, which
860 * is incremented here because we must be doing flat-out scrolling.
861 *
862 * refreshing should be correct for small scrolls, because of the
863 * time-out
864 */
865 if (refreshnow)
866 {
867 if ((Options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD)
868 refresh_limit++;
869
870 rxvt_scr_refresh (this, refresh_type);
871 }
872
873 }
874 else
875 {
876 switch (ch)
877 {
878 default:
879 rxvt_process_nonprinting (this, ch);
880 break;
881 case C0_ESC: /* escape char */
882 rxvt_process_escape_seq (this);
883 break;
884 /*case 0x9b: */ /* CSI */
885 /* rxvt_process_csi_seq (this); */
886 }
887
888 ch = NOCHAR;
889 }
890 }
891 }
725} 892}
726 893
727// read the next character, currently handles UTF-8 894// read the next character, currently handles UTF-8
728// will probably handle all sorts of other stuff in the future 895// will probably handle all sorts of other stuff in the future
729uint32_t 896uint32_t
775 return ch; 942 return ch;
776 } 943 }
777 } 944 }
778 945
779 return NOCHAR; 946 return NOCHAR;
780}
781
782bool
783rxvt_term::pty_fill ()
784{
785 ssize_t n = cmdbuf_endp - cmdbuf_ptr;
786
787 memmove (cmdbuf_base, cmdbuf_ptr, n);
788 cmdbuf_ptr = cmdbuf_base;
789 cmdbuf_endp = cmdbuf_ptr + n;
790
791 n = read (cmd_fd, cmdbuf_endp, BUFSIZ - n);
792
793 if (n > 0)
794 {
795 cmdbuf_endp += n;
796 return true;
797 }
798 else if (n < 0 && errno == EAGAIN)
799 return false;
800
801 destroy ();
802}
803
804void
805rxvt_term::pty_cb (io_watcher &w, short revents)
806{
807 SET_R (this);
808
809 if (revents & EVENT_WRITE)
810 tt_write (0, 0);
811 else if (revents & EVENT_READ)
812 // loop, but don't allow a single term to monopolize us
813 // the number of loops is fully arbitrary, and thus wrong
814 for (int i = 7; i-- && pty_fill (); )
815 {
816 //TODO:
817 /* once we know the shell is running, send the screen size. Again! */
818 //ch = rxvt_cmd_getc(aR); /* wait for something */
819 //rxvt_tt_winsize(cmd_fd, TermWin.ncol, TermWin.nrow, cmd_pid);
820
821 uint32_t ch = NOCHAR;
822
823 for (;;)
824 {
825 if (ch == NOCHAR)
826 ch = next_char ();
827
828 if (ch == NOCHAR) // TODO: improve
829 break;
830
831 if (ch >= ' ' || ch == '\t' || ch == '\n' || ch == '\r')
832 {
833 /* Read a text string from the input buffer */
834 uint32_t buf[BUFSIZ];
835 bool refreshnow = false;
836 int nlines = 0;
837 uint32_t *str = buf;
838
839 *str++ = ch;
840
841 for (;;)
842 {
843 ch = next_char ();
844
845 if (ch == NOCHAR || (ch < ' ' && ch != '\t' && ch != '\n' && ch != '\r'))
846 break;
847 else
848 {
849 *str++ = ch;
850
851 if (ch == '\n')
852 {
853 nlines++;
854 refresh_count++;
855
856 if (!(Options & Opt_jumpScroll)
857 || (refresh_count >= (refresh_limit * (TermWin.nrow - 1))))
858 {
859 refreshnow = true;
860 ch = NOCHAR;
861 break;
862 }
863 }
864
865 if (str >= buf + BUFSIZ)
866 {
867 ch = NOCHAR;
868 break;
869 }
870 }
871 }
872
873 rxvt_scr_add_lines (this, buf, nlines, str - buf);
874
875 /*
876 * If there have been a lot of new lines, then update the screen
877 * What the heck I'll cheat and only refresh less than every page-full.
878 * the number of pages between refreshes is refresh_limit, which
879 * is incremented here because we must be doing flat-out scrolling.
880 *
881 * refreshing should be correct for small scrolls, because of the
882 * time-out
883 */
884 if (refreshnow)
885 {
886 if ((Options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD)
887 refresh_limit++;
888
889 rxvt_scr_refresh (this, refresh_type);
890 }
891
892 }
893 else
894 {
895 switch (ch)
896 {
897 default:
898 rxvt_process_nonprinting (this, ch);
899 break;
900 case C0_ESC: /* escape char */
901 rxvt_process_escape_seq (this);
902 break;
903 /*case 0x9b: */ /* CSI */
904 /* rxvt_process_csi_seq (this); */
905 }
906
907 ch = NOCHAR;
908 }
909 }
910 }
911
912 flush ();
913}
914
915void
916rxvt_term::flush ()
917{
918#ifdef TRANSPARENT
919 if (want_full_refresh)
920 {
921 want_full_refresh = 0;
922 rxvt_scr_clear (this);
923 rxvt_scr_touch (this, False);
924 want_refresh = 1;
925 }
926#endif
927
928 if (want_refresh)
929 {
930 rxvt_scr_refresh (this, refresh_type);
931 rxvt_scrollbar_show (this, 1);
932#ifdef USE_XIM
933 rxvt_IMSendSpot (this);
934#endif
935 }
936
937 if (XPending (Xdisplay)) process_x_events ();
938 XFlush (Xdisplay);
939 if (XPending (Xdisplay)) process_x_events ();
940} 947}
941 948
942/* rxvt_cmd_getc() - Return next input character */ 949/* rxvt_cmd_getc() - Return next input character */
943/* 950/*
944 * Return the next input character after first passing any keyboard input 951 * Return the next input character after first passing any keyboard input
2094 return stream; 2101 return stream;
2095} 2102}
2096 2103
2097/* EXTPROTO */ 2104/* EXTPROTO */
2098int 2105int
2099rxvt_pclose_printer(FILE *stream) 2106rxvt_pclose_printer (FILE *stream)
2100{ 2107{
2101 fflush(stream); 2108 fflush (stream);
2102/* pclose() reported not to work on SunOS 4.1.3 */ 2109/* pclose() reported not to work on SunOS 4.1.3 */
2103# if defined (__sun__) /* TODO: RESOLVE THIS */ 2110# if defined (__sun__) /* TODO: RESOLVE THIS */
2104/* pclose works provided SIGCHLD handler uses waitpid */ 2111/* pclose works provided SIGCHLD handler uses waitpid */
2105 return pclose(stream); /* return fclose (stream); */ 2112 return pclose (stream); /* return fclose (stream); */
2106# else 2113# else
2107 return pclose(stream); 2114 return pclose (stream);
2108# endif 2115# endif
2109} 2116}
2110 2117
2111/* 2118/*
2112 * simulate attached vt100 printer 2119 * simulate attached vt100 printer

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines