Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Colouring my prompt

22 views
Skip to first unread message

Cecil Westerhof

unread,
Dec 18, 2017, 4:28:06 AM12/18/17
to
I have written my ::tclreadline::prompt1. Now I want to add colours.
How would I do that?

For example: in my Bash PS1 I have:
\[\e[32;1m\]

to make my prompt green.

When I put this in the string that prompt1 returns, it is just
displayed like that instead of colouring my prompt.

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Andreas Leitgeb

unread,
Dec 18, 2017, 4:34:13 AM12/18/17
to
Cecil Westerhof <Ce...@decebal.nl> wrote:
> I have written my ::tclreadline::prompt1. Now I want to add colours.
> How would I do that?
> For example: in my Bash PS1 I have:
> \[\e[32;1m\]

Tcl doesn't have the "\e"... rather try \033

> to make my prompt green.

"Make the prompt green again" ;-)

Cecil Westerhof

unread,
Dec 18, 2017, 5:59:06 AM12/18/17
to
That was one problem. But there was also a problem with \[ and \]. But
I solved it with writing a routine to find out the values of the
original prompt.

I now use:
set colourStart "\001\033\["
set colourEnd "m\002"
set colour1 [format "%s1;31%s" ${colourStart} ${colourEnd}]
set colour2 [format "%s1;32%s" ${colourStart} ${colourEnd}]
set colour3 [format "%s1;37%s" ${colourStart} ${colourEnd}]

and because the root user is a special case, I also have:
set user $::tcl_platform(user)
if {${user} eq "root"} {
set temp ${colour1}
set colour1 ${colour2}
set colour2 ${temp}
}

and I create the prompt with:
format "%s%s %s\[%s %s@%s:%s\]\n$ %s" \
${colour1} \
tclsh${::tcl_version} \
${colour2} \
${dateTime} \
${user} \
${host} \
${currentDir} \
${colour3}

And maybe I should write a proc to create the colours. Something like:
[getColour redLight]

is a bit more clear as:
[format "%s1;31%s" ${colourStart} ${colourEnd}]
0 new messages