PDA

View Full Version : Color Text


ericdp
03-21-2006, 12:56 PM
I use ksh88 as my shell. I'd really like to use ksh93, but that is a different story. So in my .profile I have:

PS1=''`whoami`'"@"$HOSTNAME:" "\[$PWD\] > '; export PS1

Which gets me:

name@machine: [/dir1/dir2] >

I would like to see that in one color. The text I am typing in a different color. Then the output text, i.e. normal text in a third color. Is this possible in CRT?



question 2:
I've set my screen to use FloralWhile/DarkCyan in XTerm emulation. But I'm not sure if that is the best emulation mode I should be using. I'd like to use vim, but I just can't seem to find the right settings.


Thanks.
Eric

tnygren
03-22-2006, 09:47 AM
Hi Ericd,

I just want to make certain that I totally understand the coloring that you would like to see.

The prompt should be one color, text being type another and rest of the text a third.

Is that correct?

Is this how it displays when connected directly to the remote machine?

As for your second question, are the colors not appearing correctly in VIM?

If so, is 'ANSI' color enabled in the 'Emulation' sub-category under 'Terminal' in the 'Session Options'?

The 'Xterm' emulation should work fine with VIM.

If ANSI color was already enabled, could you send me a screen shot of how VIM is appearing?

Just include the screen shot in an email to support@vandyke.com. Just use 'ATTN: Teresa Forum Thread 1366' in the subject so that it will get to me.

MrC
10-23-2006, 10:46 AM
From Ericdp:
> recently you mentioned that you have a way of doing color within CRT.
> I am using ksh88 (not my choice, but I can't get the SAs to load ksh93).
> Could you help me? I too would like to use color to distinguish my various
> sessions.
>
> Thanks
> Eric

Eric,

You can add color by setting your term type to one that supports color. I'm using xterm for this. Here's a sample prompt setting that will give you color:

PS1="^[[1;33m$LOGNAME@$HOSTNAME: [$PWD] >^[[0;32m "
export PS1

The ^[ are literal escape characters. You enter those in the vi/vim with a control V followed by the Escape key. Your prompt will look something like:

MrC@glacier: [/home/MrC] > pwd
/home/MrC

The 33 is the fourth color in the ANSI colors (0 based, 0-7) as set in your Global Settings. 32 is green (third color in the ANSI colors).

There is no way to differentiate between input and output in the shell. Its all just text.

For VIM, you need to enable syntax highlighting. Once in VIM, type:

:syntax on

and see if this helps.

ericdp
10-24-2006, 01:06 PM
with ANSIColor check on


(e0110054@lfs8401q) /ldaphome/e0110054>PS1="^[[1;33m$LOGNAME@$HOSTNAME: [$PWD] >^[[0;32m "
^[[1;33me0110054@: [/ldaphome/e0110054] >^[[0;32m



Doesn't look like I'll be able to use color in the prompt.

Eric

miked
10-24-2006, 05:47 PM
It looks like the escape characters weren't accepted. However, along the same lines MrC suggested, try replacing the escape character "^[" with the octal value for escape \033:export PS1="\033[1;33m$LOGNAME@$HOSTNAME: [$PWD] >\033[0;32m "Here is a website with some other dotfiles you might be able to use as examples:http://www.dotfiles.com/index.php?app_id=5

ericdp
10-25-2006, 10:57 AM
Still no go.


(e0110054@lfs6411q) /ldaphome/e0110054>export PS1="\033[1;33m$LOGNAME@$HOSTNAME: [$PWD] >\033[0;32m "
033[1;33me0110054@: [/ldaphome/e0110054] >033[0;32m


I guess I'm stuck with monocolor text.

Eric

ericdp
10-25-2006, 12:32 PM
Ok, finally I found the clue to solving this. :) the \e or \033 values for ESC do not work. You must edit a file (I use vi), enter ctrl-v then hit the ESC key. This will create the ^[ single chararacter.


export reset='^[[0m'
export black='^[[0;30m'
export red='^[[0;31m'
export green='^[[0;32m'



echo $red This is a test $green and some more $reset
This is a test and some more


next step to set up commands like
alias ll=echo $yellow;ls -alF;echo $reset

Thanks for the help. Just took me a while to find the trick to create and use the ESC character. Why the other alternatives don't work, I don't know.

Eric

MrC
10-25-2006, 12:42 PM
Excellent!

I didn't think \e or \033 would work in your old'ish ksh, and that's why I had mentioned to use the escaped Escape char. Newer shells are more elegant in how they handle prompts.

Glad its working.

miked
10-25-2006, 01:47 PM
Eric,

Thanks for the follow up message and persistence :) - glad to see your colors :cool:

Many shells allow you to press Ctrl-V (and release the keys) then press the ESC key and see ^[ appear as a single character, as well as letting you do things like: echo -ne "\033[0;33m hello ". I'm not sure why the vi editor would be necessary, but it looks like MrC saw the solution to this question pretty clearly.