I don't seem to be able to find any examples on the Internet for this environment variable, which top
will apparently read and use to display colours.
How would I set this variable correctly so top
used alternate colours in its output?
I have Solaris top
version 3.5beta9.
Best Answer
The TOPCOLORS variable in this
top
(also referred to as unixtop) is not available in the version you are using. It first appeared in version 3.6 of this utility, as stated in the COLOR section of the README file. For some reason, it seems that the usual BSD don't include an updated version of top (FreeBSD 9.1 has 3.5beta12).If you can install or compile an updated version, the man page should give you more information on how to set colours. In version 3.8beta1 that is what it prints:
TOPCOLORS
Specifies colors to use and conditions for which they should be used. At the present time, only numbers in the summary display area can be colored. In a future version it will be possible to highlight numbers in the process display area as well. The environment variable is the only way to specify color: there is no equivalent command line option. Note that the environment variable TOPCOLOURS is also understood. The British spelling takes precedence. The use of color only works on terminals that understand and process ANSI color escape sequences.
The environment variable is a sequence of color specifications, separated by colons. Each specification takes the form
tag=min,max#code
wheretag
is the name of the value to check,min
andmax
specify a range for the value, andcode
is an ANSI color code.Multiple color codes can be listed and separated with semi-colons. A missing
min
implies the lowest possible value (usually 0) and a missingmax
implies infinity. The comma must always be present.When specifying numbers for load averages, they should be multiplied by 100. For example, the specification:
1min=500,1000#31
indicates that a 1 minute load average between 5 and 10 should be displayed in red.Color attributes can be combined. For example, the specification:
5min=1000,#37;41
indicates that a 5 minute load average higher than 10 should be displayed with white characters on a red background.A special tag named
header
is used to control the color of the header for process display. It should be specified with no lower and upper limits, specificallyheader=,#
followed by the ANSI color code.You can see a list of color codes recognized by this installation of top with the
-T
option. This will also show the current set of tests used for color highligting, as specified in the environment.(end of man page extract)
Colour Codes
The
color.h
file from the source code list the tags and codes the utility understands. The tags are:And the color are the ANSI ones:
Example
Using the following setup, you can get a glimpse at the possibilities (here for top 3.8beta1 compiled on FreeBSD):
A call to
top -T
will directly show you if top understands the color setup you've declared. It will also list all the tags understood (which in my case where somewhat different from the content of thecolor.h
file).Alternatives
On different UNIX systems, alternatives are used. Under Linux you usually find the
top
utility coming from the procps package. You can also install htop which is a nice colourful alternative that is also available on OSX and FreeBSD (where it relies on the Linux layer), but AFAIK not on Solaris.