I'm just wondering if this fairly reliable across most terminal types.
Do all the common real and virtual terminal types support ansi control
sequences?
TERM=linux,TERM=ansi,TERM=color,TERM=vt100,TERM=vt220,TERM=vt,TERM=rxvt,
TERM=xterm etc?
What about TERM=3270?
What terminals do not support ANSI sequences?
What does a monochrome terminal do if it receives a colour ansi sequence?
Mark.
--
Mark Hobley
Linux User: #370818 http://markhobley.yi.org/
> Do all the common real and virtual terminal types support ansi control
> sequences?
Rather then using ANSI control sequences defined in the script/program, find
the correct ones using tput.
This should work, as long as the terminal is properly defined in the terminfo
database. See "man tput" and "man terminfo" The following script may help.
#!/bin/bash
for ((ForegroundColorCurrent=0; ForegroundColorCurrent < 10; ForegroundColorCurrent++)); do
for ((BackgroundColorCurrent=0; BackgroundColorCurrent < 10; BackgroundColorCurrent++)); do
tput setaf $ForegroundColorCurrent
tput setab $BackgroundColorCurrent
echo ForegroundColorCurrent="$ForegroundColorCurrent", "BackgroundColorCurrent=$BackgroundColorCurrent"
done
done
See the "Colors using tput" section of
http://bash-hackers.org/wiki/doku.php/scripting/terminalcodes
Regards, Dave Hodgins
--
Change nomail.afraid.org to ody.ca to reply by email.
(nomail.afraid.org has been set up specifically for
use in usenet. Feel free to use it yourself.)
That's absolutely the wrong way to do it at least in the land of
UNIX(/Linux/BSD/etc.), and reinvention of a problem that was well
solved
over 3 decades ago. I can also guarantee that that approach will
generally fail rather miserably on my on my Cromemco 3102* terminal
and
my Qume QVT-102 terminal - at least in most of its modes (so yes, it
would generally fail on every actual physical terminal that I own).
So, in general, it won't work, and won't work for a large number of
terminals/emulations.
The correct way to do it is to use terminfo (or termcap in some cases,
e.g. old systems with termcap, but not terminfo). From shell, that
would typically be making use of tput.
On the system at my fingertips, I find approximately 2498 distinct
supported terminal types and some of their various main/distinct modes
and aliases defined, and among them, I find 137 distinct primary/best
means to clear their screen (at least for those that support such a
capability ... and even have a screen for that matter (generally not
applicable for hardcopy terminal)).
Some examples**:
$ tput clear || {
> 1>&2 echo "Don't know how to clear screen for TERM=$TERM"
> fail
> }
$ if tput setaf 1 || tput setf 4; then
> echo RED
> tput op || { 2>&1 echo 'tput op failed - stuck in RED?'; false; }
> else
> 2>&1 echo "Can't get red via tput setaf or tput setf"
> false
> fi
$ TERM=ansi-m
$ tput setaf 1 || tput setf 4 || {
> 1>&2 echo "Can't do that for TERM=$TERM"
> false
> }
Can't do that for TERM=ansi-m
$
*and yes, one can crash a Cromemco 3102 terminal by sending it
inappropriate control/escape sequences (such as the one that
essentially
says interpret the following as hex data, load and execute it).
**for illustrative purposes only - no guarantees to be sufficiently
robust/complete for production purposes
> That's absolutely the wrong way to do it at least in the land of
> UNIX(/Linux/BSD/etc.), and reinvention of a problem that was well
> solved over 3 decades ago.
Right, OK. I have encountered these on certain applications, so I will rip
these out and try to recode them.
Cheers,
Unfortunately, tput is not consistent from one system to another.
The support of ANSI sequences is all but universal these days, so
you are likely to be more portable using ANSI sequences than
tput.
--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
I don't have an answer to your questions but there is a
comp.terminals newsgroup and it sounds as if your
questions have a better chance of getting answered there.