zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: PROMPT_SP
@ 2005-07-14 18:25 Wayne Davison
  2005-07-15 17:55 ` Wayne Davison
  0 siblings, 1 reply; 13+ messages in thread
From: Wayne Davison @ 2005-07-14 18:25 UTC (permalink / raw)
  To: zsh-workers

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

I've been doing some work on this new option I'm suggesting.  The
current name I'm leaning towards is PROMPT_SP, so that's what this
patch implements.  Please feel free to comment about this or suggest
a better name.

The patch was also changed to try to output fewer characters, and also
to try to prevent mouse selection from joining a partial line with the
prompt line that follows it (resulting in a lot of spaces being copied
to the clipboard).  So, this patch uses TCMULTRIGHT or TCRIGHT (when
available) to get to (or near) the right margin, outputs 2 spaces (which
might induce a wrap), and then (if save- and restore-cursor are there),
it outputs two backspaces and either tries to clear-to-EOL or to delete
a character before restoring the cursor position.

In my testing, as long as the cursor ends up on the previous line by the
backspaces, both xterm and konsole fix the selection problem using
either clear-to-EOL or delete-char.  However, the only way I currently
know of to enable a wrappable left margin is to run zsh under screen, so
suggestions are welcomed as to how to enable a soft left margin in a
modern day terminal emulator.

One thing I added while I was adding support for looking up the save-
and restore-cursor escapes was a lookup for the backspace character
("bc" is only supposed to be set if the "bs" flag is not set, but I just
made the code always look up "bc" and default the value to "\b" if it
wasn't found).  Since some other parts of zsh use literal \b characters,
this might be overkill and it is debatable if we really need it.

This patch is based on the CVS version, not my prior patch.

..wayne..

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

--- Doc/Zsh/options.yo	18 Mar 2005 22:40:17 -0000	1.37
+++ Doc/Zsh/options.yo	14 Jul 2005 17:49:54 -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_SP)
+cindex(prompt, save partial lines)
+item(tt(PROMPT_SP) (tt(PLUS()V)) <D>)(
+Attempt to preserve any partially-output line (i.e. a line 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	14 Jul 2005 17:49:55 -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 */
 
@@ -518,7 +518,7 @@ static char *tccapnams[TC_COUNT] = {
     "cl", "le", "LE", "nd", "RI", "up", "UP", "do",
     "DO", "dc", "DC", "ic", "IC", "cd", "ce", "al", "dl", "ta",
     "md", "so", "us", "me", "se", "ue", "ch",
-    "ku", "kd", "kl", "kr"
+    "ku", "kd", "kl", "kr", "sc", "rc", "bc"
 };
 
 /* Initialise termcap */
@@ -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");
@@ -587,10 +588,22 @@ init_term(void)
 	    termflags |= TERM_NOUP;
 	}
 
-	/* if there's no termcap entry for cursor left, use \b. */
+	/* most termcaps don't define "bc" because they use \b. */
+	if (!tccan(TCBACKSPACE)) {
+	    tcstr[TCBACKSPACE] = ztrdup("\b");
+	    tclen[TCBACKSPACE] = 1;
+	}
+
+	/* if there's no termcap entry for cursor left, use backspace. */
 	if (!tccan(TCLEFT)) {
-	    tcstr[TCLEFT] = ztrdup("\b");
-	    tclen[TCLEFT] = 1;
+	    tcstr[TCLEFT] = tcstr[TCBACKSPACE];
+	    tclen[TCLEFT] = tclen[TCBACKSPACE];
+	}
+
+	if (tccan(TCSAVECURSOR) && !tccan(TCRESTRCURSOR)) {
+	    tclen[TCSAVECURSOR] = 0;
+	    zsfree(tcstr[TCSAVECURSOR]);
+	    tcstr[TCSAVECURSOR] = NULL;
 	}
 
 	/* if the termcap entry for down is \n, don't use it. */
--- Src/options.c	18 Mar 2005 22:40:26 -0000	1.22
+++ Src/options.c	14 Jul 2005 17:49:55 -0000
@@ -181,6 +181,7 @@ static struct optname optns[] = {
 {NULL, "promptbang",	      OPT_KSH,			 PROMPTBANG},
 {NULL, "promptcr",	      OPT_ALL,			 PROMPTCR},
 {NULL, "promptpercent",	      OPT_NONBOURNE,		 PROMPTPERCENT},
+{NULL, "promptsp",	      OPT_ALL,			 PROMPTSP},
 {NULL, "promptsubst",	      OPT_KSH,			 PROMPTSUBST},
 {NULL, "pushdignoredups",     OPT_EMULATE,		 PUSHDIGNOREDUPS},
 {NULL, "pushdminus",	      OPT_EMULATE,		 PUSHDMINUS},
--- Src/zsh.h	1 Jun 2005 10:45:42 -0000	1.74
+++ Src/zsh.h	14 Jul 2005 17:49:55 -0000
@@ -1594,6 +1594,7 @@ enum {
     PROMPTBANG,
     PROMPTCR,
     PROMPTPERCENT,
+    PROMPTSP,
     PROMPTSUBST,
     PUSHDIGNOREDUPS,
     PUSHDMINUS,
@@ -1716,7 +1717,10 @@ struct ttyinfo {
 #define TCDOWNCURSOR   26
 #define TCLEFTCURSOR   27
 #define TCRIGHTCURSOR  28
-#define TC_COUNT       29
+#define TCSAVECURSOR   29
+#define TCRESTRCURSOR  30
+#define TCBACKSPACE    31
+#define TC_COUNT       32
 
 #define tccan(X) (tclen[X])
 
--- Src/Zle/zle_main.c	8 Apr 2005 16:58:21 -0000	1.68
+++ Src/Zle/zle_main.c	14 Jul 2005 17:49:56 -0000
@@ -962,8 +962,30 @@ zleread(char **lp, char **rp, int flags,
 	}
     }
     initundo();
-    if (isset(PROMPTCR))
+    if (isset(PROMPTCR)) {
+	/* The PROMPT_SP heuristic will move 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(PROMPTSP)) {
+	    if (hasxn) /* w/o this, a delayed wrap might be lost by TCRIGHT */
+		putc(' ', shout);
+	    if (tccan(TCSAVECURSOR)
+	     && tcmultout(TCRIGHT, TCMULTRIGHT, columns - 3)) {
+		putc(' ', shout);
+		putc(' ', shout);
+		tcout(TCSAVECURSOR);
+		tcout(TCBACKSPACE);
+		tcout(TCBACKSPACE);
+		if (tccan(TCCLEAREOL))
+		    tcout(TCCLEAREOL);
+		else
+		    tcmultout(TCDEL, TCMULTDEL, 1);
+		tcout(TCRESTRCURSOR);
+	    } else
+		fprintf(shout, "%*s", (int)columns - 1, "");
+	}
 	putc('\r', shout);
+    }
     if (tmout)
 	alarm(tmout);
     zleactive = 1;

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: PATCH: PROMPT_SP
  2005-07-14 18:25 PATCH: PROMPT_SP Wayne Davison
@ 2005-07-15 17:55 ` Wayne Davison
  2005-07-16 16:06   ` Bart Schaefer
  0 siblings, 1 reply; 13+ messages in thread
From: Wayne Davison @ 2005-07-15 17:55 UTC (permalink / raw)
  To: zsh-workers

I went ahead and checked in the new PROMPT_SP option, including some
improved documentation beyond what was present in my last email.  Please
feel free to comment on my implementation and suggest any improvements
you might think of.

..wayne..


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: PATCH: PROMPT_SP
  2005-07-15 17:55 ` Wayne Davison
