Visible bell mini-Howto <author>Alessandro Rubini, <tt/rubini@ipvvis.unipv.it/ <date>v2.1, Aug 1996 <abstract> This doc explains something about termcap usage and provides a pointer to a kernel patch to completely disable audible bells on demand. </abstract> <!-- Table of contents --> <toc> <!-- Begin the document --> <sect>Introduction <p> The Linux console driver beeps the audible bell whenever a BEL char is output (ASCII code 7). Though this is a right choice for the default behaviour, many users don't like their computer to beep. This mini-Howto is meant to explain how to tell applications not to output the BEL code. Pointers to a kernel patch are provided as well. The patch is intended as a catch-all approach to avoid mangling with termcap and applications' defaults. <p> In my opinion the best solution is a hardware one, and my own computer doesn't even carry a loudspeaker. <sect>Spekearectomy <p> Speakerectomy is by far the most brilliant solution to the audible bell problem. It is the simplest way to remove beeps, though some additional notes are worth. <p> PC's are usually equipped with a silly switch to toggle the mainboard clock to a lower speed. The switch is completely unneeded when you work in a multitasking environment, and even its original function to slow down old dos games based on software-loop delays is no more used. Unfortunately we can't use the switch to increase processor speed, but we can turn it in a speaker enable/disable toggle. It is nice when your computer beeps at you to signal the end of a lenghty compilation, even for those who prefer a silent console. <p> To modify the switch functionality, just detatch it from the main board and connect its wires in series with the loudspeaker. That's all to it. <p> Owners of laptop boxes, unfortunately, don't have easy access to the lousspeaker, and neither have a spare switch to turn to a different task. The preferred solution for such users is trying to configure their software to avoid beeping. <sect>Per-console Beep Configuration <p> As of Linux 1.3.43, Martin Mares added configurability to the bell sound in <tt/console.c/. You can change the duration and pitch of the console beep on a per-console basis, by writing escape sequences to the tty. You can apply your configuration in your own <tt>~/.profile</tt> or <tt>~/.login</tt>, to have a different beep (or no beep) associated to each console. <p> The escape sequences work as follow: <itemize> <item>ESC-<tt/[10;/xx<tt/]/ chooses the bell frequency in Hertz. The value should be in the range 21-32766, otherwise the result is undefined (at least up to the 2.0.x version -- I can't foresee the future. If the `xx' argument is missing, the default value (750Hz) will apply, as in `ESC-<tt/[10]/. <item>ESC-<tt/[11;/xx<tt/]/ chooses the bell duration, in milli-seconds. If you specify more than 2 seconds, the default applies (125ms). Once again, if the `xx' argument is missing (ESC-<tt/[11]/) the default value will be used. </itemize> <p> To print the escape sequences, you can try for example (50Hz, 1s) "<tt/echo -e "\33[10;50]\33[11;1000]"/" with <tt/bash/ (where "-e" means `understand escape sequences'. With <tt/tcsh/ "<tt/echo "\033[10;50]\033[11;1000]"/ will have the same effect. <p> Note that a new `setterm' command might support bell configuration of command line, as these control codes are marked as `setterm-commands'. However, no `setterm' version I know of supports these codes. <p> If you run Linux-1.3.43 or newer, you may be satisfied with the escape sequences and avoid reading further. If you run an older kernel (I do it myself, on a small 386), or if you want the visual bell, have a good reading. <sect>Basic Concepts About Termcap <p> The file <tt>/etc/termcap</tt> is a text file which lists the <tt/term/inal <tt/cap/abilities. Several applications use the <tt/termcap/ information to move the cursor in the screen and do other screen-oriented tasks. <tt/tcsh/, <tt/bash/, <tt/vi/ and all the <tt/curses/-based applications use the <tt/termcap/database. <p> The database represents various terminal types, and applications use the <tt/TERM/ environment variable to refer to the right entry in <tt/termcap/. Each capability is then represented by a two-letter code associated to the character string used to get the desired effect. The separator character between different capabilities is colon (":"). As an example, the audible bell, whith code "bl", is usually represented by the string "<tt/bl=^G/", which instructs the applications to use the control-G character, the ASCII BEL. <p> In addition to the <tt/bl/ capability, there is a <tt/vb/ capability, which represents the "visible bell". <tt/vb/ is usually missing in the <tt/console/ entry in Linux' <tt>/etc/termcap</tt>. <sect>Defining a visible bell <p> You can add the entry for the <tt/vb/ capability in your own termcap file. Dennis Henriksen (duke@diku.dk) suggested to insert the following line in the <tt/termcap/ entry for <tt/console/: <tscreen><verb> :vb=\E7\E[?5h\E[?5l\E[?5h\E[?5l\E[?5h\E[?5l\E[?5h\E[?5l\E8:\ </verb></tscreen> The trailing backslash is used to escape the newline in the database. Dennis' code does the following (his own words): <itemize> <item>Save the cursor position (Just a safety precaution) <item>Change the background color several times between normal and reverse <item>Restore the cursor position. </itemize> <p> Some warnings about modifying termcap: <itemize> <item>Check what your <tt/TERM/ variable looks like: it used to be "console", but it depends on your distribution and kernel version. Actually, it is due to change to "linux". <item>Check if the <tt/vb/ field is already there, distributors are reading docs and upgrading their software all the time. <item>Some applications don't use <tt/termcap/ but the <tt/terminfo/ database. They won't sense your <tt/vb/ entry. Terminfo is more powerful than termcap, as well as more difficult. </itemize> <sect>Telling applications about it <p> This is an incomplete list of applications that can be instrued to use the <tt/vb/ entry for the current terminal type: <itemize> <item><tt/tcsh/ (6.04 and later): "<tt/set visiblebell/". The instruction can appear in <tt/.cshrc/ or can be issued interactively. To reset the audible bell just "<tt/unset visiblebell/". To disable any notification issue "<tt/set nobeep/". <item><tt/bash/ (any bash, as fas as I know): put "<tt/set bell-style visible/" in your <tt>~/.bashrc</tt>. Possible bell-style's are also "none" or "audible". <item><tt/bash/ (with <tt/readline/, as well as other <tt/readline/ based applications): put "<tt/set prefer-visible-bell/" in <tt>~/.inputrc</tt>. <item><tt/nvi/ and <tt/elvis/: put "<tt/set flash/" in <tt>~/.exrc</tt> or tell "<tt/:set flash/" interactively (note the colon). To disable the visible bell use <tt/noflash/ in place of <tt/flash/. <item><tt/emacs/: put "<tt/(setq visible-bell t)/" in your <tt>~/.emacs</tt>. It is disabled by "<tt/(setq visible-bell nil)/". <item><tt/less/: use "<tt/-q/" on command line to use the visual bell, use "<tt/-Q/" to disable any reporting. Default options can be put in your environment variable "<tt/LESS/". <item><tt/screen/: issue the CtrlA-CtrlG command. It works on all the virtual screens. Refer to the man page under "CUSTOMIZATION" for setting the default. <item><tt/xterm/: xterm can convert each bell to either a visible or audible signal. It defualt to audible, but you can use the "<tt/-vb/" command line option and the "<tt/xterm*visualBell: true/" resource. You can toggle visible/audible signaling on the fly with the control-mouse-1 menu. <item>other X applications: you can tell the X server the volume of the bell, with the "<tt/-f/ volume" commandline option. "volume" is between 0 and 100. Refer to X docs/experts about how to pass command line options to the server. </itemize> <sect>Disabling the audible bell <p> If you want to force the visible bell on your console you can replace the "<tt/bl/" entry in <tt/termcap/ with the same string suggested for "<tt/vb/" above. This approach can unload you from the task of customizing each application. I use this option on all the machines where I can run Linux. <p> Note that applications with hardwired bells in their source code won't be affected by this change. <sect>Easier configurability <p> If you want the ability to choose between audible and visible bell on a console basis, you can use two different terminal types for the linux console. You can name them, for example, <tt/console/ and <tt/console-vb/. The <tt/console/ entry would be the original one, while the other could feature a visual bell string for the "<tt/bl/" item. Thus you can change the behaviour of your bell on a console basis: <itemize> <item>With <tt/tcsh/: "<tt/setenv TERM console-vb/" to get a screen flash, and "<tt/setenv TERM console/" to get the audible beep. <item>With <tt/bash/: "<tt/TERM=console-vb; export TERM/" for the flash, and "<tt/TERM=console; export TERM/" for the beep. </itemize> Note that the <tt/termcap/ format allows to define a terminal-type in terms of another, so you need to insert in the database only the differences. Refer to the manpages for more information. <sect>Other solutions <p> The bad news is that not all the applications are termcap-aware. Most small programs feature 'backslash-a' characters in the C source code. Those chars become a literal ASCII BEL in the executable binary. Real application don't usually fall in this category, but be careful of C newcomers who give your their own programs; novice computer-science students are the worst of all. <p> The only way to shut the loudspeaker for these applications is spekearectomy, or use of the escape sequences by Martin Mares. <p> A long time ago I made a patch for me. I don't support it anymore as the escape sequences are there. When I reworked my patch against 1.3.42 to support a configurable tone, I found that 1.3.43 already had it :-) </article>