zsh-workers
 help / color / mirror / code / Atom feed
* Good documentation about literal escape sequences in prompt?
@ 2000-03-11 23:41 Juhapekka Tolvanen
  2000-03-11 23:55 ` Adam Spiers
  2000-03-12  0:05 ` Bart Schaefer
  0 siblings, 2 replies; 7+ messages in thread
From: Juhapekka Tolvanen @ 2000-03-11 23:41 UTC (permalink / raw)
  To: zsh-workers


%{...%}
        Include a string as a literal escape sequence. The
        string within the braces should not change the cursor
        position. Brace pairs can nest.

Hey, come on! Do you really think that is enough? Why don't you provide some
good examples? I know you can do it better!

For example this does not work:

PS1="%{\e[1;31m%}$PS1%{\e[1m%}"

Just look, what i get:

Normally my PS1 is like this:

1510 | p5 | juhtolv@heresy : /home/juhtolv/apu
% 

If I say this:

PS1="%{\e[1;31m%}$PS1%{\e[1m%}"

I get this:

[1;31m$PS1"\e[1;31m1538 | p6 | juhtolv@heresy : /home/juhtolv
% \e[1m

Color-codes were found from /usr/share/zsh/functions/colors

I tried to understand other files in /usr/share/zsh/functions, like _prompt
and promptinit but even it was the real pain in the ass.

So meanwhile I have to use really ugly hacks like these:

PS1="`print -Pn '\e[1;31m'`$PS1 `print -Pn '\e[0m'`"

PS1="`print -Pn '\e[1;31m'``print -Pn '\e[1;43m'`$PS1`print -Pn '\e[0m'`"

-- 
-- Juhapekka "naula" Tolvanen * * * U of Jyväskylä * * juhtolv@st.jyu.fi --
-- http://www.cc.jyu.fi/~juhtolv/ * * * * " STRAIGHT BUT NOT NARROW !! " --
---------------------------------------------------------------------------
"I don't want to run a company. I'm not good at managing people. You have
a problem with the guy in the next cubicle? I don't care. Shoot him or
something." Marc Andreessen, founder of Netscape, in Rolling Stone, May '97


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

* Re: Good documentation about literal escape sequences in prompt?
  2000-03-11 23:41 Good documentation about literal escape sequences in prompt? Juhapekka Tolvanen
@ 2000-03-11 23:55 ` Adam Spiers
  2000-03-12  0:05 ` Bart Schaefer
  1 sibling, 0 replies; 7+ messages in thread
From: Adam Spiers @ 2000-03-11 23:55 UTC (permalink / raw)
  To: zsh-workers

Juhapekka Tolvanen (juhtolv@st.jyu.fi) wrote:
> 
> %{...%}
>         Include a string as a literal escape sequence. The
>         string within the braces should not change the cursor
>         position. Brace pairs can nest.
> 
> Hey, come on! Do you really think that is enough? Why don't you provide some
> good examples? I know you can do it better!
> 
> For example this does not work:
> 
> PS1="%{\e[1;31m%}$PS1%{\e[1m%}"

That's because \e doesn't mean anything special within double-quotes;
it only gets interpreted as ASCII 27 when used inside $'' quotes, or
from the `print', `echo', or `bindkey' built-ins.  So what you want
is:

PS1=$'%{\e[1;31m%}'"$PS1"$'%{\e[1m%}'

I also made this mistake when first messing around with prompts, so it
looks like the relevant docs could indeed do with a bit of
improvement.  (Would do this myself, but still waiting for someone to
give me the go-ahead on sourceforge, or at least make up-to-date
snapshots available so that I can submit reliable patches.  Anyone
planning to release dev-20 before pws comes back?)

Adam


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

* Re: Good documentation about literal escape sequences in prompt?
  2000-03-11 23:41 Good documentation about literal escape sequences in prompt? Juhapekka Tolvanen
  2000-03-11 23:55 ` Adam Spiers
@ 2000-03-12  0:05 ` Bart Schaefer
  2000-03-12 17:35   ` Juhapekka Tolvanen
  1 sibling, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2000-03-12  0:05 UTC (permalink / raw)
  To: Juhapekka Tolvanen, zsh-workers

On Mar 12,  1:41am, Juhapekka Tolvanen wrote:
} Subject: Good documentation about literal escape sequences in prompt?
}
} %{...%}
}         Include a string as a literal escape sequence. The
}         string within the braces should not change the cursor
}         position. Brace pairs can nest.
} 
} Hey, come on! Do you really think that is enough? Why don't you provide some
} good examples? I know you can do it better!

It's an acknowledged problem that the docs need more examples.  Care to
provide any?

} For example this does not work:
} 
} PS1="%{\e[1;31m%}$PS1%{\e[1m%}"
         ^^^^^^^^
The doc says LITERAL escape sequence; the substring \e is not LITERALLY the
character with ASCII value decimal-27.  What other part of the doc gave you
the idea that prompting would replace \e with something else?

} Color-codes were found from /usr/share/zsh/functions/colors

Well, then.  What you want to do is (1) run that function `colors' to set
up the $fg_bold array, etc., and then (2) set your prompt like this:

PS1="%{$fg_bold[red]%}$PS1%{$reset_color%}"

} I tried to understand other files in /usr/share/zsh/functions, like _prompt
} and promptinit but even it was the real pain in the ass.

