1 |
[ Please excuse the length... I'm making a proposal related to an issue |
2 |
which isn't widely understood, and I think it's better to provide an |
3 |
explanation straight off rather than watch this thread descend into |
4 |
irrelevant arguments by people who don't have a clue about what's being |
5 |
discussed. ] |
6 |
|
7 |
First, some background. Different terminal emulators have different |
8 |
capabilities. Some can report their width and height to applications, |
9 |
some can't. Some can do 8 colours, some can do 8 colours + bold, some |
10 |
can do 16 colours, some can do 16 colours + bold, some can do 88 or 256 |
11 |
colours + bold and italic. Some terminals have problems writing to the |
12 |
last character on the screen, some have strange erase bugs, some allow |
13 |
programs to resize the terminal. Different terminals use different magic |
14 |
sequences to do these things. Keyboard handling is also different |
15 |
between different terminals -- some terminals don't support the meta / |
16 |
alt key, some don't distinguish between escape and control, and handling |
17 |
of keys like home, end and the function and arrow keys varies |
18 |
considerably. |
19 |
|
20 |
All modern terminals will set the TERM environment variable. This allows |
21 |
applications to: |
22 |
|
23 |
* support optional capabilities (eg colour) on terminals where it is |
24 |
available. |
25 |
|
26 |
* work around bugs or limiting features in terminals, for example by |
27 |
never writing to the bottom right character on terminals that don't |
28 |
support it properly. |
29 |
|
30 |
* know which escape sequences to use when reading or writing from the |
31 |
terminal. |
32 |
|
33 |
Obviously, making each application have its own list of TERM values and |
34 |
settings isn't a very good solution -- it's a lot of duplicated |
35 |
information, and makes it hard to update things when new terminals are |
36 |
released. A centralised database and library makes much more sense. |
37 |
|
38 |
Historically, there have been two widely used implementations of said |
39 |
database. These are usually known as 'termcap' and 'terminfo'. |
40 |
|
41 |
The termcap method is provided by libtermcap-compat. Most applications |
42 |
which use this method only do so as an option for systems where terminfo |
43 |
is not available -- for example, for Vim, terminfo vs termcap is a |
44 |
compile-time option. The termcap database is limited, generally out of |
45 |
date and mostly unmaintained. It will likely not remain in the tree for |
46 |
much longer (bug #103105). |
47 |
|
48 |
The terminfo method is provided by ncurses. It is considerably more |
49 |
powerful and has far fewer arbitrary restrictions upon database entry |
50 |
lengths. It is also less unmaintained than termcap. In simple terms, |
51 |
ncurses provides two things -- a standardised way for applications to |
52 |
look up terminal capabilities, and a set of library functions which |
53 |
simplify various terminal-related tasks. Some applications use both of |
54 |
these, whilst others only use the former and implement their own more |
55 |
powerful screen handling. Both approaches are valid, depending upon |
56 |
application needs. |
57 |
|
58 |
Now, there's a slight problem. If you have TERM=shinynewterm, and you |
59 |
ssh to a box with an old terminfo database, you'll get a warning or |
60 |
error that your terminal isn't recognised when you try to use an |
61 |
ncurses-based application. You can either ask the sysadmin to upgrade, |
62 |
or you can install the relevant terminfo files into ~/.terminfo. This |
63 |
isn't a major problem, but the local terminfo thing isn't very well |
64 |
known, so some people have this silly misconception that you're either |
65 |
screwed or have to export a fake TERM if the box you're on doesn't |
66 |
recognise your terminal. |
67 |
|
68 |
Unfortunately, some of the people who have this silly misconception also |
69 |
happen to write terminal emulators. |
70 |
|
71 |
See, certain terminal emulators lie about their TERM setting. Usually |
72 |
it's things that aren't xterm pretending to be an xterm, although rxvt |
73 |
sometimes crops up too. Examples of things pretending to be xterm |
74 |
include Konsole, Gnome Terminal. |
75 |
|
76 |
The logic behind it goes like this: |
77 |
|
78 |
* We don't understand this 'terminfo' thing, but we want our terminal to |
79 |
work with programs which use ncurses. |
80 |
|
81 |
* We've implemented xterm-style colour sequences and some basic cursor |
82 |
movement. |
83 |
|
84 |
* Therefore, we shall set TERM=xterm. |
85 |
|
86 |
This is not a good idea. See, real xterm supports a hell of a lot of |
87 |
fancy voodoo. It and rxvt-unicode are two of the most fully featured |
88 |
terminal emulators (from a terminal capability point of view) out there. |
89 |
None of these cheap knockoffs that claim to be xterm come anywhere near |
90 |
close to supporting full xterm capabilities. |
91 |
|
92 |
Right now we have two sets of workarounds in place to avoid problems |
93 |
with these lying apps. The first is that the xterm terminfo entry is |
94 |
utterly crippled. The second is that apps which make full use of all the |
95 |
fancy terminal sequences will often include additional checks and |
96 |
restrictions when running on an 'xterm' (for example, Vim will disable |
97 |
most of its mouse capabilities on an xterm to avoid breaking Gnome |
98 |
Terminal). |
99 |
|
100 |
This is bad. |
101 |
|
102 |
It screws over xterm users, because their terminal is not being used to |
103 |
full effect. Applications which should support 256 colours, full mouse |
104 |
support, background detection, terminal titles etc have to disable |
105 |
support for those things in case they break fake xterms. |
106 |
|
107 |
It also screws over users of those things that pretend to be xterm. Both |
108 |
Konsole and Gnome Terminal implement a few extras beyond the 'crippled' |
109 |
xterm definition, but these can't be turned on for fear of breaking both |
110 |
other "pretend to be xterm" terminals and real xterms. |
111 |
|
112 |
For some apps, this doesn't really make much difference. For others it |
113 |
does. As it stands, applications such as powerful text editors and |
114 |
terminal multiplexers (screen) can't be used properly on anything that |
115 |
claims TERM="xterm". |
116 |
|
117 |
At this point, there's at least one person who's going to whine "but I |
118 |
use vim and screen on $whatever just fine!". Which is true, for |
119 |
sufficiently small values of fine. As soon as you try to do 256 colour |
120 |
support (`:set t_Co=256 | colorscheme inkpot` in vim, for example), or |
121 |
anything mouse related, you're stuffed. You'll also be experiencing |
122 |
considerable screen redraw slowdowns because some wannabe-xterms don't |
123 |
do screen refresh voodoo properly. |
124 |
|
125 |
Not satisfied, and still think your crappy Gnome Terminal is a full |
126 |
xterm? Install xtermcontrol, run `xtermcontrol --get-bg` and watch your |
127 |
terminal get very very upset. This is a frickin' nuisance, because |
128 |
there's a long standing issue to do with Vim and making the default |
129 |
colour scheme readable on both light and dark backgrounds. It would be |
130 |
easy to fix if we could count upon anything claiming to be an xterm |
131 |
supporting xterm colour reporting, but this is not the case. |
132 |
|
133 |
Now the proposal. This isn't something that can happen immediately, but |
134 |
it's something I'd like to see us working towards: |
135 |
|
136 |
* Make everything that isn't xterm set its own TERM value. Possibly the |
137 |
same for things pretending to be rxvt, although this is less of an |
138 |
issue since I think everything that pretends to be rxvt is "rxvt plus |
139 |
some patches". |
140 |
|
141 |
* Install, either with the terminal (as is done by rxvt-unicode |
142 |
currently), or as part of ncurses, proper terminfo definitions for |
143 |
these terminals. |
144 |
|
145 |
* De-cripple the standard xterm definition and remove restrictions from |
146 |
programs which can make full use of xterm's capabilities. |
147 |
|
148 |
* Provide a short FAQ explaining what I said above in a more |
149 |
newbie-friendly way, along with a description of how to generate and |
150 |
use terminfo files under a user's home directory for compatibility |
151 |
with legacy systems and a note that users sshing from legacy systems |
152 |
to Gentoo may need to switch their TERM value. |
153 |
|
154 |
* Include TERM stuff in policy so that the problem doesn't crop up again |
155 |
a few months later. |
156 |
|
157 |
* Putty? Since I consider sshing from insecure systems irresponsible, I |
158 |
don't know much about this one, other than that it's another dirty |
159 |
liar and that said lying has caused various bugs in the past. Perhaps |
160 |
someone could clarify with details of what it pretends to support and |
161 |
what it really supports? |
162 |
|
163 |
Before I go any further with this, does anyone have a really really good |
164 |
reason why we should continue to make lots of users suffer because a few |
165 |
upstreams don't know what they're doing? |
166 |
|
167 |
-- |
168 |
Ciaran McCreesh : Gentoo Developer (Vim, Shell tools, Fluxbox, Cron) |
169 |
Mail : ciaranm at gentoo.org |
170 |
Web : http://dev.gentoo.org/~ciaranm |