Visible bell mini-Howto Alessandro Rubini, rubini@ipvvis.unipv.it v1.01, July 1994 This doc explains something about termcap usage and provides Linux with a patch to completely disable audible bells on demand. 1. Introduction 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. 2. Basic Concepts about termcap The file /etc/termcap is a text file which lists the terminal capabilities. Several applications use the termcap information to move the cursor in the screen and do other screen-oriented tasks. tcsh, bash, vi and all the curses-based applications use the termcapdatabase. The database represents various terminal types, and applications use the TERM environment variable to refer to the right entry in 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 "bl=^G", which instructs the applications to use the control-G character, the ASCII BEL. In addition to the bl capability, there is a vb capability, which represents the "visible bell". vb is usually missing in the console entry in Linux' /etc/termcap. 3. Defining a visible bell You can add the entry for the vb capability in your own termcap file. Dennis Henriksen (duke@diku.dk) suggested to insert the following line in the termcap entry for console: :vb=\E7\E[?5h\E[?5l\E[?5h\E[?5l\E[?5h\E[?5l\E[?5h\E[?5l\E8:\ The trailing backslash is used to escape the newline in the database. Dennis' code does the following (his own words): o Save the cursor position (Just a safety precaution) o Change the background color several times between normal and reverse o Restore the cursor position. 4. Telling applications about it This is an incomplete list of applications that can be instrued to use the vb entry for the current terminal type: o tcsh (6.04 and later): "set visiblebell". The instruction can appear in .cshrc or can be issued interactively. To reset the audible bell just "unset visiblebell". o bash (with readline, as well as other readline based applications): put "set prefer-visible-bell" in ~/.inputrc. o nvi and elvis: put "set flash" in ~/.exrc or tell ":set flash" interactively (note the colon). To disable the visible bell use noflash in place of flash. o emacs: put "(setq visible-bell t)" in your ~/.emacs. It is disabled by "(setq visible-bell nil)". 5. Disabling the audible bell If you want to force the visible bell on your console you can replace the "bl" entry in termcap with the same string suggested for "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. 6. Easier configurability 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, console and console- vb. The console entry would be the original one, while the other could feature a visual bell string for the "bl" item. Thus you can change the behaviour of your bell on a console basis: o With tcsh: "setenv TERM console-vb" to get a screen flash, and "setenv TERM console" to get the audible beep. o With bash: "TERM=console; export TERM" for the flash, and "TERM=console-vb; export TERM" for the beep. Note that the 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. 7. About the patch 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. less is one of those applications. The only way to shut the loudspeaker for these applications is to modify the console driver in the kernel. Either, you may remove the loudspeaker altogether. The patch I provide is taken agains the 1.1.31 kernel sources, but it applies fine to any kernel I know of (just remember to pass the -l option to patch). The patch comes with a small user program to set/unset visible and audible bells on a console basis. It is available by ftp from sunsite.unc.edu as /pub/Linux/......