Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Prompt erases line
- X-seq: zsh-users 4478
- From: Deborah Ariel Pickett <debbiep@xxxxxxxxxxxxxxxxxxxxxxx>
- To: lewang@xxxxxxxxx (Le Wang)
- Subject: Re: Prompt erases line
- Date: Fri, 16 Nov 2001 10:07:39 +1100 (EST)
- Cc: zsh-users@xxxxxxxxxx (Zsh-users List)
- In-reply-to: <20011115224905.67345.qmail@xxxxxxxxxxxxxxxxxxxxxxx> from "Le Wang" at Nov 15, 2001 05:49:05 PM
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
> 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@xxxxxxxxxx> 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@xxxxxxxxxxxxxxxxxx
If I throw a stick, will you leave? - button slogan
Messages sorted by:
Reverse Date,
Date,
Thread,
Author