@ 2005-07-16 16:06   ` Bart Schaefer
  2005-07-16 19:56     ` Wayne Davison
  0 siblings, 1 reply; 13+ messages in thread
From: Bart Schaefer @ 2005-07-16 16:06 UTC (permalink / raw)
  To: zsh-workers

On Jul 15, 10:55am, Wayne Davison wrote:
} Subject: Re: PATCH: PROMPT_SP
}
} feel free to comment on my implementation and suggest any improvements
} you might think of.

As I expected, prompt_bart_setup is messed up by this and will have to
be adjusted again.  This is actually a bit annoying, because it's not
possible to test [[ -o promptsp ]] in an older version without causing
an error (as opposed to a nonzero status) so it's ugly to deal with in
a version-independent way.  I ended up with

    eval '[[ -o promptsp ]] 2>/dev/null'

Otherwise it seems to be working nicely.

An obvious documentation error:

 PROMPT_CR (+V) <D>
     Print a carriage return just before printing a prompt [...]

 PROMPT_SP (+V) <D>
     Attempt to preserve a partial line [...]

The +V command-line option doesn't really control both PROMPT_CR and
PROMPT_SP, does it?


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: PATCH: PROMPT_SP
  2005-07-16 16:06   ` Bart Schaefer
@ 2005-07-16 19:56     ` Wayne Davison
  2005-07-18 10:32       ` Peter Stephenson
  0 siblings, 1 reply; 13+ messages in thread
From: Wayne Davison @ 2005-07-16 19:56 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-workers

On Sat, Jul 16, 2005 at 04:06:34PM +0000, Bart Schaefer wrote:
> The +V command-line option doesn't really control both PROMPT_CR and
> PROMPT_SP, does it?

Correct -- that was left over from my initial copy-paste.  I've checked
in a fix.  Thanks,

..wayne..


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: PATCH: PROMPT_SP
  2005-07-16 19:56     ` Wayne Davison
