Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

First zle_refresh.c patch



Heyla,
 this is the first zle_refresh.c patch - some of the changes have made
a bug obvious which was extremely unlikely for people to display before.
You'll have to await patch number 2 for that.

This patch improves the display for long lines (except for the bug still
there :-)
If there's text before the start, you get ">...." at the start. The right
prompt is no longer displayed if this is the case.
If there's text after the end, you get "<...." at the end.

Scrolling for < 9600 speeds is still by the half screen (which is why you
sometimes get lines above your current line even when you've got more than
a screenful of text).  Scrolling for >=9600 is line by line (much prettier).
I'm not entirely confident that this is best speed cutoff.  Perhaps it
should be 19200?




*** zle_refresh.c	1996/06/28 02:05:24	2.5
--- zle_refresh.c	1996/07/13 15:50:22
***************
*** 46,52 ****
  char **nbuf = NULL,		/* new video buffer line-by-line char array */
      **obuf = NULL;		/* old video buffer line-by-line char array */
  static char *lpptbuf, *rpptbuf; /* prompt buffers			    */
! static int olnct,		/* previous number of lines		    */
      ovln,			/* previous video cursor position line	    */
      lpptlen, rpptlen,           /* length of prompt buffers                 */
      pptw, rpw,                  /* prompt widths on screen                  */
--- 46,55 ----
  char **nbuf = NULL,		/* new video buffer line-by-line char array */
      **obuf = NULL;		/* old video buffer line-by-line char array */
  static char *lpptbuf, *rpptbuf; /* prompt buffers			    */
! static int baudrate,		/* BAUD					    */
!     more_start,			/* more text before start of screen?	    */
!     more_end,			/* more stuff after end of screen?	    */
!     olnct,			/* previous number of lines		    */
      ovln,			/* previous video cursor position line	    */
      lpptlen, rpptlen,           /* length of prompt buffers                 */
      pptw, rpw,                  /* prompt widths on screen                  */
***************
*** 106,127 ****
  	showinglist = -2;
  }
  
  /**/
  int
! scrollwindow(int hwinh)
  {
!     int t0;
      char *s;
  
!     for (t0 = 0; t0 != winh - hwinh; t0++) {
! 	s = nbuf[t0];
! 	nbuf[t0] = nbuf[t0 + hwinh];
! 	nbuf[t0 + hwinh] = s;
!     }
!     memset(nbuf[0], ' ', pptw);
!     t0 = winw - pptw;
!     memset(nbuf[0] + pptw, '\0', t0 + 1);
!     strncpy(nbuf[0] + pptw, ">....", t0 > 5 ? 5 : t0);
      return winh - hwinh;
  }
  
--- 109,143 ----
  	showinglist = -2;
  }
  
+ /*
+  * Jul 96: changed to single line scroll for higher speed terminals - mason
+  *  I've seperated the loops for readability (and it's slightly faster)
+  *  Returns line number to be used next
+  */
+ 
  /**/
  int
! scrollwindow(int tline)
  {
!     int t0, hwinh;
      char *s;
  
!     if (tline || baudrate >= 9600) {	/* single line scroll */
! 	hwinh = 1;
! 	s = nbuf[tline];
! 	for (t0 = tline; t0 < winh - 1; t0++)
! 	    nbuf[t0] = nbuf[t0 + 1];
! 	nbuf[winh - 1] = s;
!     } else { 				/* half screen scroll */
! 	hwinh = winh / 2;
! 	for (t0 = 0; t0 != winh - hwinh; t0++) {
! 	    s = nbuf[t0];
! 	    nbuf[t0] = nbuf[t0 + hwinh];
! 	    nbuf[t0 + hwinh] = s;
! 	}
!     }
!     if (!tline)
! 	more_start = 1;
      return winh - hwinh;
  }
  
