zsh-users
 help / color / mirror / code / Atom feed
* PROMPT escape sequences
@ 2007-10-07 10:34 Atom Smasher
  2007-10-07 17:32 ` Bart Schaefer
  0 siblings, 1 reply; 9+ messages in thread
From: Atom Smasher @ 2007-10-07 10:34 UTC (permalink / raw)
  To: zsh-users

PS1='%S%# '

that sets my prompt to reverse video, and it works fine if i tab-complete. 
but....

PS1='%{^[[36m%}%# '

that sets my prompt to cyan, but reverts to default colors when i 
tab-complete.

is there a way to set a color at the prompt that doesn't reset to default 
when i tab-complete?

thanks...


-- 
         ...atom

  ________________________
  http://atom.smasher.org/
  762A 3B98 A3C3 96C9 C6B7 582A B88D 52E4 D9F5 7808
  -------------------------------------------------

 	"Not one weapon in our vast arsenal can shield us from
 	 a nuclear weapon delivered in a sailboat or a Piper
 	 Cub or a suitcase or a Ryder rental truck. Not a
 	 penny of the 273 billion dollars a year we spend on
 	 so-called defense can actually defend us against a
 	 terrorist bomb. Nothing in our enormous military
 	 establishment can actually give us one whit of
 	 security. That is a military fact... In country
 	 after country, our government has thwarted
 	 democracy, stifled freedom, and trampled human
 	 rights. That's why we are hated around the world...
 	 We are not hated because we practice democracy,
 	 freedom, and human rights. We are hated because our
 	 government denies these things to people in third
 	 world countries whose resources are coveted by our
 	 multinational corporations... We must change our
 	 government's ways... Only one thing has ever ended a
 	 terrorist campaign - denying the terrorist
 	 organization the support of the larger community it
 	 represents... Remove the desperation, give them some
 	 hope, and support for terrorism will evaporate. At
 	 that point bin Laden will be forced to abandon
 	 terrorism or be treated like a common criminal.
 	 Either way, he and his money cease to be a threat. We
 	 CAN have security ... or we can have revenge. We
 	 cannot have both."
 		-- Dr. Robert M. Bowman, Director of all "Star Wars"
 		programs under presidents Ford and Carter, combat
 		pilot over Vietnam (101 missions), Ph.D. in Aeronautics
 		and Nuclear Engineering, President of the Institute for
 		Space and Security Studies and Presiding Archbishop of
 		the United Catholic Church



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

* Re: PROMPT escape sequences
  2007-10-07 10:34 PROMPT escape sequences Atom Smasher
@ 2007-10-07 17:32 ` Bart Schaefer
  2007-10-07 23:27   ` Atom Smasher
  2007-10-08  1:22   ` Geoff Wing
  0 siblings, 2 replies; 9+ messages in thread
From: Bart Schaefer @ 2007-10-07 17:32 UTC (permalink / raw)
  To: zsh-users

On Oct 7, 11:34pm, Atom Smasher wrote:
}
} PS1='%S%# '

That doesn't just set your prompt to reverse, does it?  Everything you
type after the prompt would be in reverse, too, because you're never
turning "standout mode" off again after turning it on.

Similarly:

} PS1='%{^[[36m%}%# '

This enters cyan coloring mode but does not leave it again.

The prompt itself (the "%" or "#" sign) remains cyan colored, does it not?
Zsh is only responsible for what happens to the characters that are in
the PS1 string, not for any "unbalanced" state you've left things in
after PS1 has been printed.

So the answer to this question is:

} is there a way to set a color at the prompt that doesn't reset to default 
} when i tab-complete?

No, there isn't, because you're relying on the entire prompt being re-
painted every time zsh needs to redraw the line that begins with the
prompt, but ZLE is optimized to use cursor motions and only redraw the
bits of the line that actually need changing.  It has no idea what the
color settings are at any given position on the terminal, so it can't
restore color; it only knows what the non-zero-width characters are.

It "works" for %S because of a quirk in the way some terminals (xterm
included) implement "standout mode", not because of anything zsh does
differently.  On a different terminal/emulator (or possibly even just
with different termcap/terminfo definitions) you're likely to see %S
behaving the same way you now see cyan.

You can "unsetopt alwayslastprompt" so that zsh does not return to the
previous prompt after completing, but you may find that unsatisfactory
for other reasons.


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

* Re: PROMPT escape sequences
  2007-10-07 17:32 ` Bart Schaefer
@ 2007-10-07 23:27   ` Atom Smasher
  2007-10-08  3:27     ` Bart Schaefer
  2007-10-08  1:22   ` Geoff Wing
  1 sibling, 1 reply; 9+ messages in thread
From: Atom Smasher @ 2007-10-07 23:27 UTC (permalink / raw)
  To: zsh-users

On Sun, 7 Oct 2007, Bart Schaefer wrote:

