home *** CD-ROM | disk | FTP | other *** search
/ Caldera Network Desktop 1.0 / caldera-network-desktop-1.0.bin / doc / HOWTO / mini / Colour-ls < prev    next >
Text File  |  1995-05-07  |  6KB  |  180 lines

  1. $Id: MINI-colour,v 1.4 1994/12/05 19:10:26 ravn Exp $
  2.   
  3.   Thorbjoern Ravn Andersen
  4.   ravn@imada.ou.dk
  5.  
  6.   A standard installation of Linux with Slackware [*] enables colours with
  7. the 'ls' command.  Sometimes you wish to use other colours than the
  8. default, but this is hard to do with a non-black background.  This
  9. mini-howto explains which standard escape codes to use and where to use
  10. them.
  11.  
  12. [* The information in here was compiled with the 2.0.2 release of
  13. Slackware, and the 1.1.54 kernel. It works both with agetty and mgetty_ps.]
  14.  
  15.  
  16. 1) How to select colours?
  17.  
  18. Essentially you have two choices:
  19.  
  20. Method 1: Use the setterm program which is fine if you just need a quick
  21. change.  The helpscreen and man page are cryptic, so here you are somewhat
  22. on your own. [If somebody has an adequate description I would love to read
  23. it].
  24.  
  25. Selections are done like
  26.  
  27.     "setterm -foreground black -background white -store"
  28.  
  29. where the "-store" makes it the default for the current console.  This
  30. needs to be done for each virtual console you want to change, so a good
  31. place might be in your .login file.  Now you know as much as I do about
  32. setterm. :-)
  33.  
  34.  
  35. Metod 2: Linux uses ANSI escape codes of the form
  36.  
  37.   ESC [ <parameters> m
  38.  
  39. where ESC is ASCII 27 and <parameters> are zero or more numbers separated
  40. with semi-colons.  Valid examples might be
  41.  
  42.   "\033[41;33;1m" which results in bright yellow on red,
  43.   "\033[30;47m"   which results in white on black, and
  44.   "\033[m"        which restores the default colour set.
  45.  
  46. These examples requires that the shell in question recognizes the \xxx
  47. construction.  If not, just insert an escape character directly in the
  48. string.  In bash/vi type Ctrl-V ESC, and in tcsh/emacs type Ctrl-Q ESC.
  49.  
  50.  
  51. 2) What colour combinations are available?
  52.  
  53.   This c-shell script shows all colour combinations on the current console:
  54.  
  55. ------------------- CUT HERE-----------
  56. #!/bin/csh
  57. #
  58. # Display ANSI colours. /ravn 941129
  59. #
  60. set esc="\033["
  61. foreach fore (30 31 32 33 34 35 36 37)
  62.   set line1="$fore  " line2="    " 
  63.   foreach back (40 41 42 43 44 45 46 47)
  64.     set line1="${line1}${esc}${back};${fore}m Normal  ${esc}0m"
  65.     set line2="${line2}${esc}${back};${fore};1m ${back} Bold ${esc}0m"
  66.   end
  67.   echo "$line1\n$line2"
  68. end
  69. ------------------- CUT HERE-----------
  70.  
  71.   The foreground colour number is listed to the left, and the background
  72. number in the box.  If you want bold you add a "1" to the parameters.  Put
  73. semi colons in between, and plug it in the <parameters> part above.
  74.  
  75. Note: The background cannot be bold, so you cannot have yellow (bold brown)
  76. as a background.
  77.  
  78.  
  79. 3) How to make 'ls' select colours.
  80.  
  81.   The colourised 'ls' command looks for the configuration in
  82. "~/.dir_colors", and failing that in "/etc/DIR_COLORS".  It contains a lot
  83. of entries like
  84.  
  85.     LINK 36;1           # symbolic link
  86.     FIFO 40;33          # pipe
  87.     SOCK 41;01;35       # socket
  88.     BLK 41;33;01        # block device driver
  89.     CHR 41;33;01        # character device driver
  90.  
  91.     # This is for files with execute permission:
  92.     EXEC 32;1
  93.  
  94. which is exactly the <parameters> part from the ANSI sequence.
  95.  
  96. Alter these as you wish.  See the result with '/sbin', '/etc', and '/dev'.
  97.  
  98.  
  99. 4) How to set a default colour set.
  100.  
  101.   This is set individually for each virtual console, with the ANSI sequence
  102. [**]
  103.     ESC [ 8 ]
  104.  
  105. which sets the default to the current fore- and background colours.  Then
  106. the Reset Attributes string (ESC [ m) selects these colours instead of
  107. white on black.
  108.  
  109. [** This information was found by browsing the kernel source.  I don't know
  110. whether this is standard.]
  111.  
  112.   The method described below is primarily intended for stand-alone systems,
  113. in the sense that logins *only* happen on the console.  There should not be
  114. any logins from terminals, modems or other machines, as they may not
  115. understand the sequences added.
  116.  
  117.  
  118.   On a *stand-alone* Linux system a good file is "/etc/issue", so edit this file directly and check the result by typing
  119. Ctrl-D to a login prompt.  If you have a standard Slackware installation
  120. this file is rewritten each time the system is rebooted, so if your
  121. "/etc/rc.d/rc.S" contains lines looking like (around line 75)
  122.  
  123.   # Setup the /etc/issue and /etc/motd to reflect the current kernel level:
  124.   # THESE WIPE ANY CHANGES YOU MAKE TO /ETC/ISSUE AND /ETC/MOTD WITH EACH
  125.   # BOOT. COMMENT THEM OUT IF YOU WANT TO MAKE CUSTOM VERSIONS.
  126.   echo ""> /etc/issue
  127.   echo Welcome to Linux `/bin/uname -a | /bin/cut -d\  -f3`. >> /etc/issue
  128.   echo >> /etc/issue
  129.  
  130. you may want to either comment these out or replace the first echo line with
  131.  
  132. ...
  133.   # BOOT. COMMENT THEM OUT IF YOU WANT TO MAKE CUSTOM VERSIONS.
  134.   ESCAPE="<replace with a single escape character here>"
  135.   echo "${ESCAPE}[H${ESCAPE}[37;44m${ESCAPE}[8]${ESCAPE}[2J"> /etc/issue
  136. ...
  137.  
  138.   My startup-shell doesn't understand the "\033" so I must insert the ASCII
  139. code 27 literally in my script where indicated (as described in section 1).
  140. The line should then look like 'ESCAPE="^[" '.
  141.  
  142.   This code will home the cursor, set the colour (here white on blue), save
  143. this selection and clean the rest of the screen.  This modification takes
  144. effect after the next reboot.
  145.  
  146.  
  147.   If your Linux box *is not* stand-alone, you may have problems with remote
  148. users since their terminal probably cannot understand the sequences inserted
  149. above. 
  150.  
  151. Then you must make this user-based by adding it to your 
  152.  
  153. .profile (sh/bash)
  154.   if [ "$TERM" = "console" ]; then
  155.       echo "\033[37;44m\033[8]"
  156.   fi
  157.  
  158. .login (csh/tcsh)
  159.   if ( "$TERM" == "console" ) then
  160.     echo "\033[37;44m\033[8]"
  161.   endif
  162.  
  163. or system wide by modifying "/etc/profile" or "/etc/csh.login" as root.
  164. (Again, replace \033 with literate escapes if the shell cannot parse \xxx
  165. constructions)
  166.  
  167.  
  168. 6) Comments and criticism
  169.  
  170.   This is still a rough draft, and English isn't my primary language.
  171. Please feel free to correct me on the above text in order to make it as
  172. clear and correct as possible.  This goes, of course, for the information
  173. provided as well.
  174.  
  175. Comments and criticism goes to 
  176. --
  177.   Thorbjo/rn Ravn Andersen        "...and...Tubular Bells!"
  178.   ravn@imada.ou.dk         
  179.   <http://www.imada.ou.dk/~ravn>
  180.