***************
*** 131,142 ****
  #define nextline				\
  {						\
      *s = '\0';					\
!     if (ln == winh - 1)				\
! 	if (nvln != -1)				\
  	    break;				\
! 	else					\
! 	    ln = scrollwindow(winh / 2) - 1;	\
!     if (!nbuf[++ln])				\
  	nbuf[ln] = (char *)zalloc(winw + 1);	\
      s = (unsigned char *)nbuf[ln];		\
      sen = s + winw;				\
--- 147,159 ----
  #define nextline				\
  {						\
      *s = '\0';					\
!     if (++ln == winh)				\
! 	if (nvln != -1) {			\
! 	    ln--;		/* too eager */	\
  	    break;				\
! 	} else 					\
! 	    ln = scrollwindow(0);		\
!     if (!nbuf[ln])				\
  	nbuf[ln] = (char *)zalloc(winw + 1);	\
      s = (unsigned char *)nbuf[ln];		\
      sen = s + winw;				\
***************
*** 145,162 ****
  #define snextline				\
  {						\
      *s = '\0';					\
!     if (ln == winh - 1 && tosln <= nvln + 1) {	\
! 	ln = scrollwindow(1) - 1;		\
! 	if(nvln)				\
! 	    nvln--, tosln--;			\
!     } else if(ln == winh - 1) {			\
! 	char *sav = nbuf[--tosln];		\
! 	for(t0 = tosln; t0 < winh - 1; t0++)	\
! 	    nbuf[t0] = nbuf[t0 + 1];		\
! 	nbuf[winh - 1] = sav;			\
! 	ln--;					\
!     }						\
!     if (!nbuf[++ln])				\
  	nbuf[ln] = (char *)zalloc(winw + 1);	\
      s = (unsigned char *)nbuf[ln];		\
      sen = s + winw;				\
--- 162,177 ----
  #define snextline				\
  {						\
      *s = '\0';					\
!     if (++ln == winh)				\
! 	if (tosln <= nvln + 1) {		\
! 	    ln = scrollwindow(0);		\
! 	    if (nvln)				\
! 		nvln--, tosln--;		\
! 	} else {				\
! 	    tosln--;				\
! 	    ln = scrollwindow(tosln);		\
! 	}					\
!     if (!nbuf[ln])				\
  	nbuf[ln] = (char *)zalloc(winw + 1);	\
      s = (unsigned char *)nbuf[ln];		\
      sen = s + winw;				\
***************
*** 180,190 ****
      static int inlist;		/* avoiding recursion                        */
      int ln = 0,			/* current line we're working on	     */
  	nvcs = 0, nvln = -1,	/* video cursor column and line		     */
! 	t0 = -1;		/* tmp					     */
      unsigned char *s,		/* pointer into the video buffer	     */
  	*t,			/* pointer into the real buffer		     */
  	*sen,			/* pointer to end of the video buffer (eol)  */
! 	*scs = line + cs;	/* pointer to cursor position in real buffer */
      char **qbuf;		/* tmp					     */
  
      /* If this is called from listmatches() (indirectly via trashzle()), and *
--- 195,206 ----
      static int inlist;		/* avoiding recursion                        */
      int ln = 0,			/* current line we're working on	     */
  	nvcs = 0, nvln = -1,	/* video cursor column and line		     */
! 	t0 = -1,		/* tmp					     */
! 	tosln;			/* tmp in statusline stuff		     */
      unsigned char *s,		/* pointer into the video buffer	     */
  	*t,			/* pointer into the real buffer		     */
  	*sen,			/* pointer to end of the video buffer (eol)  */
! 	*scs;			/* pointer to cursor position in real buffer */
      char **qbuf;		/* tmp					     */
  
      /* If this is called from listmatches() (indirectly via trashzle()), and *
***************
*** 198,203 ****
--- 214,221 ----
      cost = 0;			/* reset */
  #endif
      cleareol = 0;		/* unset */
+     more_start = more_end = 0;	/* unset */
+     baudrate = getiparam("BAUD");
      if (resetneeded) {
  	setterm();
  #ifdef TIOCGWINSZ
***************
*** 239,244 ****
--- 257,271 ----
  	return;
      }
  
+     if (cs < 0) {
+ #ifdef DEBUG
+ 	fprintf(stderr, "BUG: negative cursor position\n");
+ 	fflush(stderr); 
+ #endif
+ 	cs = 0;
+     }
+     scs = line + cs;
+ 
  /* first, we generate the video line buffers so we know what to put on
     the screen - also determine final cursor position (nvln, nvcs) */
  
***************
*** 284,291 ****
  	nvln++;
      }
  
      if (statusline) {
! 	int tosln = ln + 1;
  	snextline
  	t = (unsigned char *)statusline;
  	for (; t < (unsigned char *)statusline+statusll; t++) {
--- 311,321 ----
  	nvln++;
      }
  
+     if (t != line + ll)
+ 	more_end = 1;
+ 
      if (statusline) {
! 	tosln = ln + 1;
  	snextline
  	t = (unsigned char *)statusline;
  	for (; t < (unsigned char *)statusline+statusll; t++) {
***************
*** 301,313 ****
  	}
      }
  
      *s = '\0';
      nlnct = ln + 1;
      for (ln = nlnct; ln < winh; ln++)
  	zfree(nbuf[ln], winw + 1), nbuf[ln] = NULL;
  
!     /* determine whether the right-prompt exists and can fit on the screen */
!     put_rpmpt = rpptlen && (int)strlen(nbuf[0]) + rpw < winw - 1;
  
      for (ln = 0; !clearf && (ln < nlnct); ln++) {
  	/* if we have more lines than last time, clear the newly-used lines */
--- 331,361 ----
  	}
      }
  
+ /* insert <.... at end of last line if there is more text past end of screen */
+     if (more_end) {
+ 	if (!statusline)
+ 	    tosln = winh;
+ 	strncpy(nbuf[tosln - 1] + winw - 7, " <.... ", 7);
+ 	nbuf[tosln - 1][winw] = '\0';
+     }
+ 
      *s = '\0';
      nlnct = ln + 1;
      for (ln = nlnct; ln < winh; ln++)
  	zfree(nbuf[ln], winw + 1), nbuf[ln] = NULL;
  
! /* determine whether the right-prompt exists and can fit on the screen */
!     if (!more_start)
! 	put_rpmpt = rpptlen && (int)strlen(nbuf[0]) + rpw < winw - 1;
!     else {
! /* insert >.... on first line if there is more text before start of screen */
! 	memset(nbuf[0], ' ', pptw);
! 	t0 = winw - pptw;
! 	t0 = t0 > 5 ? 5 : t0;
! 	strncpy(nbuf[0] + pptw, ">....", t0);
! 	memset(nbuf[0] + pptw + t0, ' ', winw - t0 - pptw);
! 	nbuf[0][winw] = '\0';
!     }
  
      for (ln = 0; !clearf && (ln < nlnct); ln++) {
  	/* if we have more lines than last time, clear the newly-used lines */
***************
*** 811,816 ****
--- 859,872 ----
  	else if (icntrl(line[t0]))
  	    vsiz++;
      vbuf = (char *)zalloc(vsiz);
+ 
+     if (cs < 0) {
+ #ifdef DEBUG
+ 	fprintf(stderr, "BUG: negative cursor position\n");
+ 	fflush(stderr); 
+ #endif
+ 	cs = 0;
+     }
  
      memcpy(vbuf, lpptbuf + lpptlen - pptw, pptw); /* only use last part of prompt */
      vbuf[pptw] = '\0';



-- 
Mason [G.C.W]  mason@xxxxxxxxxxxxxxxxxx    "Hurt...Agony...Pain...LOVE-IT"




Messages sorted by: Reverse Date, Date, Thread, Author