zsh-workers
 help / color / mirror / code / Atom feed
* prompt and prompt_cr option
@ 2004-10-09 15:17 Jordan Breeding
  2004-10-11 22:11 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Jordan Breeding @ 2004-10-09 15:17 UTC (permalink / raw)
  To: zsh-workers

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

Hello,

I have run into the problem several times of having lines of output in 
the shell that don't have a newline and having the prompt overwrite 
them.  I did find the `setopt nopromptcr` solution but I also like 
having multiline editing always work correctly.  I thought that I would 
try and solve both problems with the following:

setopt nopromptcr
prompt='%(1l,\n,)%! %n@%m %0~ > '

but that didn't seem to do the trick.  Is there a way to force zsh to 
check to see if the last character that was printed was a newline and 
if it wasn't to just print one before it issues the carriage return?

Jordan

[-- Attachment #2: Type: text/enriched, Size: 673 bytes --]

<fontfamily><param>Courier</param><bigger>Hello,


I have run into the problem several times of having lines of output in
the shell that don't have a newline and having the prompt overwrite
them.  I did find the `setopt nopromptcr` solution but I also like
having multiline editing always work correctly.  I thought that I
would try and solve both problems with the following:


setopt nopromptcr

prompt='%(1l,\n,)%! %n@%m %0~ > '


but that didn't seem to do the trick.  Is there a way to force zsh to
check to see if the last character that was printed was a newline and
if it wasn't to just print one before it issues the carriage return?


Jordan</bigger></fontfamily>

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

* Re: prompt and prompt_cr option
  2004-10-09 15:17 prompt and prompt_cr option Jordan Breeding
@ 2004-10-11 22:11 ` Bart Schaefer
  2004-10-11 23:28   ` Danek Duvall
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2004-10-11 22:11 UTC (permalink / raw)
  To: zsh-workers; +Cc: Jordan Breeding

On Sat, 9 Oct 2004, Jordan Breeding wrote:

> Is there a way to force zsh to check to see if the last character that 
> was printed was a newline and if it wasn't to just print one before it 
> issues the carriage return?

No.  There's no way, in general, for zsh to know what characters were 
previously output to the terminal (or for any process to know what any 
other process has done with a shared device).

For certain types of terminals you might be able to query the current 
cursor position and do something clever when it is not in column zero, but 
it's been deemed more trouble than it's worth to have ZLE attempt to 
determine whether the terminal has support for this and then to make use 
of that information.  (Querying the terminal involves sending a control 
string and then reading back a response, which is unreliable because it 
can be garbled by user type-ahead or other interference.)


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

* Re: prompt and prompt_cr option
  2004-10-11 22:11 ` Bart Schaefer
@ 2004-10-11 23:28   ` Danek Duvall
  2004-10-12  1:52     ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Danek Duvall @ 2004-10-11 23:28 UTC (permalink / raw)
  To: zsh-workers; +Cc: Jordan Breeding

On Mon, Oct 11, 2004 at 03:11:43PM -0700, Bart Schaefer wrote:

> For certain types of terminals you might be able to query the current 
> cursor position and do something clever when it is not in column zero, but 
> it's been deemed more trouble than it's worth to have ZLE attempt to 
> determine whether the terminal has support for this and then to make use 
> of that information.  (Querying the terminal involves sending a control 
> string and then reading back a response, which is unreliable because it 
> can be garbled by user type-ahead or other interference.)

On the other hand, you could write a precmd function that did this and spit
out an extra newline if necessary (and set nopromptcr), no?  If so, that
might be worth adding to the Misc directory, as it's such a FAQ.

Danek


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

* Re: prompt and prompt_cr option
  2004-10-11 23:28   ` Danek Duvall
@ 2004-10-12  1:52     ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2004-10-12  1:52 UTC (permalink / raw)
  To: Danek Duvall; +Cc: zsh-workers, Jordan Breeding

On Mon, 11 Oct 2004, Danek Duvall wrote:

> On Mon, Oct 11, 2004 at 03:11:43PM -0700, Bart Schaefer wrote:
> 
> > For certain types of terminals you might be able to query the current 
> > cursor position and do something clever when it is not in column zero
> 
> On the other hand, you could write a precmd function that did this and 
> spit out an extra newline if necessary (and set nopromptcr), no?

Unfortunately it's not quite that simple.

As far as I can tell, there's no terminfo/termcap capability that defines
the "report cursor position" string.  So it can't easily be determined
whether the terminal supports it, or what to send.

If the terminal is ANSI/ECMA compliant, the query string is $'\e[6n' and 
the response is $'\e[ll;ccR' where cc and ll are the column and line 
numbers -- but if it is not ANSI then sending that string won't give any 
response (and may just garble the output further).

So the following might work, or might not.  It uses the prompt printed by
the read builtin to query the terminal and the combination of IFS and the
-d option to parse the response.

  precmd() {
    local escape colno lineno
    IFS='[;' read -s -d R escape\?$'\e[6n' lineno colno
    (( colno > 1 )) && echo ''
  }


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

end of thread, other threads:[~2004-10-12  1:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-09 15:17 prompt and prompt_cr option Jordan Breeding
2004-10-11 22:11 ` Bart Schaefer
2004-10-11 23:28   ` Danek Duvall
2004-10-12  1:52     ` Bart Schaefer

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