zsh-workers
 help / color / mirror / code / Atom feed
From: Wayne Davison <wayned@users.sourceforge.net>
To: Peter Stephenson <pws@csr.com>
Cc: Zsh hackers list <zsh-workers@sunsite.dk>
Subject: Re: PATCH: PROMPT_SP
Date: Mon, 18 Jul 2005 11:13:30 -0700	[thread overview]
Message-ID: <20050718181330.GA19066@blorf.net> (raw)
In-Reply-To: <200507181032.j6IAWB4q022520@news01.csr.com>

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


  reply	other threads:[~2005-07-18 18:13 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-14 18:25 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 [this message]
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

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=20050718181330.GA19066@blorf.net \
    --to=wayned@users.sourceforge.net \
    --cc=pws@csr.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).