@ 2005-07-18 10:32       ` Peter Stephenson
  2005-07-18 18:13         ` Wayne Davison
  0 siblings, 1 reply; 13+ messages in thread
From: Peter Stephenson @ 2005-07-18 10:32 UTC (permalink / raw)
  To: Zsh hackers list

Here's an update to the FAQ entry.

Index: Etc/FAQ.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Etc/FAQ.yo,v
retrieving revision 1.18
diff -u -r1.18 FAQ.yo
--- Etc/FAQ.yo	17 May 2005 01:24:24 -0000	1.18
+++ Etc/FAQ.yo	18 Jul 2005 10:31:10 -0000
@@ -43,11 +43,11 @@
 whenman(report(ARG1)(ARG2)(ARG3))\
 whenms(report(ARG1)(ARG2)(ARG3))\
 whensgml(report(ARG1)(ARG2)(ARG3)))
-myreport(Z-Shell Frequently-Asked Questions)(Peter Stephenson)(2005/01/11)
+myreport(Z-Shell Frequently-Asked Questions)(Peter Stephenson)(2005/07/18)
 COMMENT(-- the following are for Usenet and must appear first)\
 description(\
 mydit(Archive-Name:) unix-faq/shell/zsh
-mydit(Last-Modified:) 2005/01/11
+mydit(Last-Modified:) 2005/07/18
 mydit(Submitted-By:) email(pws@pwstephenson.fsnet.co.uk (Peter Stephenson))
 mydit(Posting-Frequency:) Monthly
 mydit(Copyright:) (C) P.W. Stephenson, 1995--2005 (see end of document)
@@ -1671,6 +1671,11 @@
   One final alternative is to put a newline in your prompt -- see question
   link(3.13)(313) for that.
 
+  Version 3.0 of zsh includes a workaround: if the tt(PROMPT_SP) option
+  is set, as it is by default, the shell will try to move the cursor to the
+  start of the next screen line.  This requires some support from the
+  terminal which is available in most recent terminal emulators.
+
 
 sect(What's wrong with cut and paste on my xterm?)
 

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

**********************************************************************


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: PATCH: PROMPT_SP
  2005-07-18 10:32       ` Peter Stephenson
@ 2005-07-18 18:13         ` Wayne Davison
  2005-07-23 13:55           ` Bart Schaefer
  0 siblings, 1 reply; 13+ messages in thread
From: Wayne Davison @ 2005-07-18 18:13 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh hackers list

On Mon, Jul 18, 2005 at 11:32:11AM +0100, Peter Stephenson wrote:
> Here's an update to the FAQ entry.

Good idea.  I think it might be better to do a bigger rewrite, though,
so that we indicate early on that this FAQ entry's problem is largely
solved by PROMPT_SP.

What do you think of the following?  (Hopefully my improved precmd
function is not too complex.)

--- Etc/FAQ.yo	18 Jul 2005 14:54:11 -0000	1.20
+++ Etc/FAQ.yo	18 Jul 2005 18:03:36 -0000
@@ -1640,43 +1640,49 @@
 
 sect(How do I prevent the prompt overwriting output when there is no newline?)
 
-  The problem is, for example,
+  The problem is normally limited to zsh versions prior to 4.3.0 due to the
+  advent of the PROMPT_SP option (which is enabled by default, and eliminates
+  this problem for most terminals).  An example of the overwriting is:
   verb(
     % echo -n foo
     % 
   )
-  and the tt(foo) has been overwritten by the prompt tt(%).  The reason this
-  happens is that the option tt(PROMPT_CR) is enabled by default, and it
-  outputs a carriage return before the prompt in order to ensure that the
-  line editor knows what column it is in (this is needed to position the
-  right-side prompt correctly (mytt($RPROMPT), mytt($RPS1)) and to avoid screen
-  corruption when performing line editing).  If you add tt(unsetopt promptcr)
-  to your tt(.zshrc), you will see any partial output, but your screen may
-  look weird until you press return or refresh the screen.
-
-  Another solution for many terminals is to define a precmd function that
-  outputs a screen-width of spaces, like this:
-  verb(
-    function precmd {
-      echo -n ${(l:$COLUMNS:::):-}
-    }
-  )
-  (Explanation: an empty parameter expansion is padded out to the number of
-  columns on the screen.)  That precmd function will only bump the screen
-  down to a new line if there was output on the prompt line, otherwise the
-  extra spaces get removed by the tt(PROMPT_CR) action.  Although this
-  typically looks fine it may result in the preceding spaces being included
-  when you select a line of text with the mouse.
+  This shows a case where the word tt(foo) was output without a newline, and
+  then overwritten by the prompt line tt(%).  The reason this happens is that
+  the option tt(PROMPT_CR) is enabled by default, and it outputs a carriage
+  return before the prompt in order to ensure that the line editor knows what
+  column it is in (this is needed to position the right-side prompt correctly
+  (mytt($RPROMPT), mytt($RPS1)) and to avoid screen corruption when performing
+  line editing).  If you add tt(unsetopt promptcr) to your tt(.zshrc), you
+  will see any partial output, but your screen may look weird until you press
+  return or refresh the screen.
+
+  A better solution than disabling PROMPT_CR (for most terminals) is adding
+  a simpler version of the PROMPT_SP functionality to an older zsh using a
+  custom precmd function, like this one:
+  verb(
+    # Skip defining precmd if the PROMPT_SP option is available.
+    if ! eval '[[ -o promptsp ]] 2>/dev/null'; then
+      function precmd {
+        # An efficient version using termcap multi-right:
+        echo -n ' '       # Output 1 space
+        echotc RI $((COLUMNS - 3))
+        echo -n '  '      # Output 2 spaces
+        # Alternately, try replacing the above 3 lines with this echo
+        # that outputs a screen-column-width of spaces:
+        #echo -n ${(l:$COLUMNS:::):-}
+      }
+    fi
+  )
+  That precmd function will only bump the screen down to a new line if there
+  was output on the prompt line, otherwise the extra spaces get removed by
+  the tt(PROMPT_CR) action.  Although this typically looks fine it may result
+  in the preceding spaces being included when you select a line of text with
+  the mouse.
 
   One final alternative is to put a newline in your prompt -- see question
   link(3.13)(313) for that.
 
-  Version 3.0 of zsh includes a workaround: if the tt(PROMPT_SP) option
-  is set, as it is by default, the shell will try to move the cursor to the
-  start of the next screen line.  This requires some support from the
-  terminal which is available in most recent terminal emulators.
-
-
 sect(What's wrong with cut and paste on my xterm?)
 
   On the majority of modern UNIX systems, cutting text from one window and

..wayne..


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: PATCH: PROMPT_SP
  2005-07-18 18:13         ` Wayne Davison
@ 2005-07-23 13:55           ` Bart Schaefer
  2005-07-23 16:53             ` Wayne Davison
  0 siblings, 1 reply; 13+ messages in thread
From: Bart Schaefer @ 2005-07-23 13:55 UTC (permalink / raw)
  To: Zsh hackers list

On Jul 18, 11:13am, Wayne Davison wrote:
}
} What do you think of the following?  (Hopefully my improved precmd
} function is not too complex.)

