Operating System - HP-UX
1822919 Members
4027 Online
109645 Solutions
New Discussion юеВ

change clours in telnet session

 
Geetam
Frequent Advisor

change clours in telnet session

Does anyone know of a way to change the colours in my
telnet session in response to a command to a script or
the contents of an environment variable? The interactive
work I do depends on a few environment variables; I
change them with a script.
I would like an un-avoidable visual reminder of which environment I am in.

I am using Reflection for Unix as my telnet application (in case that matters).

Thanks
17 REPLIES 17
Dan Hetzel
Honored Contributor

Re: change clours in telnet session

Hi,

As I don't have any Reflection software at hand it will be impossible to give you an accurate response.
Anyway, if you have the ability to change the color of your screen/characters, it will most probably be through an 'Escape Sequence' for which you should find all information in the Reflection user manual.

Outputting an escape sequence from a script, is as simple as an 'echo' or 'print' statement, which will look like
echo "\033[xxxxx\c"
where \033 is the escape character and \c prevents outputting a newline (mandatory, otherwise your cursor will change location)

That's about all I can say, It's not much but could be a starting point for you.

Best regards,

Dan
Everybody knows at least one thing worth sharing -- mailto:dan.hetzel@wildcroft.com
Richard Darling
Trusted Contributor

Re: change clours in telnet session

You could change the PS1 prompt in you profile to include the environmental factors (I am not sure which ones you want to show). For example, so that it is known who the user is and what box they are on; I added this line to the /etc/profile

PS1=`whoami`:`hostname`\>:

so when I am logged into my primary box called L1000 as root the prompt looks like this:

root:L1000>:

RD
Geetam
Frequent Advisor

Re: change clours in telnet session

Dan

I have managed to change to inverse video this way.
Colours are not working (yet)

Richard

I have changed the prompt already, but that is still
overlooked, specially when logged-in in multiple telnet
sessions.

Anyone else any suggestions?

Thanks
Alan Riggs
Honored Contributor

Re: change clours in telnet session

I use reflection X. In that program, I define telnet sesisons to hit various servers. Reflections then emulates a terminal of my choice (xterm, hpterm, etc.) and opens a telnet connection. In the connections settings window there is a command string that specifies the terminal, display, etc. If your Reflections for Unix works the same way, simpy specify the colors you wish as flags to the hpterm/xterm/dtterm command line.
Bruce Regittko_1
Esteemed Contributor

Re: change clours in telnet session

Hi,

I'm not sure how Reflection will handle it but you may want to check out the tput(1) an untic(1m) commands and the terminfo(4) database.

--Bruce
www.stratech.com/training
Richard Darling
Trusted Contributor

Re: change clours in telnet session

There is one other thing that I do...We have a training login, as well as a live database login for users. I setup separate icons on their desktop; one for training (with read background) and one for live (blue background). However, this still requires that the user login properly. I use Powerterm and changed the background color in Setup, Terminal, Colors.

RD
Bill Hassell
Honored Contributor

Re: change clours in telnet session

Since telnet does not define colors as such, you can emulate video enhancements with different colors. Reflection/1 (aka, Reflection for HP) from WRQ is an HP terminal emulator while Reflection/X is an Xwindow emulator that happens to contain a Reflection/2 (aka, Reflection VT100...) emulator too.

The Reflection/1 for Windows products (hereafter referred to Rwin1) can be configured for a huge variety of colors. Depending on the version you are running (5.x, 6.x etc), you would select the menu bar item Setup then either Terminal or Display where your colrs canm be defined.

Start with a dark blue background and white letters, then change Inverse, Halfbright, Blink, etc to different colors. Try a pink backgroud with black letters or a green background with white letters, etc for each of the 5 enhancements.

Save the result and then run sam or swinstall or GlancePlus in character mode and see what a difference color makes. On a 'real' terminal, these enhancements are in monochrome, hence the advantage to using configurable enhancement colors. I like to use a different color scheme for different connections as I often have 5-10 windows open at the same time.

