BackspaceDelete(1).pdf
(
39 KB
)
Pobierz
Linux Backspace/Delete mini-HOWTO
Linux Backspace/Delete mini−HOWTO
Sebastiano Vigna
vigna@acm.org
Revision History
Revision v1.6 19 Jan 2002
Included many comments from Alex Boldt and Chung−Rui Kao.
Revision v1.5 3 May 2000
Updated for new distros and the tput trick.
Revision v1.4 7 December 2000
Updated for Red Hat 7.0 and Helix Gnome conflicts.
Revision v1.3
18 October 2000
Name change.
Revision v1.2 15 October 2000
Updated. Added "What If Nothing Works" section.
Revision v1.1
13 September 2000
Added tcsh fixes
Revision v1.0
5 September 2000
First release
Linux Backspace/Delete mini−HOWTO
Table of Contents
1. Introduction.
....................................................................................................................................................1
2. How Keys Are Turned Into Actions.
.............................................................................................................2
3. Why It Doesn't (Always) Work
.....................................................................................................................3
4. X.
.......................................................................................................................................................................4
5. What You Should Do When Writing Applications.
.....................................................................................5
6. What You Should Do On Your System..
.......................................................................................................6
6.1. What Needs to Be Done.
...................................................................................................................6
6.1.1. Detecting Deviance.
..........................................................................................................6
6.1.2. Distinguishing Between Emulators.
.................................................................................6
6.1.3. Fixing the Terminal Database.
..........................................................................................7
6.1.4. Fixing the Shell Behaviour.
..............................................................................................7
6.2. How to Do It.
....................................................................................................................................7
6.3. Fixing for tcsh.
..................................................................................................................................9
Notes.
........................................................................................................................................10
7. What If Nothing Works.
...............................................................................................................................11
8. More Hacking.
...............................................................................................................................................12
9. Conclusions.
...................................................................................................................................................12
i
1. Introduction
Every Linux user has been sooner or later trapped in a situation in which having working
Backspace
and
Delete
keys on the console and on X seemed impossible. This paper explains why this happens and suggests
solutions. The notions given here are essentially distribution−independent: due to the widely different content
of system configuration files in each distribution, I will try to give the reader enough knowledge to think up
his/her own fixes, if necessary.
I assume that the
Backspace
key should go back one character and then erase the character under the cursor.
On the other hand, the
Delete
key should delete the character under the cursor, without moving it. If you
think that the function of the two keys should be exchanged, in spite of the fact that most keyboards feature
an arrow pointing to the
left
(
) on the
Backspace
key, then this paper will not give you immediate solutions,
but certainly you may find the explanations given here useful.
Another assumption is that the fixes should alter only local (user) files. No standard part of the distribution
should be altered. Finally, this document discusses how to set up your system so that applications get the
right events. If an application decides to interpret such events in an idiosyncratic way, the only possible fix is
to reconfigure the application.
Since the first release of this Mini−HOWTO things have
become even more entangled. Different distributions of the
same terminal emulator (e.g., gnome−terminal as provided by
Red Hat 7.0, Helix Code/Ximian or even Red Hate7.1)
generate different ASCII sequences. Due to this mismatch,
now the terminal databases correspond even less to the
terminal emulators they are supposed to describe. To set a
firm ground for the following discussion, we assume basically
as correct settings the ones proposed in the
Debian keyboard
policy
.
1. Introduction
1
2. How Keys Are Turned Into Actions
When a key is pressed on the keyboard, a number of hardware and software components cooperate so as to
guarantee that the intended meaning of the key (e.g., emitting a certain character) matches the actual
behaviour of the key. I will concentrate on the software side (as our control on the hardware part is
nonexistent), and in particular, for the time being, on the events related to console output.
1.
Hitting a key causes raw keyboard
scancodes
to be generated; these scancodes are then transformed
in a
keycode
. On an i386 system, usually the key
Backspace
emits 14 and the key
Delete
emits 111.
2.
The keycodes are translated by the keyboard library into a
keyboard symbol (keysym)
using the
keyboard definition loaded by the user. If you look into your keyboard database (e.g., in
/lib/kbd/
), you'll discover several definitions for different computers, different layouts and
possibly different interpretations of the same keys (e.g., one could desire that the two
Alt
keys really
behave as distinct modifiers). The Linux console keyboard layout assigns keysym Delete to keycode
14 and keysym Remove to keycode 111. This may seem strange, but the Linux console emulates a
VT100 terminal, and this is the way things work in that realm.
[1]
3.
Our journey has still to come to an end. Console applications read ASCII sequences, not keysyms. So
the console must read keysyms and translate them into ASCII sequences that suitably encode the
keys. Of course, this operation must be performed in a way that is understandable by applications.
For instance, on the Linux console the Delete keysym is mapped to the ASCII code 127 (DEL), the
Remove keysym on a suitable escape sequence, and the BackSpace keysym to ASCII code 8 (BS).
4.
Finally, we must in a sense roll back to what we had before and translate the ASCII sequences
generated by each key into a
key capability
. This goal is reached by a
terminal database
, which
contains, for each kind of terminal, a reverse mapping from sequences of characters to key
capabilities (which are essentially a subset of the keysyms).
[2]
Unfortunately, there are two "standard" terminal
databases, termcap and terminfo. Depending on your
distribution, you could be using either one of them,
or the database could even depend on the
application. Our discussion will concentrate on the
more modern terminfo database, but the suggested
fixes take both into consideration.
For instance, on the Linux console
F1
generates an escape followed by
[[A
, which can be translated
to the capability
key_f1
by looking into the terminal−database entry of the console (try
infocmp
linux
if you want to have a look at the entry). A very good and thorough discussion of terminal
databases can be found in GNU's termcap manual. Usually Linux applications use the newer
terminfo database, contained in the ncurses package.
Maybe at this point not surprisingly, the Linux console terminfo entry maps DEL to the
kbs
(backspace key) capability, and escape followed by
[3~
to the
kdch1
("delete−one−char" key)
capability. Even if you could find strange that the
Backspace
key emits a DEL, the terminal database
puts everything back into its right place, and correctly behaving applications will interpret DEL as
the capability
kbs
, thus deleting the character to the left of the cursor.
2. How Keys Are Turned Into Actions
2
3. Why It Doesn't (Always) Work
I hope the basic problem is clear at this point: there is a bottleneck between the keyboard and console
applications, that is, the fact that they can only communicate by ASCII sequences. So special keys must be
first translated from keysyms to sequences, and then from sequences to key capabilities. Since different
consoles have different ideas about what this translation can look like, we need a terminal database. The
system would work flawlessly, except for a small problem: it is not always set up correctly, and not everyone
uses it.
Applications must have a way to know which database entry to use: this is accomplished by suitably setting
the
TERM
environment variable. In some cases, there is a mismatch between the terminal emulator and the
content of the database entry suggested by
TERM
.
Moreover, many applications
do not use
the terminal database (or at least not all of it), and consider BS and
DEL ASCII codes with an intended meaning: thus, without looking at the database, they assign them
semantics (usually, of course, the semantics is removing the character before or under the cursor). So now our
beautiful scheme is completely broken (as every Linux user is bitterly aware). For instance, the bash assumes
that DEL should do a backward−delete−char, that is, backspace. Hence, on a fresh install the
Backspace
key
works on the console as expected, but just because of two twists in a row! Of course, the
Delete
key does not
work. This happens because the bash does not look into the terminal database for the
kdch1
capability.
Just to illustrate how things have become entangled, consider the
fix_bs_and_del
script provided with the
Red Hat distribution (and maybe others). It assigns on−the−fly the BackSpace keysym to the
Backspace
key,
and the Delete keysym to the
Delete
key. Now the shell works! Unfortunately, all programs relying on the
correct coupling of keysym generation and terminal database mappings are now not working at all, as the
Delete keysym is mapped to DEL, and the latter to the
kbs
key capability by the terminfo database, so in
such programs both keys produce backspacing.
3. Why It Doesn't (Always) Work
3
Plik z chomika:
megaskrypty
Inne pliki z tego folderu:
3-Button-Mouse(1).pdf
(58 KB)
XWindow-Overview-HOWTO(1).pdf
(30 KB)
Xterm-Title(1).pdf
(39 KB)
Xterminals(1).pdf
(30 KB)
Xinerama-HOWTO(1).pdf
(33 KB)
Inne foldery tego chomika:
Programowanie
Zgłoś jeśli
naruszono regulamin