home *** CD-ROM | disk | FTP | other *** search
/ BURKS 2 / BURKS_AUG97.ISO / BURKS / LINUX / HOWTO / mini / visbell.txt < prev    next >
Text File  |  1997-07-07  |  10KB  |  222 lines

  1.   Visible bell mini-Howto
  2.   Alessandro Rubini, rubini@ipvvis.unipv.it
  3.   v2.1, Aug 1996
  4.  
  5.   This doc explains something about termcap usage and provides a pointer
  6.   to a kernel patch to completely disable audible bells on demand.
  7.  
  8.   1.  Introduction
  9.  
  10.   The Linux console driver beeps the audible bell whenever a BEL char is
  11.   output (ASCII code 7).  Though this is a right choice for the default
  12.   behaviour, many users don't like their computer to beep. This mini-
  13.   Howto is meant to explain how to tell applications not to output the
  14.   BEL code. Pointers to a kernel patch are provided as well. The patch
  15.   is intended as a catch-all approach to avoid mangling with termcap and
  16.   applications' defaults.
  17.  
  18.   In my opinion the best solution is a hardware one, and my own computer
  19.   doesn't even carry a loudspeaker.
  20.  
  21.   2.  Spekearectomy
  22.  
  23.   Speakerectomy is by far the most brilliant solution to the audible
  24.   bell problem. It is the simplest way to remove beeps, though some
  25.   additional notes are worth.
  26.  
  27.   PC's are usually equipped with a silly switch to toggle the mainboard
  28.   clock to a lower speed. The switch is completely unneeded when you
  29.   work in a multitasking environment, and even its original function to
  30.   slow down old dos games based on software-loop delays is no more used.
  31.   Unfortunately we can't use the switch to increase processor speed, but
  32.   we can turn it in a speaker enable/disable toggle. It is nice when
  33.   your computer beeps at you to signal the end of a lenghty compilation,
  34.   even for those who prefer a silent console.
  35.  
  36.   To modify the switch functionality, just detatch it from the main
  37.   board and connect its wires in series with the loudspeaker. That's all
  38.   to it.
  39.  
  40.   Owners of laptop boxes, unfortunately, don't have easy access to the
  41.   lousspeaker, and neither have a spare switch to turn to a different
  42.   task.  The preferred solution for such users is trying to configure
  43.   their software to avoid beeping.
  44.  
  45.   3.  Per-console Beep Configuration
  46.  
  47.   As of Linux 1.3.43, Martin Mares added configurability to the bell
  48.   sound in console.c. You can change the duration and pitch of the
  49.   console beep on a per-console basis, by writing escape sequences to
  50.   the tty. You can apply your configuration in your own ~/.profile or
  51.   ~/.login, to have a different beep (or no beep) associated to each
  52.   console.
  53.  
  54.   The escape sequences work as follow:
  55.  
  56.   ╖  ESC-[10;xx] chooses the bell frequency in Hertz. The value should
  57.      be in the range 21-32766, otherwise the result is undefined (at
  58.      least up to the 2.0.x version -- I can't foresee the future.  If
  59.      the `xx' argument is missing, the default value (750Hz) will apply,
  60.      as in `ESC-[10].
  61.  
  62.   ╖  ESC-[11;xx] chooses the bell duration, in milli-seconds.  If you
  63.      specify more than 2 seconds, the default applies (125ms). Once
  64.      again, if the `xx' argument is missing (ESC-[11]) the default value
  65.      will be used.
  66.  
  67.   To print the escape sequences, you can try for example (50Hz, 1s)
  68.   "echo -e "\33[10;50]\33[11;1000]"" with bash (where "-e" means
  69.   `understand escape sequences'. With tcsh "echo
  70.   " 33[10;50] 33[11;1000]" will have the same effect.
  71.  
  72.   Note that a new `setterm' command might support bell configuration of
  73.   command line, as these control codes are marked as `setterm-commands'.
  74.   However, no `setterm' version I know of supports these codes.
  75.  
  76.   If you run Linux-1.3.43 or newer, you may be satisfied with the escape
  77.   sequences and avoid reading further. If you run an older kernel (I do
  78.   it myself, on a small 386), or if you want the visual bell, have a
  79.   good reading.
  80.  
  81.   4.  Basic Concepts About Termcap
  82.  
  83.   The file /etc/termcap is a text file which lists the terminal
  84.   capabilities. Several applications use the termcap information to move
  85.   the cursor in the screen and do other screen-oriented tasks.  tcsh,
  86.   bash, vi and all the curses-based applications use the
  87.   termcapdatabase.
  88.  
  89.   The database represents various terminal types, and applications use
  90.   the TERM environment variable to refer to the right entry in termcap.
  91.   Each capability is then represented by a two-letter code associated to
  92.   the character string used to get the desired effect.  The separator
  93.   character between different capabilities is colon (":").  As an
  94.   example, the audible bell, whith code "bl", is usually represented by
  95.   the string "bl=^G", which instructs the applications to use the
  96.   control-G character, the ASCII BEL.
  97.  
  98.   In addition to the bl capability, there is a vb capability, which
  99.   represents the "visible bell". vb is usually missing in the console
  100.   entry in Linux' /etc/termcap.
  101.  
  102.   5.  Defining a visible bell
  103.  
  104.   You can add the entry for the vb capability in your own termcap file.
  105.   Dennis Henriksen (duke@diku.dk) suggested to insert the following line
  106.   in the termcap entry for console:
  107.  
  108.        :vb=\E7\E[?5h\E[?5l\E[?5h\E[?5l\E[?5h\E[?5l\E[?5h\E[?5l\E8:\
  109.  
  110.   The trailing backslash is used to escape the newline in the database.
  111.   Dennis' code does the following (his own words):
  112.  
  113.   ╖  Save the cursor position (Just a safety precaution)
  114.  
  115.   ╖  Change the background color several times between normal and
  116.      reverse
  117.  
  118.   ╖  Restore the cursor position.
  119.  
  120.   Some warnings about modifying termcap:
  121.  
  122.   ╖  Check what your TERM variable looks like: it used to be "console",
  123.      but it depends on your distribution and kernel version.  Actually,
  124.      it is due to change to "linux".
  125.   ╖  Check if the vb field is already there, distributors are reading
  126.      docs and upgrading their software all the time.
  127.  
  128.   ╖  Some applications don't use termcap but the terminfo database.
  129.      They won't sense your vb entry. Terminfo is more powerful than
  130.      termcap, as well as more difficult.
  131.  
  132.   6.  Telling applications about it
  133.  
  134.   This is an incomplete list of applications that can be instrued to use
  135.   the vb entry for the current terminal type:
  136.  
  137.   ╖  tcsh (6.04 and later): "set visiblebell".  The instruction can
  138.      appear in .cshrc or can be issued interactively. To reset the
  139.      audible bell just "unset visiblebell". To disable any notification
  140.      issue "set nobeep".
  141.  
  142.   ╖  bash (any bash, as fas as I know): put "set bell-style visible" in
  143.      your ~/.bashrc. Possible bell-style's are also "none" or "audible".
  144.  
  145.   ╖  bash (with readline, as well as other readline based applications):
  146.      put "set prefer-visible-bell" in ~/.inputrc.
  147.  
  148.   ╖  nvi and elvis: put "set flash" in ~/.exrc or tell ":set flash"
  149.      interactively (note the colon).  To disable the visible bell use
  150.      noflash in place of flash.
  151.  
  152.   ╖  emacs: put "(setq visible-bell t)" in your ~/.emacs.  It is
  153.      disabled by "(setq visible-bell nil)".
  154.  
  155.   ╖  less: use "-q" on command line to use the visual bell, use "-Q" to
  156.      disable any reporting. Default options can be put in your
  157.      environment variable "LESS".
  158.  
  159.   ╖  screen: issue the CtrlA-CtrlG command. It works on all the virtual
  160.      screens. Refer to the man page under "CUSTOMIZATION" for setting
  161.      the default.
  162.  
  163.   ╖  xterm: xterm can convert each bell to either a visible or audible
  164.      signal. It defualt to audible, but you can use the "-vb" command
  165.      line option and the "xterm*visualBell: true" resource. You can
  166.      toggle visible/audible signaling on the fly with the control-
  167.      mouse-1 menu.
  168.  
  169.   ╖  other X applications: you can tell the X server the volume of the
  170.      bell, with the "-f volume" commandline option. "volume" is between
  171.      0 and 100. Refer to X docs/experts about how to pass command line
  172.      options to the server.
  173.  
  174.   7.  Disabling the audible bell
  175.  
  176.   If you want to force the visible bell on your console you can replace
  177.   the "bl" entry in termcap with the same string suggested for "vb"
  178.   above.  This approach can unload you from the task of customizing each
  179.   application.  I use this option on all the machines where I can run
  180.   Linux.
  181.  
  182.   Note that applications with hardwired bells in their source code won't
  183.   be affected by this change.
  184.  
  185.   8.  Easier configurability
  186.  
  187.   If you want the ability to choose between audible and visible bell on
  188.   a console basis, you can use two different terminal types for the
  189.   linux console.  You can name them, for example, conso