1763587 Members
3264 Online
108913 Solutions
New Discussion юеВ

Determine terminal type

 
SOLVED
Go to solution
James Kirk_1
Occasional Contributor

Determine terminal type

Hi,

Is there a way to determine the kind of terminal in use? I don't mean simply $TERM but rather a way of asking the terminal itself?

Thanks,
Jim
10 REPLIES 10
A. Clay Stephenson
Acclaimed Contributor

Re: Determine terminal type

Well, that sort of a chicken and egg problem. If you knew what kind of terminal it was, you could send the proper string to ask it.

There is something of a solution:
TTYPE=$(tset -)
echo "Terminal Type = ${TTYPE}"

man tset for details. The man pages may also give you ideas for other approaches. In general, the most foolproof way is to present the user with choices in the .profile and ask.
If it ain't broke, I can fix that.
Kenneth Platz
Esteemed Contributor

Re: Determine terminal type

The "ttytype" command will interrogate your terminal.

# ttytype -a -s
TERM='vt200'; export TERM;
LINES=24; export LINES;
COLUMNS=80; export COLUMNS;
ERASE='^?'; export ERASE;

Just do an eval $( ttytype -a -s ) and you're good to go.
I think, therefore I am... I think!
Jeff Schussele
Honored Contributor

Re: Determine terminal type

Hi Jim,

Use tset as follows

tset -

HTH,
Jeff

"Captain! She just can't take any more!"
Bet you get tired of hearing that all the time....
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Determine terminal type

Before using the ttytype command, carefully read the warnings section. If an unexpected terminal type is encountered the inquiry strings can send the terminal into La-La Land. This is what I alluded to in my first response. If you know that you will only be dealing with terminals or terminal emulators that ttytype supports then use it but otherwise the safe play is to always ask.
If it ain't broke, I can fix that.
Bill Hassell
Honored Contributor

Re: Determine terminal type

Determining (automatically) what type of terminal you are using is a guessing game. The ttytype command is about the best you'll get in testing the terminal. Here's how it works:

There are about 3 major categories of terminal emulations, ANSI/vt, Wyse and HP. ANSI terminals are similar to vt (which is a shorthand way of saying VT-series of terminals made by DEC a couple decades ago). These are not truly 'dumb' as they can answer questions, or more accurately, respond to certain escape sequences. And each of the 3 categories of terminals has a specific set of strings that cause the terminal to reply automatically. Most of these strings return some sort of ID and ttytype will often perform additional queries once the category is discovered. The order of test is:

Wyse
ANSI and VT
HP

ttytype waits for one second to see if the terminal responds and if not, assumes it is not compatible with that test and tries another query. During that time, you may see semi-random characters on the screen which don't mean anything to the terminal. If the qery works, the sequence (and response) are invisible. The actual escape sequences are:

.ESC i
.ESC[ci
.ESC*s1DC1i

where ESC is the escape character and DC1 is device control 1, used for handshaking in HP's commercial opsystem, MPE.

Therein lies the two-edged sword. One sequence will make a Wyse terminal respond with a valid ID but connect a VT-420 and the terminal will lock up due to it's unique response to an incompatible query.

So you need to check all the possible terminals (and emulators) you'll be using to see if ttytype locks any of them. Another technique is to specify only the family that you are using:

eval $(ttytype -t ansi -t hp -s)

This will cut down the test time by one second and since almost no one uses Wyse terminals or emulators, you won't miss anything by eliminating the Wyse test, and will likely eliminate terminal lockups (HP terminals and emulators reliably ignore the ansi test sequence.


Bill Hassell, sysadmin
James Kirk_1
Occasional Contributor

Re: Determine terminal type

Hi Guys:

Thanks for the ideas. I have a few users who access the system using modems connected to Televideo 925's. Those are the terminals that are giving me the most trouble. I also have problems when using reverse video on those terminals.

Thanks for your help,
Jim
A. Clay Stephenson
Acclaimed Contributor

Re: Determine terminal type

I don't think I've seen a tvi925 since the 1980's -- and they were klunkers then. You have managed to find a terminal with the "magic cookie glitch" and I'll bet that is the source of your problem. Untic tvi925 and make sure that xmc#1 is set. Back in the days when memory was expensive, terminals sometimes stored attributes in blank characters that preceded the data. For example, suppose you wanted to hilight "I'm with Stupid" by displaying it in reverse video. You would first send the sequence
for reverse video. That would drop a "magic cookie" at the current location. Any text received after that would be in reverse video until a 2nd magic cookie was dropped turning off video.

The other (better) method was to carry attributes for each display character in the character itself. This required more terminal memory but screen space was not wasted.

If it ain't broke, I can fix that.
Jeff Schussele
Honored Contributor

Re: Determine terminal type

Hi Jim,

I, too, haven't seen a TVIXXX for quite some time. But I *think* they had VT100 & maybe even Wyse emulation. You could try setting it to VT100 & make your problems go away.

Rgds,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Bill Hassell
Honored Contributor

Re: Determine terminal type

If you can find a TechRef manual for the Televideo, run ttytype -s to report on the terminal type, then use the untic command to display the results. If the terminal has alternate modes (Wyse, ANSI, VT, etc), try one of those since the new mode should handle escape codes differently. I've attached a simple script to demonstrate the 5 most common video enhancements for terminals, along with their Curses/terminfo names. It first uses ttytype to ID the terminal, then using the TERM value discovered by ttytype, displays the 5 enhancement modes. The script shows how to use tput to test or use enhancements in a script.

This all assumes that the application program is using the Curses library or tput to display inverse video. If the program uses hard-coded escape sequences imbedded in the program, fire the programmer and get someone that knows there are better ways to handle terminals.


Bill Hassell, sysadmin