Visible bell mini-Howto <author>Alessandro Rubini, <tt/rubini@ipvvis.unipv.it/ <date>v2.00, May 1995 <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 embed 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. <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 in an useful toggle. The preferred solution for such users is trying to configure their software to avoid beeping. <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. 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. 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/ (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 theis 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 a modification of the console driver in the kernel. <p> An old patch to the kernel is available by ftp from <tt>iride.unipv.it:/pub/linux/</tt>. It was taken against the 1.1.31 kernel sources, but it applies to older kernels as well. The patch comes with a small user program to set/unset visible and audible bells on a per-console basis. I'm not currently mantaining the patch, but if you are interested in it drop me a note. If there's enough interest we could even make it in the mainstream kernel. </article>