The echotc command now requires the termcap module ... I can't decide
whether I'm more concerned that (1) the module won't be available, or
that (2) the RI capability won't be.  However, neither concern is very
serious.

Reading this ...

} +  The problem is normally limited to zsh versions prior to 4.3.0 due to the
} +  advent of the PROMPT_SP option (which is enabled by default, and eliminates
} +  this problem for most terminals).  An example of the overwriting is:
}    verb(
}      % echo -n foo
}      % 
}    )

... I've begun to wonder whether we're only replacing one complaint ("the
prompt overwrites my output") with another ("'echo -n' doesn't work, I
always get a newline").


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: PATCH: PROMPT_SP
  2005-07-23 13:55           ` Bart Schaefer
@ 2005-07-23 16:53             ` Wayne Davison
  2005-07-23 17:19               ` Wayne Davison
  0 siblings, 1 reply; 13+ messages in thread
From: Wayne Davison @ 2005-07-23 16:53 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh hackers list

On Sat, Jul 23, 2005 at 01:55:54PM +0000, Bart Schaefer wrote:
> The echotc command now requires the termcap module ... I can't decide
> whether I'm more concerned that (1) the module won't be available, or
> that (2) the RI capability won't be.  However, neither concern is very
> serious.

And I do still give the simpler 1-echo alternative for those that can't
use the 3-echo version.  There's probably even be a way to code up a
check for the termcap module and the RI capability, but that seems like
overkill to me.

> ... I've begun to wonder whether we're only replacing one complaint ("the
> prompt overwrites my output") with another ("'echo -n' doesn't work, I
> always get a newline").

Interesting!  One way to deal with that would be to output some
characters other than spaces that would only become visible when zsh
makes a partial line visible.  For instance:

	echotc so
	echo -n '[EOL]'
	echotc se
	echotc RI $((COLUMNS - 7))
	echo -n '  '

That puts a standout-string "[EOL]" at the end of the output.  I like
the extra indication that the output did not end with a newline.  What
do you think?

..wayne..


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: PATCH: PROMPT_SP
  2005-07-23 16:53             ` Wayne Davison
@ 2005-07-23 17:19               ` Wayne Davison
  2005-07-24  5:27                 ` Bart Schaefer
  0 siblings, 1 reply; 13+ messages in thread
From: Wayne Davison @ 2005-07-23 17:19 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh hackers list

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

On Sat, Jul 23, 2005 at 09:53:01AM -0700, Wayne Davison wrote:
> That puts a standout-string "[EOL]" at the end of the output.

Here's a potential patch for FAQ.yo if folks like the idea.  I
made the text bold too (if possible) and switched to using print
with prompt expansion.

..wayne..

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

--- Etc/FAQ.yo	19 Jul 2005 15:18:11 -0000	1.22
+++ Etc/FAQ.yo	23 Jul 2005 17:16:34 -0000
@@ -1664,13 +1664,13 @@ sect(How do I prevent the prompt overwri
     # Skip defining precmd if the PROMPT_SP option is available.
     if ! eval '[[ -o promptsp ]] 2>/dev/null'; then
       function precmd {
+        print -nP '%B%S[EOL]%s%b'
         # An efficient version using termcap multi-right:
-        echo -n ' '       # Output 1 space
-        echotc RI $((COLUMNS - 3))
+        echotc RI $((COLUMNS - 7))
         echo -n '  '      # Output 2 spaces
-        # Alternately, try replacing the above 3 lines with this echo
-        # that outputs a screen-column-width of spaces:
-        #echo -n ${(l:$COLUMNS:::):-}
+        # Alternately, try replacing the above 2 lines with this echo
+        # that pads the line with spaces:
+        #echo -n ${(l:$((COLUMNS-5)):::):-}
       }
     fi
   )

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: PATCH: PROMPT_SP
  2005-07-23 17:19               ` Wayne Davison
@ 2005-07-24  5:27                 ` Bart Schaefer
  2005-07-24  6:10                   ` Wayne Davison
  0 siblings, 1 reply; 13+ messages in thread
From: Bart Schaefer @ 2005-07-24  5:27 UTC (permalink / raw)
  To: Zsh hackers list

On Jul 23,  9:53am, Wayne Davison wrote:
} Subject: Re: PATCH: PROMPT_SP
}
} One way to deal with that would be to output some
} characters other than spaces that would only become visible when zsh
} makes a partial line visible.

What happens when THOSE characters cause the line to wrap?  You don't
know how many RI to emit (COLUMNS-7 is definitely wrong in your
example).  You can only do this right if you manage to do it with a
single character.

} Subject: Re: PATCH: PROMPT_SP
}
} I made the text bold too (if possible) and switched to using print
} with prompt expansion.

I was going to suggest that.  Perhaps '%B%S$%s%b' would do it, as long
as the user doesn't have promptsubst set; hrm.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: PATCH: PROMPT_SP
  2005-07-24  5:27                 ` Bart Schaefer
@ 2005-07-24  6:10                   ` Wayne Davison
  2005-07-24  9:49                     ` Bart Schaefer
  0 siblings, 1 reply; 13+ messages in thread
From: Wayne Davison @ 2005-07-24  6:10 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh hackers list

On Sun, Jul 24, 2005 at 05:27:57AM +0000, Bart Schaefer wrote:
> What happens when THOSE characters cause the line to wrap?

Then you only see as much of the [EOL] string as would fit on the line
before the prompt (I had already tested that, and it seemed like a
reasonable enough behavior).  I had originally thought to use just an
inverse ~ (kind of like the EOF indicator in vi/vim/less), but I thought
that the [EOL] string might be clearer.  But perhaps ~EOL~ would be
better (which would degrade to a single ~ if nothing else fits).

> You don't know how many RI to emit (COLUMNS-7 is definitely wrong in
> your example).

