zsh-workers
 help / color / mirror / code / Atom feed
* Escape characters in $psvar[]
@ 2010-11-19 13:04 Frank Terbeck
  2010-11-19 14:03 ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Frank Terbeck @ 2010-11-19 13:04 UTC (permalink / raw)
  To: zsh-workers; +Cc: idl0r.qasl.de

Hey list,

The following came up on IRC.

A user uses the `clint' prompt, which uses `psvar' to include results
from `vcs_info'. He wanted to include colour codes in the vcs_info
formats for proper eye candy. Which resulted in literal "^[[35m" strings
in the actual prompt instead of colours.

It seems using $psvar[] replaces escape characters (ascii 0x1b) with two
characters: `^' and `[':

[snip]
% autoload -Uz colors
% colors
% psvar[9]=$fg[red]foo
% print ${psvar[9]} | hd -c
00000000  1b 5b 33 31 6d 66 6f 6f  0a                       |.[31mfoo.|
0000000 033   [   3   1   m   f   o   o  \n                            
0000009
% print -P '%9v' | hd -c
00000000  5e 5b 5b 33 31 6d 66 6f  6f 0a                    |^[[31mfoo.|
0000000   ^   [   [   3   1   m   f   o   o  \n                        
000000a
[snap]

Is that indented behaviour or a bug? A quick skim through the docs
didn't turn up an answer.

Regards, Frank

-- 
In protocol design, perfection has been reached not when there is
nothing left to add, but when there is nothing left to take away.
                                                  -- RFC 1925


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

* Re: Escape characters in $psvar[]
  2010-11-19 13:04 Escape characters in $psvar[] Frank Terbeck
@ 2010-11-19 14:03 ` Peter Stephenson
  2010-11-19 14:06   ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2010-11-19 14:03 UTC (permalink / raw)
  To: zsh-workers; +Cc: idl0r.qasl.de

On Fri, 19 Nov 2010 14:04:35 +0100
> A user uses the `clint' prompt, which uses `psvar' to include results
> from `vcs_info'. He wanted to include colour codes in the vcs_info
> formats for proper eye candy. Which resulted in literal "^[[35m"
> strings in the actual prompt instead of colours.
> 
> It seems using $psvar[] replaces escape characters (ascii 0x1b) with
> two characters: `^' and `[':
>
> Is that indented behaviour or a bug? A quick skim through the docs
> didn't turn up an answer.

psvar is sanitized by going through nicechar(), or equivalent, so it
appears to be deliberate if undocumented.  I think one of the points of
psvar is to protect it from funny goings on in prompt expansion; you can
set $prompt_subst and use $psvar[1] if you prefer the other way.

You'd need to surround with %{ ... %} however you did it, or use the new
colour codes.

-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK



Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom


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

* Re: Escape characters in $psvar[]
  2010-11-19 14:03 ` Peter Stephenson
@ 2010-11-19 14:06   ` Peter Stephenson
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2010-11-19 14:06 UTC (permalink / raw)
  To: zsh-workers

On Fri, 19 Nov 2010 14:03:13 +0000
Peter Stephenson <Peter.Stephenson@csr.com> wrote:
> you can set $prompt_subst and use $psvar[1] if you prefer the other
> way.

sorry, 'setopt prompt_subst', obviously.

-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom


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

end of thread, other threads:[~2010-11-19 15:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-19 13:04 Escape characters in $psvar[] Frank Terbeck
2010-11-19 14:03 ` Peter Stephenson
2010-11-19 14:06   ` Peter Stephenson

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