From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21087 invoked from network); 3 Nov 2000 11:10:00 -0000 Received: from sunsite.dk (HELO sunsite.auc.dk) (130.225.51.30) by ns1.primenet.com.au with SMTP; 3 Nov 2000 11:10:00 -0000 Received: (qmail 25618 invoked by alias); 3 Nov 2000 11:09:54 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 13111 Received: (qmail 25611 invoked from network); 3 Nov 2000 11:09:53 -0000 Date: Fri, 03 Nov 2000 11:09:25 +0000 From: Peter Stephenson Subject: Re: PATCH: Polite output from traps with zle active In-reply-to: "Your message of Thu, 02 Nov 2000 17:30:42 GMT." <1001102173042.ZM19733@candle.brasslantern.com> To: zsh-workers@sunsite.auc.dk (Zsh hackers list) Message-id: <0G3G003HN4BPU3@la-la.cambridgesiliconradio.com> Content-transfer-encoding: 7BIT Bart instructed: > It's too bad that the trap writer has to call `zle -R' as well as `zle -I'. > What happens if you accidentally call only `zle -I'? > > It'd also be nice if `zle -R' and `zle -I' returned zero when zle is > active and nonzero otherwise, just as `zle' with no arguments does. This looks like it works. This is on top of everything else (still uncommitted): the signals.c hunk just about fails to conflict when any of Sven's trap work. --- Doc/Zsh/mod_zle.yo.zrt2 Fri Nov 3 10:57:42 2000 +++ Doc/Zsh/mod_zle.yo Fri Nov 3 11:02:33 2000 @@ -267,9 +267,8 @@ This command can safely be called outside user defined widgets; if zle is active, the display will be refreshed, while if zle is not active, the -command has no effect. This is useful for trap functions, which may be -called while zle is active, in order to tidy up the display on exit. -In this case there will usually be no other arguments. +command has no effect. In this case there will usually be no other +arguments. The status is zero if zle was active, else one. ) item(tt(-M) var(string))( As with the tt(-R) option, the var(string) will be displayed below the @@ -291,23 +290,24 @@ item(tt(-I))( Unusually, this option is only useful em(outside) ordinary widget functions. It invalidates the current zle display in preparation for output; usually -this will be from a trap function. As it has no effect if zle is not -active, a safe idiom for ensuring that output from traps interacts cleanly -with text being edited is: +this will be from a trap function. It has no effect if zle is not +active. When a trap exits, the shell checks to see if the display needs +restoring, hence the following will print output in such a way as not to +disturb the line being edited: example(TRAPUSR1() { # Invalidate zle display zle -I # Show output print Hello - # Refresh display - zle -R }) Note that there are better ways of manipulating the display from within zle widgets. In general, the trap function may need to test whether zle is loaded before using this method; if it is not, there is no point in loading it specially since the line editor will not be active. + +The status is zero if zle was active, else one. ) item(var(widget) tt([ -n) var(num) tt(]) tt([ -N ]) var(args) ...)( Invoke the specified widget. This can only be done when ZLE is --- Src/Zle/zle_thingy.c.zrt2 Fri Nov 3 11:00:00 2000 +++ Src/Zle/zle_thingy.c Fri Nov 3 11:00:30 2000 @@ -398,7 +398,7 @@ int sl = statusll, ocl = clearlist; if (!zleactive) - return 0; + return 1; statusline = NULL; statusll = 0; if (*args) { @@ -659,8 +659,11 @@ static int bin_zle_invalidate(char *name, char **args, char *ops, char func) { - trashzle(); - return 0; + if (zleactive) { + trashzle(); + return 0; + } else + return 1; } /*******************/ --- Src/signals.c.zrt2 Fri Nov 3 10:57:12 2000 +++ Src/signals.c Fri Nov 3 10:57:24 2000 @@ -955,6 +955,13 @@ breaks = loops; } + /* + * If zle was running while the trap was executed, see if we + * need to restore the display. + */ + if (zleactive && resetneeded) + zrefresh(); + if (*sigtr != ZSIG_IGNORED) *sigtr &= ~ZSIG_IGNORED; } -- Peter Stephenson Software Engineer Cambridge Silicon Radio, Unit 300, Science Park, Milton Road, Cambridge, CB4 0XL, UK Tel: +44 (0)1223 392070