zsh-workers
 help / color / mirror / code / Atom feed
From: Wayne Davison <wayned@users.sourceforge.net>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: zsh-workers@sunsite.dk
Subject: [PATCH] adding a new option: PROMPT_NUDGE
Date: Mon, 11 Jul 2005 22:35:09 -0700	[thread overview]
Message-ID: <20050712053509.GB10890@blorf.net> (raw)
In-Reply-To: <1050712032050.ZM26026@candle.brasslantern.com>

[-- Attachment #1: Type: text/plain, Size: 1700 bytes --]

On Tue, Jul 12, 2005 at 03:20:50AM +0000, Bart Schaefer wrote:
> it's going to cause strange behavior for anyone who already has made
> the FAQ-suggested alteration to precmd.

Yeah, but that should be a minor problem that is offset by more people
getting what they expect out of the shell by default.  I think that the
worst-case problem will be someone who needs to use the same .zshrc file
with both an older and newer zsh, but I think an easy solution for that
is to have the user tweak their .zshrc to force the new option off
(silently, in case the option isn't around) and to continue to use the
current precmd heuristic for both the old and new shells.

> I'm agnostic on whether _SPACES is the best suffix.

I'm currently thinking that the SPACES part is overly tied to the
implementation rather than what it's trying to accomplish.  How about
PROMPT_NUDGE?  That at least hints at its purpose.

> Also, it should perhaps be mutually exclusive with SINGLE_LINE_ZLE.

Perhaps, but for now I've created a trial implementation that depends on
PROMPT_CR being set (since its output would look crazy without the CR,
and anyone who has gone to the trouble to disable PROMPT_CR doesn't want
things to suddenly look wacko).  It might be better to auto-disable the
PROMPT_NUDGE option if PROMPT_CR is unset, and auto-enable PROMPT_CR if
PROMPT_NUDGE is set, but for now my code takes the easy way out and just
ignores PROMPT_NUDGE if PROMPT_CR is not set.

Attached is a patch of my first implementation.  It pays attention to
the presence of the "xn" termcap attribute to know if it should output
a full column-width of spaces (for xn terminals) or one space less (for
non-xn terminals).

..wayne..

[-- Attachment #2: nudge.patch --]
[-- Type: text/plain, Size: 2833 bytes --]

--- Doc/Zsh/options.yo	18 Mar 2005 22:40:17 -0000	1.37
+++ Doc/Zsh/options.yo	12 Jul 2005 05:26:34 -0000
@@ -906,6 +906,15 @@ Print a carriage return just before prin
 a prompt in the line editor.  This is on by default as multi-line editing
 is only possible if the editor knows where the start of the line appears.
 )
+pindex(PROMPT_NUDGE)
+cindex(prompt, nudge after partial line)
+item(tt(PROMPT_NUDGE) (tt(PLUS()V)) <D>)(
+Attempt to preserve any partially-output line (i.e. output that did not end
+with a newline) by outputting a series of spaces prior to the carriage return
+that is output by PROMPT_CR.  This only works if your terminal has automatic
+margins.  Also, if the PROMPT_CR option is not set, enabling this option will
+have no effect.  This option is on by default.
+)
 pindex(PROMPT_PERCENT)
 cindex(prompt, % expansion)
 item(tt(PROMPT_PERCENT) <C> <Z>)(
--- Src/init.c	13 Jun 2005 14:59:37 -0000	1.53
+++ Src/init.c	12 Jul 2005 05:26:34 -0000
@@ -77,7 +77,7 @@ mod_export int tclen[TC_COUNT];
 /**/
 int tclines, tccolumns;
 /**/
-mod_export int hasam;
+mod_export int hasam, hasxn;
 
 /* Pointer to read-key function from zle */
 
@@ -573,6 +573,7 @@ init_term(void)
 
 	/* check whether terminal has automargin (wraparound) capability */
 	hasam = tgetflag("am");
+	hasxn = tgetflag("xn"); /* also check for newline wraparound glitch */
 
 	tclines = tgetnum("li");
 	tccolumns = tgetnum("co");
--- Src/options.c	18 Mar 2005 22:40:26 -0000	1.22
+++ Src/options.c	12 Jul 2005 05:26:34 -0000
@@ -180,6 +180,7 @@ static struct optname optns[] = {
 {NULL, "privileged",	      OPT_SPECIAL,		 PRIVILEGED},
 {NULL, "promptbang",	      OPT_KSH,			 PROMPTBANG},
 {NULL, "promptcr",	      OPT_ALL,			 PROMPTCR},
+{NULL, "promptnudge",	      OPT_ALL,			 PROMPTNUDGE},
 {NULL, "promptpercent",	      OPT_NONBOURNE,		 PROMPTPERCENT},
 {NULL, "promptsubst",	      OPT_KSH,			 PROMPTSUBST},
 {NULL, "pushdignoredups",     OPT_EMULATE,		 PUSHDIGNOREDUPS},
--- Src/zsh.h	1 Jun 2005 10:45:42 -0000	1.74
+++ Src/zsh.h	12 Jul 2005 05:26:34 -0000
@@ -1593,6 +1593,7 @@ enum {
     PRIVILEGED,
     PROMPTBANG,
     PROMPTCR,
+    PROMPTNUDGE,
     PROMPTPERCENT,
     PROMPTSUBST,
     PUSHDIGNOREDUPS,
--- Src/Zle/zle_main.c	8 Apr 2005 16:58:21 -0000	1.68
+++ Src/Zle/zle_main.c	12 Jul 2005 05:26:35 -0000
@@ -962,8 +962,14 @@ zleread(char **lp, char **rp, int flags,
 	}
     }
     initundo();
-    if (isset(PROMPTCR))
+    if (isset(PROMPTCR)) {
+	/* The PROMPT_NUDGE heuristic will nudge the prompt down to a new line
+	 * if there was any dangling output on the line (assuming the terminal
+	 * has automatic margins, but we try even if hasam isn't set). */
+	if (isset(PROMPTNUDGE))
+	    fprintf(shout, "%*s", (int)columns - !hasxn, "");
 	putc('\r', shout);
+    }
     if (tmout)
 	alarm(tmout);
     zleactive = 1;

  reply	other threads:[~2005-07-12  5:35 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-11 14:47 Very wierd output problems Ulf Magnusson
2005-07-11 15:14 ` Travis Spencer
2005-07-11 17:40   ` Wayne Davison
2005-07-12  3:20     ` Bart Schaefer
2005-07-12  5:35       ` Wayne Davison [this message]
2005-07-12 14:19         ` [PATCH] adding a new option: PROMPT_NUDGE Bart Schaefer
2005-07-12 18:48           ` Wayne Davison
2005-07-12 19:16             ` Wayne Davison
2005-07-12 20:46           ` J

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=20050712053509.GB10890@blorf.net \
    --to=wayned@users.sourceforge.net \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-workers@sunsite.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).