home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 13 / CDA13.ISO / DOC / HOWTO / MINI / COLOUR_L < prev    next >
Encoding:
Text File  |  1996-05-04  |  8.4 KB  |  235 lines

  1.   Colours with Linux terminals
  2.   Thorbj°rn Ravn Andersen, ravn@dit.ou.dk
  3.   $Date: 1996/04/27 16:56:15 $
  4.  
  5.   Most Linux distributions have a 'ls' command that supports colours,
  6.   and it is often desired to have different colours than the default but
  7.   this may not be a trivial task.  This document explains the various
  8.   aspects and approaches of altering the setup by configuring existing
  9.   software, plus locations of alternative software not included with
  10.   Slackware.  The HTML version is also available from my own source
  11.   <http://www.dit.ou.dk/~ravn/colour-ls>.
  12.  
  13.   1.  Introduction
  14.  
  15.   Most Linux distributions have a 'ls' command that supports colours,
  16.   and it is often desired to have different colours than the default but
  17.   this may not be a trivial task.  This document explains the various
  18.   aspects and approaches of altering the setup by configuring existing
  19.   software, plus locations of alternative software not included with
  20.   Slackware.
  21.  
  22.   This revision is a major rewrite from the initial release, including
  23.   information on xterms and kernel patching.
  24.  
  25.   The information in here was originally compiled with the 2.0.2 release
  26.   of Slackware, and the 1.1.54 kernel.  The kernel patch information was
  27.   retrieved on slackware 2.2.0 with the 1.2.13 kernel, and tcsh as the
  28.   default shell.
  29.  
  30.   2.  Which colours to choose from.
  31.  
  32.   This shell script (thanks to the many who sent me bash versions) shows
  33.   all standard colour combinations on the current console.  If no
  34.   colours appear, your console does not support ANSI colour selections.
  35.  
  36.        #!/bin/bash
  37.        # Display ANSI colours.
  38.        #
  39.        esc="\033["
  40.        echo -e "\t  40\t   41\t   42\t    43\t      44       45\t46\t 47"
  41.        for fore in 30 31 32 33 34 35 36 37; do
  42.          line1="$fore  "
  43.          line2="    "
  44.          for back in 40 41 42 43 44 45 46 47; do
  45.            line1="${line1}${esc}${back};${fore}m Normal  ${esc}0m"
  46.            line2="${line2}${esc}${back};${fore};1m Bold    ${esc}0m"
  47.          done
  48.          echo -e "$line1\n$line2"
  49.        done
  50.  
  51.   The foreground colour number is listed to the left, and the background
  52.   number in the box.  If you want bold characters you add a "1" to the
  53.   parameters, so bright blue on white would be "30;40;1".  The whole
  54.   ANSI selection sequence is then
  55.  
  56.   ESC [ 3 0 ; 4 0 ; 1 m
  57.  
  58.   Note: The background currently cannot be bold, so you cannot have
  59.   yellow (bold brown) as anything but foreground.  This is a hardware
  60.   limitation.
  61.  
  62.   3.  How to configure colours with ls
  63.  
  64.   The standard Slackware setup creates the environment variable
  65.   LS_COLORS from the
  66.  
  67.   $HOME/.dir_colors
  68.  
  69.   system standard).  The LS_COLORS looks like
  70.  
  71.        LS_COLORS=:no=00:fi=00:di=01:ln=01;36:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:..
  72.  
  73.   If you want a setup different from the standard, copy /etc/DIR_COLORS
  74.   to
  75.  
  76.   $HOME/.dir_colors
  77.  
  78.   seen with the script above.  Use
  79.  
  80.          eval `dircolors -t` # set up color-ls variables
  81.  
  82.   to recalculate LS_COLORS with tcsh.  See dircolors(1) for details.
  83.  
  84.   Note:  If you use a 'ls' from a version of Slackware before 2.2, you
  85.   should upgrade.  It is buggy.
  86.  
  87.   4.  How to configure another default than white-on-black
  88.  
  89.   You will need to tell the terminal driver code that you want another
  90.   default.  There exists no standard way of doing this, but in case of
  91.   Linux you have the setterm program.
  92.  
  93.   "setterm" uses the information in the terminal database to set the
  94.   attributes.  Selections are done like
  95.  
  96.        setterm -foreground black -background white -store
  97.  
  98.   where the "-store" makes it the default for the current console as
  99.   well.  This requires that the current terminal (TERM environment
  100.   variable) is described "well enough" in the termcap database.  If you
  101.   are out of luck, well here is the gory details:
  102.  
  103.   4.1.  Xterm
  104.  
  105.   Use one of
  106.  
  107.        xterm -fg white -bg blue4
  108.        color_xterm -fg white -bg blue4
  109.  
  110.   where 'color_xterm' supports the colour version of 'ls'.  This
  111.   particular choice resembles the colours used on an SGI.
  112.  
  113.   4.2.  Virtual console.
  114.  
  115.   You may modify the kernel once and for all, as well as providing a
  116.   run-time default for the virtual consoles with an escape sequence.  I
  117.   strongly recommend the kernel patch if you have compiled your own
  118.   kernel.
  119.  
  120.   The kernel source file is /usr/src/linux/drivers/char/console.c around
  121.   line 1800, where you should modify
  122.  
  123.                def_color       = 0x07;   /* white */
  124.                ulcolor         = 0x0f;   /* bold white */
  125.                halfcolor       = 0x08;   /* grey */
  126.  
  127.   as appropriate.  I use white on blue with
  128.  
  129.                def_color       = 0x17;   /* white */
  130.                ulcolor         = 0x1f;   /* bold white */
  131.                halfcolor       = 0x18;   /* grey */
  132.  
  133.   The numbers are the attribute codes used by the video card: the most
  134.   significant digit (the "1" in the colours) is the background; the
  135.   least significant the foreground. 0 = black, 1 = blue, 2 = green, 3 =
  136.   cyan, 4 = red, 5 = purple, 6 = brown/yellow, 7 = white. Add 8 to get
  137.   "bright" colours. Note that, in most cases, a bright background ==
  138.   blinking characters, dull background. (From
  139.   sjlam1@mda023.cc.monash.edu.au).
  140.  
  141.   You may also supply a new run-time default for a virtual console, on a
  142.   per-display basis with the non-standard ANSI sequence (found by
  143.   browsing the kernel sources)
  144.  
  145.           ESC [ 8 ]
  146.  
  147.   which sets the default to the current fore- and background colours.
  148.   Then the Reset Attributes string (ESC [ m) selects these colours
  149.   instead of white on black.
  150.  
  151.   You will need to actually echo this string to the console each time
  152.   you reboot.  Depending on what you use your Linux box for, several
  153.   places may be appropriate:
  154.  
  155.   4.2.1.  /etc/issue
  156.  
  157.   This is where "Welcome to Linux xx.yy" is displayed under Slackware,
  158.   and that is a good choice for stand-alone equipment (and probably be a
  159.   pestilence for users logging in with rlogin).  This file is created by
  160.   /etc/rc.d/rc.S at boot time, and you should modify (around line 75)
  161.  
  162.          echo ""> /etc/issue
  163.          echo Welcome to Linux `/bin/uname -a | /bin/cut -d\  -f3`. >> /etc/issue
  164.  
  165.   to
  166.  
  167.          ESCAPE="<replace with a single escape character here>"
  168.          echo "${ESCAPE}[H${ESCAPE}[37;44m${ESCAPE}[8]${ESCAPE}[2J"> /etc/issue
  169.          echo Welcome to Linux `/bin/uname -a | /bin/cut -d\  -f3`. >> /etc/issue
  170.  
  171.   This code will home the cursor, set the colour (here white on blue),
  172.   save this selection and clean the rest of the screen.  The
  173.   modification takes effect after the next reboot.  Remember to insert
  174.   the _literal_ escape character in the file with C-q in emacs or
  175.   control-v in vi, as apparently the sh used for executing this script
  176.   does not understand the /033 syntax.
  177.  
  178.   4.2.2.  /etc/profile or .profile
  179.  
  180.          if [ "$TERM" = "console" ]; then
  181.              echo "\033[37;44m\033[8]" #
  182.        # or use setterm.
  183.              setterm -foreground white -background blue -store
  184.          fi
  185.  
  186.   4.2.3.  /etc/login or .login
  187.  
  188.     if ( "$TERM" == "console" ) then
  189.       echo "\033[37;44m\033[8]"
  190.   # or use setterm.
  191.         setterm -foreground white -background blue -store
  192.     endif
  193.  
  194.   4.3.  Remote login
  195.  
  196.   You should be able to use the setterm program as shown above.  Again,
  197.   this requires that the remote machine knows enough about your
  198.   terminal, and that the terminal emulator providing the login supports
  199.   colour.
  200.  
  201.   If you encounter a successful combination, I would like to have it
  202.   here.
  203.  
  204.   5.  Software
  205.  
  206.   All the information described here is assuming a Slackware
  207.   installation.  If you have something else (like e.g. a Sun running X
  208.   or so) you can get and compile the actual software yourself.
  209.  
  210.   The colour version of 'xterm' is based on the standard xterm source
  211.   with a patch available from any X11R6 site.
  212.  
  213.        ftp://ftp.denet.dk/pub/X11/contrib/utilities/color-xterm-R6pl5-patch.gz
  214.  
  215.   See the documentation if you use an older version of X.  Note: I
  216.   haven't tried this myself!
  217.  
  218.   of the several mirrors.  You need the package plus a patch.
  219.  
  220.        ftp://ftp.denet.dk/pub/gnu/fileutils-3.12.tar.gz
  221.        ftp://ftp.funet.fi/pub/Linux/sunsite/utils/file/color-ls-3.12.0.3.patch.gz
  222.  
  223.   I have myself successfully compiled color-ls on Solaris, SunOS and
  224.   Irix.  Note that the patch requires a recent version of the patch
  225.   program (pointers to source?) and you may find it the most easy to
  226.   untar and patch on a Linux system and then move the source.
  227.  
  228.   I would appreciate feedback on this text.  My e-mail address is
  229.   ravn@dit.ou.dk <mailto:ravn@dit.ou.dk>
  230.  
  231.   ---
  232.  
  233.   Thorbj°rn Ravn Andersen
  234.  
  235.