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

PATCH: EOF && use 'exit' to exit

If you try ^D at the command line you might see something like:

zsh: u
zsh: use 'exit' to exit.

with the cursor in the middle.  This appeared as a result of a change to
trashzle() so I could use it more easily from elsewhere.  However,
closer investigation reveals that change is OK and it's simply uncovered
an existing bug.

Before, this happened:
- zle printed the 'exit' message
- zle was trashed
- zle tried to return to the line with the prompt (if ALWAYSLASTPROMPT
was set)
- zle was trashed again: this put the cursor back on the line below the
prompt, which it shouldn't because zle was already in the trashed state
- zle returned to the main shell
- eventually, at top level, the main shell looked to see if it should
- it printed the 'exit' message again; this overwrote the previous one.
- the new prompt was printed immediately below that as if that had
always been the intention.

Without the bogus additional trash, both messages are printed and zle
gets confused.

The fix, I think, is not to print the message from the main shell if it
was handled by zle.  It's always been a bit mysterious to me how this
worked without any signalling between the two; apparently it didn't, at
least not recently.

After looking at all the layers between zle and the top-level loop, the
only clean way of doing that looked like a flag.  A cleaner interface
between zle and the main shell would help, but that's another of those
big jobs.

The result is that ALWAYS_LAST_PROMPT is now respected if the message is
printed by zle, which was the intention.

Index: Src/init.c
RCS file: /cvsroot/zsh/zsh/Src/init.c,v
retrieving revision 1.67
diff -u -r1.67 init.c
--- Src/init.c	10 Sep 2006 15:24:27 -0000	1.67
+++ Src/init.c	17 Sep 2006 17:30:16 -0000
@@ -1245,6 +1245,13 @@
+ * Used by zle to indicate it has already printed a "use 'exit' to exit"
+ * message.
+ */
+mod_export int use_exit_printed;
  * This is real main entry point. This has to be mod_export'ed
  * so zsh.exe can found it on Cygwin
@@ -1313,6 +1320,7 @@
     for (;;) {
+	use_exit_printed = 0;
 	 * See if we can free up some of jobtab.
 	 * We only do this at top level, because if we are
@@ -1343,7 +1351,13 @@
 	    stopmsg = 1;
 	    zexit(lastval, 0);
-	zerrnam("zsh", (!islogin) ? "use 'exit' to exit."
-		: "use 'logout' to logout.");
+	/*
+	 * Don't print the message if it was already handled by
+	 * zle, since that makes special arrangements to keep
+	 * the display tidy.
+	 */
+	if (!use_exit_printed)
+	    zerrnam("zsh", (!islogin) ? "use 'exit' to exit."
+		    : "use 'logout' to logout.");
Index: Src/Zle/zle_main.c
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_main.c,v
retrieving revision 1.90
diff -u -r1.90 zle_main.c
--- Src/Zle/zle_main.c	10 Sep 2006 15:24:28 -0000	1.90
+++ Src/Zle/zle_main.c	17 Sep 2006 17:30:16 -0000
@@ -1232,6 +1232,7 @@
 	    !zlell && isfirstln && (zlereadflags & ZLRF_IGNOREEOF)) {
 	    showmsg((!islogin) ? "zsh: use 'exit' to exit." :
 		    "zsh: use 'logout' to logout.");
+	    use_exit_printed = 1;
 	    eofsent = 1;
 	    ret = 1;
 	} else {

Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/

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