home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / HOWTO / MINI / COLOUR-L < prev    next >
Encoding:
Text File  |  1995-04-20  |  6.1 KB  |  182 lines

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