It's also true that there's no doc for the prompts stuff yet.  You type

autoload -U promptinit
promptinit

And then you can get a little bit of help from `prompt -h'.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


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

* Re: Good documentation about literal escape sequences in prompt?
  2000-03-12  0:05 ` Bart Schaefer
@ 2000-03-12 17:35   ` Juhapekka Tolvanen
  2000-03-12 18:19     ` Oliver Kiddle
  2000-03-12 18:37     ` Bart Schaefer
  0 siblings, 2 replies; 7+ messages in thread
From: Juhapekka Tolvanen @ 2000-03-12 17:35 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-workers


On Sun, 12 Mar 2000, Bart Schaefer wrote:

> On Mar 12,  1:41am, Juhapekka Tolvanen wrote:
> } Subject: Good documentation about literal escape sequences in prompt?
> }
> } %{...%}
> }         Include a string as a literal escape sequence. The
> }         string within the braces should not change the cursor
> }         position. Brace pairs can nest.
> } 
> } Hey, come on! Do you really think that is enough? Why don't you provide some
> } good examples? I know you can do it better!
> 
> It's an acknowledged problem that the docs need more examples.  Care to
> provide any?

I can't write documentation about things i can't do myself. Can you?
 
> } For example this does not work:
> } 
> } PS1="%{\e[1;31m%}$PS1%{\e[1m%}"
>          ^^^^^^^^
> The doc says LITERAL escape sequence; the substring \e is not LITERALLY the
> character with ASCII value decimal-27.  What other part of the doc gave you
> the idea that prompting would replace \e with something else?

Why docs does not tell, what those so called literal escape sequences mean
and how they they differ from other kind of escape sequences?
 
> } Color-codes were found from /usr/share/zsh/functions/colors
> 
> Well, then.  What you want to do is (1) run that function `colors' to set
> up the $fg_bold array, etc., and then (2) set your prompt like this:
> 
> PS1="%{$fg_bold[red]%}$PS1%{$reset_color%}"

Well, let's see:

1663 | p6 | juhtolv@heresy : /home/juhtolv
% . /usr/share/zsh/functions/colors
1664 | p6 | juhtolv@heresy : /home/juhtolv
% PS1="%{$fg_bold[red]%}$PS1%{$reset_color%}"
[red]1665 | p6 | juhtolv@heresy : /home/juhtolv
% 

And whole prompt is now cyan-colored.

 
> } I tried to understand other files in /usr/share/zsh/functions, like _prompt
> } and promptinit but even it was the real pain in the ass.
> 
> It's also true that there's no doc for the prompts stuff yet.  You type
> 
> autoload -U promptinit
> promptinit
> 
> And then you can get a little bit of help from `prompt -h'.

I can use those commands and I can load those pre-determined prompts, but
that is not exactly the thing I want to do. I just want to add some escape
sequences to my PS1 so i can add some colors to it.

The biggest unanswered question that still remains is this:

When I find some escape sequences from /usr/share/zsh/functions/colors, how
can I "convert" them so, that I can put them to my PS1 between %{...%} ?

At least that question should be answered somewhere in docs. But it would be
better to list all escape sequences in such format, that can be added to
PS1 between %{...%}.

-- 
-- Juhapekka "naula" Tolvanen * * * U of Jyväskylä * * juhtolv@st.jyu.fi --
-- http://www.cc.jyu.fi/~juhtolv/ * * * * " STRAIGHT BUT NOT NARROW !! " --
---------------------------------------------------------------------------
"I don't want to run a company. I'm not good at managing people. You have
a problem with the guy in the next cubicle? I don't care. Shoot him or
something." Marc Andreessen, founder of Netscape, in Rolling Stone, May '97


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

* Re: Good documentation about literal escape sequences in prompt?
  2000-03-12 17:35   ` Juhapekka Tolvanen