I don't follow this logic -- the code I posted works as expected (since
the RI sequence is preceded by 5 characters and followed by 2 spaces).
Perhaps you mean only in the case where the "[EOL]" wraps to the
following line?

..wayne..


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: PATCH: PROMPT_SP
  2005-07-24  6:10                   ` Wayne Davison
@ 2005-07-24  9:49                     ` Bart Schaefer
  2005-07-26 21:53                       ` Wayne Davison
  0 siblings, 1 reply; 13+ messages in thread
From: Bart Schaefer @ 2005-07-24  9:49 UTC (permalink / raw)
  To: Zsh hackers list

On Jul 23, 11:10pm, Wayne Davison wrote:
} Subject: Re: PATCH: PROMPT_SP
}
} On Sun, Jul 24, 2005 at 05:27:57AM +0000, Bart Schaefer wrote:
} > What happens when THOSE characters cause the line to wrap?
} 
} Then you only see as much of the [EOL] string as would fit on the line

Ah.  I had assumed you'd never want to cover up any part of the [EOL]
string unless you were covering up the entire thing.  The rest of my
comments followed from that assumption.

} [...] perhaps ~EOL~ would be
} better (which would degrade to a single ~ if nothing else fits).

What I find mildly distasteful are the ~E and ~EO cases.

How about '%B%S%#%s%b' ?


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: PATCH: PROMPT_SP
  2005-07-24  9:49                     ` Bart Schaefer
