top: attempt to provide missing xterm vim keys support

A recent issue (and merge request) reminded me of gaps
in top's alternate 'vim' navigation keys support. Some
xterm emulators do not pass the customary strings when
keys were used with the <Ctrl> and/or <Alt> modifiers.

While it was a known problem, this issue/merge request
prompted research into the root cause. As it turns out
the problem is traceable to an X resource known by the
name 'eightBitInput'. When 'true' (the default), a key
pressed in combination with <Alt> will not be preceded
by the <Esc> character. Rather, a single character was
presented (modified via an 'eightBitMeta' X resource).

The following approaches would eliminate this problem:

. start xterm thus: xterm -xrm '*eightBitInput: false'

. use: ~/.Xresources with 'Xterm*eightBitInput: false'

. build xterm with 'configure --enable-meta-sends-esc'
( apparently used for CentOS, Fedora, openSUSE, etc. )

. enable xterm's menu via 'configure --enable-toolbar'
( so the user can set the 'Meta Sends Escape' option )

Of course, none of the above steps is desirable from a
user's perspective. So, this patch will add additional
entries to the iokey function's tinfo_tab to represent
strings passed when the <Alt> key does not send <Esc>.

[ hopefully they'll be the same across all platforms ]

Lastly, this patch will also eliminate those redundant
<Atl> + '\', '/', '<' & '>' provisions, which now seem
like overkill and suffer from that same 'eightBitMeta'
xterm problem. And we might as well say goodbye to the
4 '<Alt> + arrow key' table entries (which do not seem
to currently work with any emulator which I can find).

[ what in the world was I thinking way back in 2011? ]

Reference(s):
. issue
https://gitlab.com/procps-ng/procps/issues/135
. merge request
https://gitlab.com/procps-ng/procps/merge_requests/84

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2019-06-24 00:00:00 -05:00 committed by Craig Small
parent 1d8d4be046
commit e6a2931c39
2 changed files with 16 additions and 23 deletions

View File

@ -62,7 +62,7 @@
. .
.\" Document ///////////////////////////////////////////////////////////// .\" Document /////////////////////////////////////////////////////////////
.\" ---------------------------------------------------------------------- .\" ----------------------------------------------------------------------
.TH TOP 1 "July 2018" "procps-ng" "User Commands" .TH TOP 1 "June 2019" "procps-ng" "User Commands"
.\" ---------------------------------------------------------------------- .\" ----------------------------------------------------------------------
.\" ---------------------------------------------------------------------- .\" ----------------------------------------------------------------------
@ -198,15 +198,15 @@ motion keys like the standard \*(KAs plus the Home, End, PgUp and PgDn keys.
If your terminal or emulator does not provide those keys, the following If your terminal or emulator does not provide those keys, the following
combinations are accepted as alternatives: combinations are accepted as alternatives:
.nf .nf
\fI key equivalent-key-combinations \fR \fI key equivalent-keys \fR
Up alt +\fB \\\fR or alt +\fB k \fR Left alt +\fB h \fR
Down alt +\fB /\fR or alt +\fB j \fR Down alt +\fB j \fR
Left alt +\fB <\fR or alt +\fB h \fR Up alt +\fB k \fR
Right alt +\fB >\fR or alt +\fB l \fR(lower case L) Right alt +\fB l \fR
PgUp alt +\fB Up\fR or alt + ctrl +\fB k \fR Home alt + ctrl +\fB h \fR
PgDn alt +\fB Down\fR or alt + ctrl +\fB j \fR PgDn alt + ctrl +\fB j \fR
Home alt +\fB Left\fR or alt + ctrl +\fB h \fR PgUp alt + ctrl +\fB k \fR
End alt +\fB Right\fR or alt + ctrl +\fB l \fR End alt + ctrl +\fB l \fR
.fi .fi
The \fBUp\fR and \fBDown\fR \*(KAs have special significance when prompted The \fBUp\fR and \fBDown\fR \*(KAs have special significance when prompted

View File

@ -969,8 +969,6 @@ static int ioch (int ech, char *buf, unsigned cnt) {
* note: we support more keys than we currently need, in case * note: we support more keys than we currently need, in case
* we attract new consumers in the future */ * we attract new consumers in the future */
static int iokey (int action) { static int iokey (int action) {
static char buf12[CAPBUFSIZ], buf13[CAPBUFSIZ]
, buf14[CAPBUFSIZ], buf15[CAPBUFSIZ];
static struct { static struct {
const char *str; const char *str;
int key; int key;
@ -979,17 +977,16 @@ static int iokey (int action) {
{ NULL, kbd_LEFT }, { NULL, kbd_RIGHT }, { NULL, kbd_PGUP }, { NULL, kbd_LEFT }, { NULL, kbd_RIGHT }, { NULL, kbd_PGUP },
{ NULL, kbd_PGDN }, { NULL, kbd_HOME }, { NULL, kbd_END }, { NULL, kbd_PGDN }, { NULL, kbd_HOME }, { NULL, kbd_END },
{ NULL, kbd_BKSP }, { NULL, kbd_INS }, { NULL, kbd_DEL }, { NULL, kbd_BKSP }, { NULL, kbd_INS }, { NULL, kbd_DEL },
// next 4 destined to be meta + arrow keys...
{ buf12, kbd_PGUP }, { buf13, kbd_PGDN },
{ buf14, kbd_HOME }, { buf15, kbd_END },
// remainder are alternatives for above, just in case... // remainder are alternatives for above, just in case...
// ( the k,j,l,h entries are the vim cursor motion keys ) // ( the k,j,l,h entries are the vim cursor motion keys )
{ "\033\\", kbd_UP }, { "\033/", kbd_DOWN }, /* meta+ \,/ */
{ "\033<", kbd_LEFT }, { "\033>", kbd_RIGHT }, /* meta+ <,> */
{ "\033k", kbd_UP }, { "\033j", kbd_DOWN }, /* meta+ k,j */ { "\033k", kbd_UP }, { "\033j", kbd_DOWN }, /* meta+ k,j */
{ "\033h", kbd_LEFT }, { "\033l", kbd_RIGHT }, /* meta+ h,l */ { "\033h", kbd_LEFT }, { "\033l", kbd_RIGHT }, /* meta+ h,l */
{ "\033\013", kbd_PGUP }, { "\033\012", kbd_PGDN }, /* ctrl+meta+ k,j */ { "\033\013", kbd_PGUP }, { "\033\012", kbd_PGDN }, /* ctrl+meta+ k,j */
{ "\033\010", kbd_HOME }, { "\033\014", kbd_END } /* ctrl+meta+ h,l */ { "\033\010", kbd_HOME }, { "\033\014", kbd_END }, /* ctrl+meta+ h,l */
{ "\xC3\xAB", kbd_UP }, { "\xC3\xAA", kbd_DOWN }, /* meta+ k,j (some xterms) */
{ "\xC3\xA8", kbd_LEFT }, { "\xC3\xAC", kbd_RIGHT }, /* meta+ h,l (some xterms) */
{ "\xC2\x8B", kbd_PGUP }, { "\xC2\x8A", kbd_PGDN }, /* ctrl+meta+ k,j (some xterms) */
{ "\xC2\x88", kbd_HOME }, { "\xC2\x8C", kbd_END } /* ctrl+meta+ h,l (some xterms) */
}; };
#ifdef TERMIOS_ONLY #ifdef TERMIOS_ONLY
char buf[SMLBUFSIZ], *pb; char buf[SMLBUFSIZ], *pb;
@ -1013,10 +1010,6 @@ static int iokey (int action) {
tinfo_tab[9].str = tOk(key_backspace); tinfo_tab[9].str = tOk(key_backspace);
tinfo_tab[10].str = tOk(key_ic); tinfo_tab[10].str = tOk(key_ic);
tinfo_tab[11].str = tOk(key_dc); tinfo_tab[11].str = tOk(key_dc);
STRLCPY(buf12, fmtmk("\033%s", tOk(key_up)));
STRLCPY(buf13, fmtmk("\033%s", tOk(key_down)));
STRLCPY(buf14, fmtmk("\033%s", tOk(key_left)));
STRLCPY(buf15, fmtmk("\033%s", tOk(key_right)));
// next is critical so returned results match bound terminfo keys // next is critical so returned results match bound terminfo keys
putp(tOk(keypad_xmit)); putp(tOk(keypad_xmit));
// ( converse keypad_local issued at pause/pgm end, just in case ) // ( converse keypad_local issued at pause/pgm end, just in case )
@ -1055,7 +1048,7 @@ static int iokey (int action) {
return tinfo_tab[i].key; return tinfo_tab[i].key;
// no match, so we'll return single non-escaped keystrokes only // no match, so we'll return single non-escaped keystrokes only
if (buf[0] == '\033' && buf[1]) return 0; if (buf[0] == '\033' && buf[1]) return -1;
return buf[0]; return buf[0];
} // end: iokey } // end: iokey