Date: Fri, 3 Oct 2003 10:55:18 +0300 From: Peter Pentchev <roam@ringlet.net> To: Gerald S Stoller <gs_stoller@juno.com> Cc: FreeBSD-doc@FreeBSD.ORG Subject: Re: color in messages Message-ID: <20031003075518.GE546@straylight.oblivion.bg> In-Reply-To: <20031002.120620.-165803.0.GS_Stoller@juno.com> References: <20031002.120620.-165803.0.GS_Stoller@juno.com>
next in thread | previous in thread | raw e-mail | index | archive | help
--eRtJSFbw+EEWtPj3 Content-Type: text/plain; charset=windows-1251 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Oct 01, 2003 at 07:33:05PM -0400, Gerald S Stoller wrote: > It is possible to put color in the FreeBSD messages, I have > seen the font color change when I used 'ls -G'. I would also like to > change the color of the background. Unfortunately i have seen no > documentation on how to do this. May i suggest that something brief be > written about this so people can start using color (ASAP) and send me a > copy, then do a more extensive version (if needed for a formal release. > I tried to find special characters in the output of 'ls -G' by > piping it through a tee but it seems that ls checks on the > destination of its STDOUT and if it not directly to the screen it > removes the color modifying code from it. Were i to have coded ls , I > would leave the color modifying code always in the output and maybe > provide another utiliity that removes it through which one could pipe the > output if one wanted the color modifying code removed. > Probably this question is better directed at the XFree86 people > but I haven't gotten a good reply from them. No, not exactly XFree86. Using colors in a terminal window predates XFree86 (and even the X Window System) by a long shot :) There are basically two ways for a program to display text in a different color (or background): the easy, but possibly very, very wrong way of using ANSI (CSI) escape sequences directly, and the somewhat harder, but much more portable and mostly guaranteed to work better way of querying the database of terminal capabilities. The ANSI escape sequences are a more or less established standard for common ways for a program to control its output on most terminals out there. They consist of sending an Escape character (ASCII code 27, 0x1C) followed by a '[' character, then some optional parameters, and a command character (usually a letter). For a list of the available commands see e.g. <URL:http://www.vmunix.com/~gabor/ansi.html>. However, using ANSI escape sequences unconditionally may be a Bad Thing(tm) on a terminal that does not support them - it will either output lots and lots of garbage (quite confusing for the user), or it might even interpret the sequences as some different set of commands and do something entirely unexpected. Most terminals out there support most ANSI sequences, but.. be warned :) The better, more portable way to do this would be to see if the OS (or rather, its application libraries such as libc) supports the termcap database - a unified database of information about the display capabilities of a wide range of terminals. This is done using the tgetent() and similar functions, described in the termcap(3) manual page. The basic idea is that the database contains an entry for each of the common (and some quite uncommon) terminal types as defined by the TERM environment variable, so that the program knows whether the terminal can e.g. change colors or move the cursor to a desired position or change characters and so on, and what exactly is the character sequence that will make it do so. For more information on the termcap database, take a look at <URL:http://www.cs.utah.edu/dept/old/texinfo/termcap/termcap_toc.html>. Hope this helped a bit :) G'luck, Peter --=20 Peter Pentchev roam@ringlet.net roam@sbnd.net roam@FreeBSD.org PGP key: http://people.FreeBSD.org/~roam/roam.key.asc Key fingerprint FDBA FD79 C26F 3C51 C95E DF9E ED18 B68D 1619 4553 The rest of this sentence is written in Thailand, on --eRtJSFbw+EEWtPj3 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.3 (FreeBSD) iD8DBQE/fStm7Ri2jRYZRVMRAhbdAKCfGoJu/EsSu9JPnq/4uykFT32yIQCeM0/Y 17ilYYDqvI1vqwlYDE/q4bI= =Lj/5 -----END PGP SIGNATURE----- --eRtJSFbw+EEWtPj3--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20031003075518.GE546>