@ 2005-07-26 21:53                       ` Wayne Davison
  0 siblings, 0 replies; 13+ messages in thread
From: Wayne Davison @ 2005-07-26 21:53 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh hackers list

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

On Sun, Jul 24, 2005 at 09:49:38AM +0000, Bart Schaefer wrote:
> How about '%B%S%#%s%b' ?

I've been using this suggestion for a couple days, and happened to
notice that sometimes some user-input would echo between the precmd
output and the PROMPT_CR output (causing a confusing wrap with the #
in column 1), so I added a CR to the end of the precmd's output.  I
also simplified the code a bit (i.e. no more termcap RI).

..wayne..

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

--- FAQ.yo	19 Jul 2005 15:18:11 -0000	1.22
+++ FAQ.yo	26 Jul 2005 18:46:36 -0000
@@ -1664,13 +1664,10 @@ sect(How do I prevent the prompt overwri
     # Skip defining precmd if the PROMPT_SP option is available.
     if ! eval '[[ -o promptsp ]] 2>/dev/null'; then
       function precmd {
-        # An efficient version using termcap multi-right:
-        echo -n ' '       # Output 1 space
-        echotc RI $((COLUMNS - 3))
-        echo -n '  '      # Output 2 spaces
-        # Alternately, try replacing the above 3 lines with this echo
-        # that outputs a screen-column-width of spaces:
-        #echo -n ${(l:$COLUMNS:::):-}
+        # Output an inverse hash and a bunch spaces.  We include
+        # a CR at the end so that any user-input that gets echoed
+        # between this output and the prompt doesn't cause a wrap.
+        print -nP "%B%S#%s%b${(l:$((COLUMNS-1)):::):-}\r"
       }
     fi
   )

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2005-07-26 21:54 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-14 18:25 PATCH: PROMPT_SP Wayne Davison
2005-07-15 17:55 ` Wayne Davison
2005-07-16 16:06   ` Bart Schaefer
2005-07-16 19:56     ` Wayne Davison
2005-07-18 10:32       ` Peter Stephenson
2005-07-18 18:13         ` Wayne Davison
2005-07-23 13:55           ` Bart Schaefer
2005-07-23 16:53             ` Wayne Davison
2005-07-23 17:19               ` Wayne Davison
2005-07-24  5:27                 ` Bart Schaefer
2005-07-24  6:10                   ` Wayne Davison
2005-07-24  9:49                     ` Bart Schaefer
2005-07-26 21:53                       ` Wayne Davison

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).