zsh-users
 help / color / mirror / code / Atom feed
From: Deborah Ariel Pickett <debbiep@mail.csse.monash.edu.au>
To: lewang@yahoo.com (Le Wang)
Cc: zsh-users@sunsite.dk (Zsh-users List)
Subject: Re: Prompt erases line
Date: Fri, 16 Nov 2001 10:07:39 +1100 (EST)	[thread overview]
Message-ID: <200111152307.fAFN7dc27614@bruce.csse.monash.edu.au> (raw)
In-Reply-To: <20011115224905.67345.qmail@web12301.mail.yahoo.com> from "Le Wang" at Nov 15, 2001 05:49:05 PM

> The zsh propmpt always seem to erase the line if the
> line does not end in a "\n"
> -----
> lewang@phobe ~ % echo asdf
> asdf
> lewang@phobe ~ % echo -n adsf
> lewang@phobe ~ %
> -----
> Is there any way to get it to just print the prompt
> after the text on the same line?

unsetopt PROMPT_CR

This is assuming that you don't have a carriage return character in your
PS1 shell variable.

Put it in your $HOME/.zshrc file if you want it to behave that way every
time you start a shell.

Be aware that unsetting PROMPT_CR can cause some unusual behaviour with
the zle editor, because it has no way of knowing how many characters
have already been printed on the line before the prompt.

<digression>

On an aside, I used to have the following code in my precmd function,
which would detect if the cursor wasn't up against the left edge of the
screen using an xterm/VT100 escape sequence.  If the cursor wasn't in
the first column, the precmd function would print a message and arrange
for the prompt to be printed anew on the line below.

It was a cute feature, but I've since disabled it because it was too
slow to use seriously, and timing issues meant that it didn't always
work across a slow (dialup) connection.  It would have worked a bit
quicker if the "STTY='opts' command" trick worked on the print/read
combination in the middle of the report-cursor-position function (thus
removing two fork/execs to the external stty command), but I couldn't
make it work.

Besides, the whole thing was pretty useless, to be honest.

To use it, set PROMPTCURSORPOS to a number such as 10.  This is the
number of milliseconds the function waits for a response from the
terminal driver.


# report-cursor-position
# Returns the horizontal cursor position for xterms and other terminals.
# The returned number is zero-origin, so a "successful" (in shell terms)
# return means the cursor is at the left edge of the screen.
#
# This code is lifted from an example in the xterm FAQ
# written by Icarus Sparry <icarus@bath.ac.uk> 11 Apr 1997
# and modified to use a different control sequence.

report-cursor-position()
{
  
  local old a
  
  if [[ $TERM = xterm* ]]
  then
    # Send the terminal the code and wait for its response.
    exec </dev/tty
    old=$(stty -g)
    stty raw -echo min 0  time ${1-10}
    print -n "\e[6n" > /dev/tty
    IFS='' read -r a
    stty $old
  
    a=${${a##*;}%%R*}
    return $(( $a - 1 ))
  fi
}

precmd()
{
# .... other stuff ...
  # Check the cursor position - is it up against the left margin?
  # This can be kind of slow, so we only do it if a shell variable is
  # set (which it isn't by default - see below).
  if [[ ${+PROMPTCURSORPOS} -eq 1 ]]
  then
    # This function works on xterms and other assorted terminals
    # by querying the terminal for its cursor position.  It returns zero
    # if the cursor is in the leftmost position, nonzero otherwise.
    if ! report-cursor-position $PROMPTCURSORPOS
    then
      print "[no newline]"
    fi
  fi
# .... other stuff ...
}

</digression>

-- 
Debbie Pickett http://www.csse.monash.edu.au/~debbiep debbiep@csse.monash.edu.au
              If I throw a stick, will you leave? - button slogan


      reply	other threads:[~2001-11-15 23:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-11-15 22:49 Le Wang
2001-11-15 23:07 ` Deborah Ariel Pickett [this message]

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=200111152307.fAFN7dc27614@bruce.csse.monash.edu.au \
    --to=debbiep@mail.csse.monash.edu.au \
    --cc=lewang@yahoo.com \
    --cc=zsh-users@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).