zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.auc.dk (Zsh hackers list)
Subject: Re: PATCH: Polite output from traps with zle active
Date: Fri, 03 Nov 2000 11:09:25 +0000	[thread overview]
Message-ID: <0G3G003HN4BPU3@la-la.cambridgesiliconradio.com> (raw)
In-Reply-To: "Your message of Thu, 02 Nov 2000 17:30:42 GMT." <1001102173042.ZM19733@candle.brasslantern.com>

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 <pws@csr.com>                  Software Engineer
Cambridge Silicon Radio, Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK                          Tel: +44 (0)1223 392070


      reply	other threads:[~2000-11-03 11:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-11-02 11:20 Peter Stephenson
2000-11-02 17:30 ` Bart Schaefer
2000-11-03 11:09   ` Peter Stephenson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0G3G003HN4BPU3@la-la.cambridgesiliconradio.com \
    --to=pws@csr.com \
    --cc=zsh-workers@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).