@ 2000-03-12 18:19     ` Oliver Kiddle
  2000-03-12 19:34       ` Juhapekka Tolvanen
  2000-03-12 18:37     ` Bart Schaefer
  1 sibling, 1 reply; 7+ messages in thread
From: Oliver Kiddle @ 2000-03-12 18:19 UTC (permalink / raw)
  To: Juhapekka Tolvanen; +Cc: zsh-workers

Juhapekka Tolvanen wrote:
> 
> Well, let's see:
> 
> 1663 | p6 | juhtolv@heresy : /home/juhtolv
> % . /usr/share/zsh/functions/colors
> 1664 | p6 | juhtolv@heresy : /home/juhtolv
> % PS1="%{$fg_bold[red]%}$PS1%{$reset_color%}"
> [red]1665 | p6 | juhtolv@heresy : /home/juhtolv
> %
>
> And whole prompt is now cyan-colored.

I think that's a result of you using a slightly older version of Zsh
than the latest. The colors function has changed so that $fg_bold is an
associative array so for example $fg_bold[red] gives you the element
indexed by 'red'. Have a look in the colors function for a variable
definition for bold red and use that insead of $fg_bold[red] above or do
it directly as follows:

PS1="%{"$'\e[1;31m'"%}$PS1%{"$'\e[0m'"%}"

> When I find some escape sequences from /usr/share/zsh/functions/colors, how
> can I "convert" them so, that I can put them to my PS1 between %{...%} ?

You should be able to take my line above as an example of this.

> At least that question should be answered somewhere in docs. But it would be
> better to list all escape sequences in such format, that can be added to
> PS1 between %{...%}.

The list of escape sequences are not a feature of zsh but of your
terminal emulator. Try looking in the man pages for xterm. The colors
function merely defines zsh variables for command ANSI standard escape
sequences. Admittedly, the zsh docs could use a simple example of a
coloured prompt though.

Oliver Kiddle


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

* Re: Good documentation about literal escape sequences in prompt?
  2000-03-12 17:35   ` Juhapekka Tolvanen
  2000-03-12 18:19     ` Oliver Kiddle
@ 2000-03-12 18:37     ` Bart Schaefer
  1 sibling, 0 replies; 7+ messages in thread
From: Bart Schaefer @ 2000-03-12 18:37 UTC (permalink / raw)
  To: Juhapekka Tolvanen; +Cc: zsh-workers

On Mar 12,  7:35pm, Juhapekka Tolvanen wrote:
} Subject: Re: Good documentation about literal escape sequences in prompt?
}
} On Sun, 12 Mar 2000, Bart Schaefer wrote:
} 
} > The doc says LITERAL escape sequence; the substring \e is not LITERALLY the
} > character with ASCII value decimal-27.  What other part of the doc gave you
} > the idea that prompting would replace \e with something else?
} 
} Why docs does not tell, what those so called literal escape sequences mean
} and how they they differ from other kind of escape sequences?

Yes, there's probably a bit of a problem with context there.  In prompts,
"escape sequence" means "sequence of characters, often beginning with an
ASCII 27, that are interpreted by terminals to change display properties."

Oliver's answered the rest of your questions, I see.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


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

* Re: Good documentation about literal escape sequences in prompt?
  2000-03-12 18:19     ` Oliver Kiddle
@ 2000-03-12 19:34       ` Juhapekka Tolvanen
  0 siblings, 0 replies; 7+ messages in thread
From: Juhapekka Tolvanen @ 2000-03-12 19:34 UTC (permalink / raw)
  To: Oliver Kiddle; +Cc: zsh-workers


On Sun, 12 Mar 2000, Oliver Kiddle wrote:

> Juhapekka Tolvanen wrote:

> PS1="%{"$'\e[1;31m'"%}$PS1%{"$'\e[0m'"%}"
> 
> > When I find some escape sequences from /usr/share/zsh/functions/colors, how
> > can I "convert" them so, that I can put them to my PS1 between %{...%} ?

> You should be able to take my line above as an example of this.

Thanks, I needed that! (C) Gillette. It works. And now, somebody please
add that to FAQ of Zsh.


-- 
-- Juhapekka "naula" Tolvanen * * * U of Jyväskylä * * juhtolv@st.jyu.fi --
-- http://www.cc.jyu.fi/~juhtolv/ * * * * " STRAIGHT BUT NOT NARROW !! " --
---------------------------------------------------------------------------
"I don't want to run a company. I'm not good at managing people. You have
a problem with the guy in the next cubicle? I don't care. Shoot him or
something." Marc Andreessen, founder of Netscape, in Rolling Stone, May '97


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

end of thread, other threads:[~2000-03-12 19:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-03-11 23:41 Good documentation about literal escape sequences in prompt? Juhapekka Tolvanen
2000-03-11 23:55 ` Adam Spiers
2000-03-12  0:05 ` Bart Schaefer
2000-03-12 17:35   ` Juhapekka Tolvanen
2000-03-12 18:19     ` Oliver Kiddle
2000-03-12 19:34       ` Juhapekka Tolvanen
2000-03-12 18:37     ` 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).