[TAG] Colouring $PS1...
Benjamin A. Okopnik
ben at linuxgazette.net
Tue Jun 6 02:19:43 MSD 2006
On Wed, May 31, 2006 at 02:46:26AM -0700, Mahesh Aravind wrote:
> --- Thomas Adam <thomas at edulinux.homeunix.org> wrote:
>
> > There's nothing wrong with it, but hard-coding escape codes is going to
> > turn around and bite you on the arse before long. Some terminals
> > don't/can't render escape codes properly.
>
> Just out of curiosity, how would a modified script using tput(1) would be able
> to print the colour coordinates to the o/p?
Just like using escape codes does - except you don't use the escape
codes. :) The point to 'tput' is that it actually queries the terminfo
database and outputs the _correct_ escape codes for a given terminal.
Using explicit escape codes will work much of the time - after all, many
Un*x terminals use the same ones - but will fail miserably on terminals
that use something different.
If you're asking about an example, here's one:
```
tput smso # Turn on bold mode
echo This should print in bold
tput rmso # Turn it off
'''
On the other hand, if you use these a lot, you're going to get tired of
typing - so it makes sense to request them once and save them:
```
a=`tput smso`
b=`tput rmso`
echo "${a}This should print in bold$b"
'''
> And how would you create (a hacked up version) of files like, say, /etc/issue
> using tput w/o using hard coded escape codes?
Those are not _terminal_ codes, they're 'getty'-specific escape codes;
no relation between the two. Yes, it's possible to use ASCII escapes to
create lots of special effects; heck, I used to do that myself, back in
the early '80s for BBS "post-login" screens. I just seriously doubt that
this hack from 25 year ago is still in any way "cool", or even
interesting - and this is filtered through the fact that it's guaranteed
to break on some percentage of terminals.
As a side note, I suspect that 'getty' replicates a fair amount of
'tput' functionality, since it has to deal with terminals at that level.
* Ben Okopnik * Editor-in-Chief, Linux Gazette * http://linuxgazette.net *
More information about the TAG
mailing list