home *** CD-ROM | disk | FTP | other *** search
/ Freelog Special Edition 1: Linux / CD1.iso / doc / HOWTO / mini / Visual-Bell < prev    next >
Text File  |  1998-10-14  |  9KB  |  198 lines

  1.   Visible bell mini-Howto
  2.   Alessandro Rubini, rubini@linux.it
  3.   v2.2, 11 November 1997
  4.  
  5.   This document explains how to use termcap to configure a visual bell
  6.   on one's system and describes how to 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. It also explain how to instruct the kernel and the X Window
  15.   System to avoid beeping when a BEL is output. Note that most of this
  16.   document refers to the text console, as configuring the X server is an
  17.   easy catch-all for any user who works in a graphic environment.
  18.  
  19.   In my opinion the best way to face a fussy computer is fixing the
  20.   hardware, and my own computer doesn't even carry a loudspeaker.
  21.  
  22.   2.  Spekearectomy
  23.  
  24.   Speakerectomy is by far the most brilliant solution to the audible
  25.   bell problem. As its name implies, it consists in removing the beeps
  26.   by removing the beeper. The operation is straightforward and you don't
  27.   even need any anesthetic, but if you want there's room for refinement.
  28.  
  29.   PC's are usually equipped with a silly switch to lower CPU clock.  The
  30.   switch is never used when you work in a multitasking environment, as
  31.   you don't even need to slow the computer down to run games based on
  32.   software loops. Unfortunately we can't use the switch to increase
  33.   processor speed, but we can use it to enable/disable the loudspeaker.
  34.   Sometimes the speaker is useful even if you enjoy a silent number
  35.   cruncher, for example to signal the end of a lenghty compilation.  To
  36.   modify the switch functionality, just detatch it from the main board
  37.   and connect its wires in series with the loudspeaker.
  38.  
  39.   Owners of laptop boxes, unfortunately, don't have easy access to the
  40.   loudspeaker, and neither they have a spare switch to turn to a
  41.   different task.  The preferred solution for such users is configuring
  42.   their software to avoid beeping, as described below.
  43.  
  44.   3.  Per-console Beep Configuration
  45.  
  46.   As of Linux 1.3.43, Martin Mares added the ability to configure the
  47.   pitch and duration of the beep, by modifying console.c. Each console
  48.   can be configured to feature a different duration and/or pitch of the
  49.   bell sound; the task is accomplished by using escape sequences to the
  50.   console device.  You can configure your own ~/.profile or ~/.login
  51.   file to select a different beep sound associated to each console (or
  52.   no beep at all, if needed).
  53.  
  54.   The escape sequences work as follow:
  55.  
  56.   ╖  ESC-[10;xx] selects the bell frequency in Hertz. The value should
  57.      be in the range 21-32766, otherwise the result is undefined.  If
  58.      the `xx' argument is missing, the default value (750Hz) will apply,
  59.      as in `ESC-[10].
  60.  
  61.   ╖  ESC-[11;xx] selects the bell duration, in milli-seconds.  If you
  62.      specify more than 2 seconds, the default applies (125ms). Once
  63.      again, if the `xx' argument is missing (ESC-[11]) the default value
  64.      will be used.
  65.   To select, for example, a 50Hz pitch for one-second duration, you can
  66.   "echo -e "\33[10;50]\33[11;1000]"" with bash (where "-e" means
  67.   `understand Escape sequences'. If you use tcsh the same command spells
  68.   "echo "\033[10;50]\033[11;1000]"".
  69.  
  70.   Although I don't know of any version of the setterm command that
  71.   supports such configuration, a future version of the command might
  72.   well support a command-line option to configure the bell sound.
  73.  
  74.   If you run Linux-1.3.43 or newer, you may be satisfied with the escape
  75.   sequences and avoid reading further. If you run an older kernel, or if
  76.   you want the visual bell, you'll enjoy the rest of this document.
  77.  
  78.   4.  Basic Concepts About Termcap and Terminfo
  79.  
  80.   The file /etc/termcap is a text file that lists the terminal
  81.   capabilities. Several applications use the termcap information to move
  82.   the cursor around the screen and do other screen-oriented tasks.
  83.   tcsh, bash, vi and all the curses-based applications use the termcap
  84.   database.
  85.  
  86.   The database describes several terminal types. The TERM environment
  87.   variable selects the right behaviour at run-time, by naming a termcap
  88.   entry to be used by applications.
  89.  
  90.   Within the database, each capability of the terminal appears as a two-
  91.   letter code and a representation of the actual escape sequence used to
  92.   get the desired effect.  The separator character between different
  93.   capabilities is the colon (":").  As an example, the audible bell,
  94.   with code "bl", usually appears as "bl=^G". This sequence tells that
  95.   the bell sound is obtained by printing the control-G character, the
  96.   ASCII BEL.
  97.  
  98.   In addition to the bl capability, the vb capability is recognized. It
  99.   is used to represent the "visible bell". vb is usually missing in the
  100.   linux entry of the termcap file.
  101.  
  102.   Most modern applications and libraries use the terminfo database
  103.   instead of termcap. This database uses one file per terminal-type and
  104.   lives in /usr/lib/terminfo; to avoid using huge directories, the
  105.   description of each terminal type is stored in a directory named after
  106.   its first letter; the linux entry, therefore, is
  107.   /usr/lib/terminfo/l/linux. To build a terminfo entry you'll
  108.   ``compile'' the termcap description; refer to the tic program and its
  109.   manual page.
  110.  
  111.   5.  Defining a Visible Bell
  112.  
  113.   You can add the entry for the vb capability in your own termcap file,
  114.   if it doesn't already define one.  Dennis Henriksen (duke@diku.dk)
  115.   suggested to insert the following line in the termcap entry for linux
  116.   (note that the entry is called console in old distributions):
  117.  
  118.        :vb=\E7\E[?5h\E[?5l\E[?5h\E[?5l\E[?5h\E[?5l\E[?5h\E[?5l\E8:\
  119.  
  120.   The trailing backslash is used to escape the newline in the database.
  121.   Dennis' code does the following (his own words):
  122.  
  123.   ╖  Save the cursor position (uust a safety precaution).
  124.  
  125.   ╖  Change the background color several times between normal and
  126.      reverse.
  127.  
  128.   ╖  Restore the cursor position.
  129.  
  130.   6.  Disabling the Audible Bell on the Text Console
  131.  
  132.   If you want to force the visible bell on your console you can use the
  133.   "bl" entry in termcap and define it with the same string suggested for
  134.   "vb" above.  This approach is handy if you don't want to customize
  135.   each application (which is described below, anyway).  I use this
  136.   option on all the machines where I can run Linux and I can't detach
  137.   the speaker.
  138.  
  139.   7.  Telling Applications to Avoid Beeping
  140.  
  141.   This is an incomplete list of applications that can be instrued to use
  142.   the vb entry for the current terminal type (using either the termcap
  143.   information or the terminfo one):
  144.  
  145.   ╖  The X server: use the "xset b" command to select the bell's
  146.      behaviour. The command takes three numeric arguments: volume, pitch
  147.      and duration. "xset -b" disables the bell altogether. Configuring
  148.      the X server affects all the applications running on the display.
  149.  
  150.   ╖  xterm: xterm can convert each bell to either a visible or audible
  151.      signal. If you use the audible bell, the settings of "xset" will
  152.      apply. The bell in xterm defualts to be audible, but you can use
  153.      the "-vb" command line option and the "xterm*visualBell: true"
  154.      resource to turn it to a visible flash. You can toggle
  155.      visible/audible signaling at run-time by using the menu invoked by
  156.      control--left-mouse-button.  If you run X you most likely won't
  157.      need the following information.
  158.  
  159.   ╖  tcsh (6.04 and later): "set visiblebell".  The instruction can be
  160.      placed in .cshrc or can be issued interactively. To reset the
  161.      audible bell just "unset visiblebell". To disable any notification
  162.      issue use "set nobeep" instead.
  163.  
  164.   ╖  bash (any bash, as fas as I know): put "set bell-style visible" in
  165.      your ~/.bashrc. Possible bell-style's are also "none" or "audible".
  166.  
  167.   ╖  bash (with readline, as well as other readline based applications):
  168.      put "set prefer-visible-bell" in ~/.inputrc.
  169.  
  170.   ╖  nvi and elvis: put "set flash" in ~/.exrc or tell ":set flash"
  171.      interactively (note the colon).  To disable the visible bell use
  172.      noflash in place of flash.
  173.  
  174.   ╖  emacs: put "(setq visible-bell t)" in your ~/.emacs.  It is
  175.      disabled by "(setq visible-bell nil)".
  176.  
  177.   ╖  less: use "-q" on command line to use the visual bell, use "-Q" to
  178.      disable any reporting. Default options can be put in your
  179.      environment variable "LESS".
  180.  
  181.   ╖  screen: issue the CtrlA-CtrlG command. It changes the behaviour of
  182.      all the virtual screens. Refer to the man page under
  183.      "CUSTOMIZATION" for setting the default.
  184.  
  185.   8.  The Dark Side of the Problem
  186.  
  187.   The bad news is that not every application uses termcap or terminfo.
  188.   Most small programs feature 'backslash-a' (alarm) characters in the C
  189.   source code.  The "alarm" code becomes a literal ASCII BEL in the
  190.   strings as stored in the executable binary.  Real application don't
  191.   usually fall in this category, but be careful of C newcomers who give
  192.   you their own programs. Students of computer science are the worst of
  193.   all, granted.
  194.  
  195.   The only way to make these programs silent applications is
  196.   spekearectomy, or using the escape sequences by Martin Mares.
  197.  
  198.