* Prompt erases line
@ 2001-11-15 22:49 Le Wang
2001-11-15 23:07 ` Deborah Ariel Pickett
0 siblings, 1 reply; 2+ messages in thread
From: Le Wang @ 2001-11-15 22:49 UTC (permalink / raw)
To: Zsh-users List
Hi all,
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?
_______________________________________________________
Build your own website in minutes and for free at http://ca.geocities.com
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Prompt erases line
2001-11-15 22:49 Prompt erases line Le Wang
@ 2001-11-15 23:07 ` Deborah Ariel Pickett
0 siblings, 0 replies; 2+ messages in thread
From: Deborah Ariel Pickett @ 2001-11-15 23:07 UTC (permalink / raw)
To: Le Wang; +Cc: Zsh-users List
> 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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2001-11-15 23:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-11-15 22:49 Prompt erases line Le Wang
2001-11-15 23:07 ` Deborah Ariel Pickett
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).