Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] adding a new option: PROMPT_NUDGE
- X-seq: zsh-workers 21445
- From: Wayne Davison <wayned@xxxxxxxxxxxxxxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Subject: [PATCH] adding a new option: PROMPT_NUDGE
- Date: Mon, 11 Jul 2005 22:35:09 -0700
- Cc: zsh-workers@xxxxxxxxxx
- In-reply-to: <1050712032050.ZM26026@xxxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <cf7bbda90507110747669da77b@xxxxxxxxxxxxxx> <20050711151454.GH12208@xxxxxxxxxxxxxxxx> <20050711174055.GB9294@xxxxxxxxx> <1050712032050.ZM26026@xxxxxxxxxxxxxxxxxxxxxxx>
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..
--- 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;
Messages sorted by:
Reverse Date,
Date,
Thread,
Author