From: Meino Christian Cramer <Meino.Cramer@gmx.de>
To: schaefer@brasslantern.com
Cc: zsh-users@sunsite.dk
Subject: Re: Colored PS1
Date: Thu, 08 Sep 2005 05:31:10 +0200 (CEST) [thread overview]
Message-ID: <20050908.053110.07640431.Meino.Cramer@gmx.de> (raw)
In-Reply-To: <1050908023921.ZM14908@candle.brasslantern.com>
From: Bart Schaefer <schaefer@brasslantern.com>
Subject: Re: Colored PS1
Date: Thu, 08 Sep 2005 02:39:21 +0000
Hi Bart !
First of all and most important:
***$fg_very_very_bold[RED]THANK YOU VERY VERY MUCH!$fg_very_very_bold[BLACK]***
for your help and patience with my English confusions !!!
This helps me a lot to understand things !
> On Sep 7, 7:21pm, Meino Christian Cramer wrote:
> }
> } Now I would write:
> }
> } export PS1=$fb_bold[black]%M$fb_no_bold[black]:%2d
> }
> } But this would not work (that's why I wrote my mail...). As I
> } understand your mail, I had to enclose the "literally escape
> } sequence" (whatever this is...I am no native English speaker and if
> } translated to german this makes really no sense - as with so many
> } technospeak expressions...
>
> "literal" (not "literally") in that context means "unchanged; exactly
> the way it appears."
...do have to say more about my English? I think...no...this is
selfdocumenting!
> "escape sequence" in the context of terminals means "a series of ASCII
> characters, often beginning with the ESC (\033, \x1B) character." It
> is common for terminals and terminal emulators to recognize such a
> series of characters in the output and alter the terminal's behavior.
...oh I see...something like "commands"! :)
( "assembler for terminals" -- either it works or you gut stuck ;)
> The "colors" (aka "colours") function sets up an associative array
> with values that are various such terminal control strings (which
> would have been a better thing to call them than "escape sequences",
> but historically they were named the latter because they allow the
> terminal to "escape" from it's routine job of displaying and instead
> do something special). So when you write $fg_bold[black], you are
> asking zsh to insert the control string that changes the terminal's
> foreground to bold and black.
>
> The trouble is that "escape sequnce" in the context of a prompt means
> one of the pairs of characters that begins with a percent (%) sign.
> Again this is from the concept of a special combination of characters
> causing a change (an escape from) the usual interpretation of such
> characters.
>
> ...do I understand this cxorrectly? In other words:
The trouble is, that a escape seuence can be misinterpreted as a
> special sign of the prompt expanding itsself ?
>
> Thus, one uses "prompt escape sequences" to surround "terminal escape
> sequences," and this clash of terminology is often enough to confuse
> native English speakers; so you shouldn't feel too bad.
>
> } And how should I figure out, whether the cursor position would
> } have been changed...???
>
> In the worst case, you go look at the documentation for an ANSI standard
> terminal, find the control string that's being used, and determine from
> the definition whether any cursor movement is involved.
URKS! I am not lazy in reading documentations, I am lesser good in
understanding (english) documentations...but the effort must be in a
reasonable relation to what I want to achieve.
> Usually, though, you just use your common sense. Does the cursor move
> when the color changes from white to red, or plain to bold? No, it does
> not, so the string value of $fg_bold[black] does not move the cursor.
>
> } So I would guess this cames more closer to what is right:
> }
> } export PS1=%{$fg_bold[black]%}%M%{$fg_no_bold[black]%}:%2d
> }
> } but this one produces
> }
> } }solfire:/home/mccramer
>
> Are you quite sure that you have all the % signs in the right places?
> My first suspicion would be that you wrote "PS1=%{$fg_bold[black]}..."
> (note missing % before the } there).
I dont think, that braces got messed up. I checked that with
MicroEmacs's (the editor I use to use...) "goto-matching-fence" and
kept an eye on the %'s....
> This can also be affected by various setopts such as SH_WORD_SPLIT and
> PROMPT_SUBST and KSH_ARRAYS. For example, $fg_bold[black] means
> something entirely different when KSH_ARRAYS is set.
I didn't set KSH_ARRAYS and SH_WORD_SPLIT. But I am not sure whether
I set "various setopts" ;)
> I strongly suggest that you unsetopt PROMPT_SUBST, and protect against
> SH_WORD_SPLIT by placing double quotes around the assignment:
>
> export PS1="%{$fg_bold[black]%}%M%{$fg_no_bold[black]%}:%2d "
>
> } Enclosing the whole thing in ${...} gives me no prompt at all.
>
> I'm surprised it didn't give a syntax error. One almost never wants
> ${...} around "the whole thing" unless one understands exactly what
> one is doing.
Yes, you are right...I didnt want it ;))))
> } And what is the reason for the ps_beg/ps_end trick? Why no to write
> } everyting in one big term ?
>
> Easier to read it, and to edit it later. That's all.
>
Finally this works for me:
autoload -U colors && colors
export prompt=%{$fg_no_bold[red]%}%M%{$fg_no_bold[black]%}:%{$fg_no_bold[blue]%}
%2d%{$fg_no_bold[black]%}\>
export PS1=$prompt
Setting PS1 directly without the addtional step using $prompt it does
not work.
No I am happy haveing a colored prompt -- only wihing that sometimes
zshall would be more understandable than totally complete. Only me two
cent....
Thank you very much for all your help and patience, Bart ! :O)
Have a nice day!
Meino
next prev parent reply other threads:[~2005-09-08 3:29 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-09-07 3:25 Meino Christian Cramer
2005-09-07 7:53 ` Tim Kruse
2005-09-07 14:57 ` Bart Schaefer
2005-09-07 17:21 ` Meino Christian Cramer
2005-09-08 2:39 ` Bart Schaefer
2005-09-08 3:31 ` Meino Christian Cramer [this message]
2005-09-08 16:05 ` Bart Schaefer
2005-09-08 16:59 ` Meino Christian Cramer
2005-09-09 14:32 ` Bart Schaefer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20050908.053110.07640431.Meino.Cramer@gmx.de \
--to=meino.cramer@gmx.de \
--cc=schaefer@brasslantern.com \
--cc=zsh-users@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).