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

PATCH: don't redraw when not printing job info



It turns out that zrefresh() can be triggered by the job handler when it
thinks some information has been printed, even though it hasn't.
This redraws the ZLE line including the prompt.  Usually this goes
unnoticed.  I spotted it because at the point in question there was a
function running under sched, and the last status was 1, which appeared
on the display because of the redraw (since my prompt outputs non-zero
statuses).

This patch doesn't force the redraw when there's nothing printed.  This
is a simple and safe thing to do which fixes this symptom.  However, it
would presumably be sensible for prompts to be insensitive to contextual
information from functions not explicitly run by the user.  (This is
more than just the status: suppose we were at a PS2 which output the
parse status, for example.)  That's messier and a rather special case
you don't normally see, so I haven't attempted it.

Index: Src/jobs.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/jobs.c,v
retrieving revision 1.53
diff -u -r1.53 jobs.c
--- Src/jobs.c	21 Jan 2007 22:47:41 -0000	1.53
+++ Src/jobs.c	30 Jan 2007 18:52:18 -0000
@@ -448,8 +448,8 @@
 	curjob = job;
     }
     if ((isset(NOTIFY) || job == thisjob) && (jn->stat & STAT_LOCKED)) {
-	printjob(jn, !!isset(LONGLISTJOBS), 0);
-	if (zleactive)
+	if (printjob(jn, !!isset(LONGLISTJOBS), 0) &&
+	    zleactive)
 	    zrefreshptr();
     }
     if (sigtrapped[SIGCHLD] && job != thisjob)
@@ -804,19 +804,22 @@
  * synch = 0 means asynchronous
  * synch = 1 means synchronous
  * synch = 2 means called synchronously from jobs
+ *
+ * Returns 1 if some output was done.
 */
 
 /**/
-void
+int
 printjob(Job jn, int lng, int synch)
 {
     Process pn;
     int job, len = 9, sig, sflag = 0, llen;
     int conted = 0, lineleng = columns, skip = 0, doputnl = 0;
+    int doneprint = 0;
     FILE *fout = (synch == 2) ? stdout : shout;
 
     if (jn->stat & STAT_NOPRINT)
-	return;
+	return 0;
 
     /*
      * Wow, what a hack.  Did I really write this? --- pws
@@ -874,8 +877,10 @@
 
 	if (!synch)
 	    trashzleptr();
-	if (doputnl && !synch)
+	if (doputnl && !synch) {
+	    doneprint = 1;
 	    putc('\n', fout);
+	}
 	for (pn = jn->procs; pn;) {
 	    len2 = (thisfmt ? 5 : 10) + len;	/* 2 spaces */
 	    if (lng & 3)
@@ -888,6 +893,7 @@
 			break;
 		    len2 += strlen(qn->text) + 2;
 		}
+	    doneprint = 1;
 	    if (!thisfmt || lng) {
 		if (fline)
 		    fprintf(fout, "[%ld]  %c ",
@@ -944,6 +950,7 @@
 	}
 	fflush(fout);
     } else if (doputnl && interact && !synch) {
+	doneprint = 1;
 	putc('\n', fout);
 	fflush(fout);
     }
@@ -954,6 +961,7 @@
 
     if ((lng & 4) || (interact && job == thisjob &&
 		      jn->pwd && strcmp(jn->pwd, pwd))) {
+	doneprint = 1;
 	fprintf(fout, "(pwd %s: ", (lng & 4) ? "" : "now");
 	fprintdir(((lng & 4) && jn->pwd) ? jn->pwd : pwd, fout);
 	fprintf(fout, ")\n");
@@ -973,6 +981,8 @@
 	    setprevjob();
     } else
 	jn->stat &= ~STAT_CHANGED;
+
+    return doneprint;
 }
 
 /**/

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php

To get further information regarding CSR, please visit our Investor Relations page at http://ir.csr.com/csr/about/overview



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