> So the answer to this question is:
>
> } is there a way to set a color at the prompt that doesn't reset to default
> } when i tab-complete?
>
> No, there isn't, because you're relying on the entire prompt being re- 
> painted every time zsh needs to redraw the line that begins with the 
> prompt, but ZLE is optimized to use cursor motions and only redraw the 
> bits of the line that actually need changing.  It has no idea what the 
> color settings are at any given position on the terminal, so it can't 
> restore color; it only knows what the non-zero-width characters are.
===================

this gets me very close:


expand-or-complete () {
     PREDISPLAY=${fg[cyan]}
     zle .expand-or-complete
}
zle -N expand-or-complete


but it doesn't output any escape characters... just the text string 
"^[[36m" as if there's an implied ${(V)fg[cyan]}. what do i need to do to 
make that output a literal escape sequence? why doesn't it work that way 
by default?

i also tried including "reset-prompt" within the redefined 
"expand-or-complete", but didn't have any luck with that. i thought that 
in re-displaying the prompt, it would also re-colorize the text typed at 
the prompt, but apparently it doesn't.


-- 
         ...atom

  ________________________
  http://atom.smasher.org/
  762A 3B98 A3C3 96C9 C6B7 582A B88D 52E4 D9F5 7808
  -------------------------------------------------

 	"I never did give them hell. I just told the truth,
 	 and they thought it was hell."
 		-- Harry S Truman, 3 Apr 1956



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

* Re: PROMPT escape sequences
  2007-10-07 17:32 ` Bart Schaefer
  2007-10-07 23:27   ` Atom Smasher
@ 2007-10-08  1:22   ` Geoff Wing
  2007-10-08  3:12     ` Bart Schaefer
  1 sibling, 1 reply; 9+ messages in thread
From: Geoff Wing @ 2007-10-08  1:22 UTC (permalink / raw)
  To: zsh-users

On Monday 2007-10-08 10:40 +1000, Bart Schaefer output:
:On Oct 7, 11:34pm, Atom Smasher wrote:
[...]
:} PS1='%{^[[36m%}%# '
:This enters cyan coloring mode but does not leave it again.

:So the answer to this question is:
:} is there a way to set a color at the prompt that doesn't reset to default 
:} when i tab-complete?
:No, there isn't, because you're relying on the entire prompt being re-
:painted every time zsh needs to redraw the line that begins with the

I (obviously) don't understand what the desired result is.  Ah, OK, 
now I've tried with alwayslastprompt it becomes clearer.

The only stored character attributes (currently) from the prompt are
bold, standout and underline.  If you use one of those (I use bold for
my main text) then you should also be setting POSTEDIT appropriately,
e.g.  POSTEDIT=`print -P -n %b`  # note that %b turns off all attributes

:It "works" for %S because of a quirk in the way some terminals (xterm
:included) implement "standout mode", not because of anything zsh does
:differently.

Well, actually, it should be handling these correctly.  For bold, standout
and underline.

Regards,
Geoff


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

* Re: PROMPT escape sequences
  2007-10-08  1:22   ` Geoff Wing
@ 2007-10-08  3:12     ` Bart Schaefer
  2007-10-08  3:42       ` Geoff Wing
  0 siblings, 1 reply; 9+ messages in thread
From: Bart Schaefer @ 2007-10-08  3:12 UTC (permalink / raw)
  To: zsh-users

On Oct 8, 11:22am, Geoff Wing wrote:
} Subject: Re: PROMPT escape sequences
}
} On Monday 2007-10-08 10:40 +1000, Bart Schaefer output:
} :It "works" for %S because of a quirk in the way some terminals (xterm
} :included) implement "standout mode", not because of anything zsh does
} :differently.
} 
} Well, actually, it should be handling these correctly. For bold,
} standout and underline.

Hm.  If I do, in my xterm,

% PS1='verylongstring%#%S '

then the entire prompt, including the "verylongstring%", appears in
reverse video.  Are you saying that it's ZLE that's spreading the
standout mode to the left as well as to the right, and not just a
quirk of xterm?

To get what I'd expect, it's necessary to explicitly put in %s at
the beginning of the prompt.

% PS1='%sverylongstring%#%S '

Further, if I type something at that prompt and then backspace over
it, the reverse video gets left behind where the erased characters
used to be.


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

* Re: PROMPT escape sequences
  2007-10-07 23:27   ` Atom Smasher
@ 2007-10-08  3:27     ` Bart Schaefer
  0 siblings, 0 replies; 9+ messages in thread
From: Bart Schaefer @ 2007-10-08  3:27 UTC (permalink / raw)
  To: zsh-users

On Oct 8, 12:27pm, Atom Smasher wrote:
} 
} expand-or-complete () {
}      PREDISPLAY=${fg[cyan]}
}      zle .expand-or-complete
} }
} zle -N expand-or-complete
} 
} but it doesn't output any escape characters... just the text string 
} "^[[36m" as if there's an implied ${(V)fg[cyan]}.

Yes, that's the way PREDISPLAY works.

} what do i need to do to make that output a literal escape sequence?

Nothing.  You can't.

} why doesn't it work that way by default?

Because it would be whole lot more difficult for ZLE to keep track of
what the screen is supposed to look like if it had to track invisible
zero-width output.
 
} i also tried including "reset-prompt" within the redefined 
} "expand-or-complete", but didn't have any luck with that.

ZLE is still working very hard to re-print only exactly those parts
of the screen that have changed ... so it prints the left prompt,
and then emits a move-the-cursor sequence to jump to the end of the
line (or to the right prompt if you have one).  It only reprints the
characters that aren't part of the prompt if there are fewer of them
than the number of characters in the move-cursor sequence.

All of this optimized redraw stuff is to make the display fast enough
for a very slow TTY line, like a late-1980s dialup.  Maybe an easy 
way to "fix" this would be a switch to turn off all such optimization
and simply redraw everything all the time.


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

* Re: PROMPT escape sequences
  2007-10-08  3:12     ` Bart Schaefer