Now for a nifty prompt string, you can use tput to create the appropriate ESC sequences for your terminal. Here is a snippet from /etc/profile (or you can put it into .profile if you like:

# Terminal character enhancements
HB=$(/usr/bin/tput dim) # dim text
HV=$(/usr/bin/tput smso) # 1/2 bright inverse
IV=$(/usr/bin/tput bold) # inverse
NV=$(/usr/bin/tput rmso) # end smso
UL=$(/usr/bin/tput smul) # underline
EE=$(/usr/bin/tput sgr0) # end enhancements

# Setup the prompt string $PS1
if [ "$(/usr/bin/id -u)" = "0" ]
then
SUFFIX="#"
else
SUFFIX="$"
fi
HN=$(/usr/bin/hostname)
PS1='${HV}${HN} ${IV}${PWD##${PWD%/*/*}/}${EE} ${SUFFIX} '

Now this strange PS1 will produce a half-bright, inverse-video string for the hostname, and full inverse-video for the current and parent directory. Since tput pays attention to the $TERM value, you can use any terminal (or emulator) and simply set $TERM to match. For the half-bright enhancement to show up, your emulator must support that feature.

Note that several (the majority) of HP terminal information (terminfo) entries in HP-UX have the wrong code for the smso enhancement (half-bright inverse-video). Since all HP terminals built since 1979 (the HP 2640A) have this feature, you can edit the terminfo database using untic and tic to add the correct code. Here's a way to test:

TERM=hp
echo "$(tput smso) half-bright=smso $(tput bold) inverse=bold"

TERM=2392a
echo "$(tput smso) half-bright=smso $(tput bold) inverse=bold"

You can see that the halfbright enhancement changes with 2392a.

As always, your mileage will vary with non-HP terminals...some have all the enhancements, others do not. Use untic and grep to search for the features.


Bill Hassell, sysadmin
Geetam
Frequent Advisor

Re: change clours in telnet session

Alan's answer, Richard's second answer and the first part of Bill's answer rely on using the right icon or session to
begin with and initiate the right environment (and not
change it). The problem it that this offers the option of
'user variation'.

Bruce and Bill (second part) are on the same track as
Dan's earlier answer and are going in the direction I
want to go. Specially Bill's comprehensive answer is
appreciated (I will assign points, honestly!). But it has a
limited range appearances: I think Bill's list gives most of
the options. But I need more: at least 4 clearly different schemes, without making them difficult to read (Health
and Safety eliminates underlines, I think)

Therefore I need colours. I think Reflection/1 and
Reflection/2 are similar to Reflection for Unix; Reflection
for Unix (and Digital) is now included with Reflection/X. As
some of our friends have indicated already, it is possible
to set the colours as a configuration option on the
MSwindows side of the application. I am looking for a
way to change the colours in response to
events/scripts/commands in the Unix environment (like
tput (using terminfo) or echo "\\033[xxx\\c" (direct to
terminal) ).

Am I looking for the impossible?

I know the VT100 does not have colour, but VT320 and
VT420 do, don't they? Reflection for Unix emulates VT400.
Impossible...?
Bill Hassell
Honored Contributor

Re: change clours in telnet session

The man pages for terminfo give some cryptic codes for colors but the details are a bit fuzzy. If you can use an hpterm Xwindow, here are the colors for text in hpterm:

for COLOR in 0 1 2 3 4 5 6 7
do
echo "\033&v${COLOR}S Color $COLOR test"
done

These escape sequences modify the text in hpterm and also the background if you add video enhancements:

HB=$(/usr/bin/tput dim) # dim text
HV=$(/usr/bin/tput smso) # 1/2 bright inverse
IV=$(/usr/bin/tput bold) # inverse
for COLOR in 0 1 2 3 4 5 6 7
do
echo "\033&v${COLOR}S Color $COLOR $IV inverse $HV inverse-dim $HB dim "
done

I don't have the Reflection/X version of Reflection for Unix but if you look at the online help, it should give some details about how to control colors.


Bill Hassell, sysadmin
Bill Hassell
Honored Contributor

Re: change clours in telnet session

In doing some research, one of our engineers came up with a short script that sets colors on dtterm (and supposedly other ANSI-style emulators). The DEC VT-series (and Reflection for Unix) may respond also:

#!/usr/bin/sh
typeset -i NUM=29
while [ $NUM -lt 50 ]
do
echo "\033[${NUM}mIndex $NUM is this color"
NUM=$(( NUM + 1 ))
done
echo "\033[m"

Unlike hpterm, video enhancements such as inverse) do not change the color (foreground or background). This may be what you are looking for.