@ 2007-10-08  3:42       ` Geoff Wing
  2007-10-08  4:02         ` Bart Schaefer
  0 siblings, 1 reply; 9+ messages in thread
From: Geoff Wing @ 2007-10-08  3:42 UTC (permalink / raw)
  To: zsh-users

On Monday 2007-10-08 13:13 +1000, Bart Schaefer output:
:On Oct 8, 11:22am, Geoff Wing wrote:
:} On Monday 2007-10-08 10:40 +1000, Bart Schaefer output:
:} :It "works" for %S because of a quirk in the way some terminals (xterm
:} :included) implement "standout mode", not because of anything zsh does
:} :differently.
:} Well, actually, it should be handling these correctly. For bold,
:} standout and underline.
:Hm.  If I do, in my xterm,
:% PS1='verylongstring%#%S '
:then the entire prompt, including the "verylongstring%", appears in
:reverse video.  Are you saying that it's ZLE that's spreading the
:standout mode to the left as well as to the right, and not just a
:quirk of xterm?

I haven't yet been able to have this occur. "verylongstring%" always stays
in normal (non-standout) attribute with rxvt and a quick test in xterm (215)
This was with the prompt near the right side and with it longer than column
width (i.e. wrapped onto next line).  Tried with both RPS1 set and unset,
w/ POSTEDIT unset; also from "zsh -f"

:To get what I'd expect, it's necessary to explicitly put in %s at
:the beginning of the prompt.
:% PS1='%sverylongstring%#%S '

:Further, if I type something at that prompt and then backspace over
:it, the reverse video gets left behind where the erased characters
:used to be.

Ah, well, I'd expect that.  I don't think it's necessarily a "wrong"
behaviour.

Regards,
Geoff


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

* Re: PROMPT escape sequences
  2007-10-08  3:42       ` Geoff Wing
@ 2007-10-08  4:02         ` Bart Schaefer
  2007-10-08  4:27           ` Geoff Wing
  0 siblings, 1 reply; 9+ messages in thread
From: Bart Schaefer @ 2007-10-08  4:02 UTC (permalink / raw)
  To: zsh-users

On Oct 8,  1:42pm, Geoff Wing wrote:
} Subject: Re: PROMPT escape sequences
}
} :Hm.  If I do, in my xterm,
} :% PS1='verylongstring%#%S '
} :then the entire prompt, including the "verylongstring%", appears in
} :reverse video.  Are you saying that it's ZLE that's spreading the
} :standout mode to the left as well as to the right, and not just a
} :quirk of xterm?
} 
} I haven't yet been able to have this occur.

Sorry, I missed a detail (that's what I get for reconstructing an
example rather than copy-pasting it).  Here's a better one:

PS1='very%Blong%bstring%#%S '

The %S effect begins at the %B, not at the point where it should.


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

* Re: PROMPT escape sequences
  2007-10-08  4:02         ` Bart Schaefer
@ 2007-10-08  4:27           ` Geoff Wing
  0 siblings, 0 replies; 9+ messages in thread
From: Geoff Wing @ 2007-10-08  4:27 UTC (permalink / raw)
  To: zsh-users

On Monday 2007-10-08 14:02 +1000, Bart Schaefer output:
:On Oct 8,  1:42pm, Geoff Wing wrote:
:} I haven't yet been able to have this occur.
:Sorry, I missed a detail (that's what I get for reconstructing an
:example rather than copy-pasting it).  Here's a better one:
:PS1='very%Blong%bstring%#%S '
:The %S effect begins at the %B, not at the point where it should.

OK, well, it was broken between 4.2.0 and 4.2.1.
Quick surface check and I'd say it looks like zle_refresh.c:1.13

Regards,
Geoff


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

end of thread, other threads:[~2007-10-08  4:28 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-07 10:34 PROMPT escape sequences Atom Smasher
2007-10-07 17:32 ` Bart Schaefer
2007-10-07 23:27   ` Atom Smasher
2007-10-08  3:27     ` Bart Schaefer
2007-10-08  1:22   ` Geoff Wing
2007-10-08  3:12     ` Bart Schaefer
2007-10-08  3:42       ` Geoff Wing
2007-10-08  4:02         ` Bart Schaefer
2007-10-08  4:27           ` Geoff Wing

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