Bill Hassell, sysadmin
Bruce Regittko_1
Esteemed Contributor

Re: change clours in telnet session

Here is a script that works with a dtterm that is from HP's POSIX Shell Programming course. You may need to use different cap values (setaf) for the tput command for other terminals.

--------------cut--------------
# cat color_text
#!/usr/bin/sh
# color_text.sh

# TERM=dtterm
# setaf for foreground color, setab for background
bla="$( tput setaf 0 )"
red="$( tput setaf 1 )"
gre="$( tput setaf 2 )"
yel="$( tput setaf 3 )"
blu="$( tput setaf 4 )"
pur="$( tput setaf 5 )"
cya="$( tput setaf 6 )"
whi="$( tput setaf 7 )"
off="$( tput sgr0 )"

print "${yel}Follow the Yellow Brick Road ${off}"

print "${gre}The grass is always greener...${off}"

print "${pur}Purple is ${red}RED ${cya}& ${blu}BLUE"

print "Good movies are ${bla}BLACK ${off}& ${whi}WHITE"

# turn off all special effects before exit (normal mode)
print "$off"
exit
--------------cut---------------------

Hope this helps,

--Bruce
www.stratech.com/training
Geetam
Frequent Advisor

Re: change clours in telnet session

Though I appreciate the script-ideas given in the last few answers, they are all relating to an x-terminal session. My question is specificly about telnet (vt400 emulation)

(I find x-terminals a lot slower then telnet, and I still have not got to grips with cutting and pasting between MS-windows and X-windows)
Carlos Fernandez Riera
Honored Contributor

Re: change clours in telnet session


Hi:

Im trying Reflection for Unix and Digital.

I can change my background color following this steps:

1- In Reflection set terminal as SCO-ansi

2- Login

3- TERM=ansi50

4- tput setb 2

now my backuground is green.

Terminfo can manage color pairs too . See man terminfo.

Hope this helps
unsupported
Geetam
Frequent Advisor

Re: change clours in telnet session

Carlos

That sounds very hopefull, but I tried it:

I set the terminal type in Relfection to SCO-ansi

When logging in the .profile is not setting TERM right (not your problem, my .profile !)

Here is what happened:
Gt $ export TERM=ansi50
Gt $ vi test.sh
ansi50: Unknown terminal type
[snip]
Gt $ tput setb 2
tput: unknown terminal "ansi50"
Gt $

The background has not changed.

Can you explain a bit more, so I can try to adapt it. I had a look at man terminfo, but there is too much stuff that is not relevant (there may be a 'needle in the haystack')

Thanks
Carlos Fernandez Riera
Honored Contributor

Re: change clours in telnet session

Yes:

terminfo databases is on /usr/share/lib/terminfo/#/#term

this is /usr/share/lib/terminfo/a/ansi50

Attached file is an untic of my ansi50 terminal

Copy on your box as /tmp/ansi50.tic and run tic /tmp/ansi50.tic


Well. try now again.
unsupported
Dan Hetzel
Honored Contributor

Re: change clours in telnet session

Hi Geetam,

The terminal ansi50 isn't defined in /usr/lib/terminfo/a, so it's normal that you get this message.

Set your terminal to 'ansi' and it should work.
# export TERM=ansi
and both 'vi' and 'tput' should stop complaining !

Dan

Everybody knows at least one thing worth sharing -- mailto:dan.hetzel@wildcroft.com
Carlos Fernandez Riera
Honored Contributor

Re: change clours in telnet session

Dan: Now i am asking myself why there is a ansi50 in my database....

But in fact it dont mind.

The secrect is setb, setf, ccc ( can change color) and others entrys in compiled terminal definitions.

You can also untic you ansi and add lines for these and then tic again.

For vt400: see on terminal manual escape secuences for color background
untic vt400 > /tmp/vt400.tic
and insert that entrys
and tic /tmp/vt400.tic.

For debug you can export TERMINFO=/tmp before tic anything to be save. $TERMINFO is new path to terminfo databases.

unsupported