Tuesday, August 27, 2013

Re: Mapping <*-CR>

On 08/25/2013 05:00 PM, Thomas E. Dickey wrote:
> On Sunday, August 25, 2013 4:10:44 PM UTC-4, Michael Henry wrote:
>> You may find, however, that some things don't work quite right
>> now that Konsole sends xterm-compatible keycodes. The "konsole"
>
> Testing konsole 2.10.5 on Fedora19, I see that it does not.
> It matches the "konsole" entry which I wrote.
>
> That's probably the most recent copy of konsole that I can test.

You're right; I'm sorry, I got myself confused here. I've got
two machines running Fedora 19's Konsole. On my main machine,
I've reconfigured Konsole to use Xterm's keycodes for <F1>
through <F4>, and on the other machine, I've left it alone for
testing with TERM=konsole. I think I've already gotten myself
believing that Konsole emulates Xterm better than it does
out-of-the-box (mostly due to wishful thinking on my part).

Thanks for the tip about the "tack" tool; that makes it much
easier to test keycodes. I've verified that the terminfo
database on Fedora 19 for TERM=konsole does indeed match the
function key behavior of Fedora 19's Konsole with out-of-the-box
Konsole settings.

There are many differences in terminfo settings between
TERM=xterm and TERM=konsole, as shown by ``infocmp xterm
konsole``. I don't yet understand them all. I'd been assuming
something was out-of-date somewhere, since there is more
compatibility between Xterm and Konsole than portions of the
infocmp output seem to indicate.

Would you be willing to double-check my thinking here? Examine
the output from ``infocmp xterm konsole`` shown below (trimmed
for size)::

comparing xterm to konsole.
[...]
comparing strings.
[...]
kDC: '\E[3;2~', NULL.
kEND: '\E[1;2F', NULL.
[...]
kf13: '\E[1;2P', '\EO2P'.
kf14: '\E[1;2Q', '\EO2Q'.
kf15: '\E[1;2R', '\EO2R'.
kf16: '\E[1;2S', '\EO2S'.
kf25: '\E[1;5P', '\EO5P'.
kf26: '\E[1;5Q', '\EO5Q'.
kf27: '\E[1;5R', '\EO5R'.
kf28: '\E[1;5S', '\EO5S'.

From man terminfo, it appears that kDC corresponds to
Shift-delete. According to infocmp, Xterm sends \E[3;2~, and
Konsole sends nothing (or unknown).

Using tack to verify the codes, it seems that both terminals
send the same keycode.

Running in Konsole, but pretending to be Xterm:

tack xterm

Testing tools | Testing function keys | run standard tests
(press Shift-Delete)
^[[3;2~ (kDC)

Running in Konsole, and claiming to be Konsole:

tack konsole
Testing tools | Testing function keys | run standard tests
(press Shift-Delete)
^[[3;2~ Unknown

When masquerading as Xterm, tack correctly identifies
Shift-Delete as kDC, but it's Unknown when claiming to be
Konsole.

Differences like this made me think the terminfo entry was for
an older revision of Konsole. If it's intended to match modern
Konsole, should it be updated to include these new codes, or
does this cause backward-compatibility problems?

The differences in kf13 and onward seem to stem from behavioral
difference between Xterm and Konsole for modified <F1> through
<F4>. Terminfo for konsole seems to correctly match Konsole's
out-of-the-box behavior. But more confusion is brought on by
adding Vim into the mix. Using Vim's 'ttybuiltin' feature (on
by default), Vim defines some keycodes when TERM=xterm that make
for much better support for modified function keys and the like.
For example, run Vim as follows in either an Xterm or Konsole,
but making sure to have TERM=xterm to get Vim's builtin support
for xterm:

vim -u NONE '+set nocp | source fixkeytest.vim'

The fixkeytest.vim script is found here:
https://github.com/drmikehenry/vim-fixkey/blob/master/scripts/fixkeytest.vim

Now examine the setting for <F5>:

:set <F5>
t_k5 <F5> ^[[15;*~

This matches the behavior of both Xterm and Konsole, using the
magic xterm ";*" sequence for modifiers, and it matches terminfo
as well. Vim correctly identifies <F5>, <S-F5>, <M-S-F5>, etc.
If enter insert mode in Vim, you can press these keys to show
them working using fixkeytest.vim.

Interestingly, Vim doesn't have built-in support for
term=konsole, but the support for TERM=xterm in Vim matches
Konsole's definition of modified <F1> through <F4> instead of
Xterm's. So if you are running in Fedora 19's Konsole, the
above testing will show <F1> through <F4> working as well, but
when running in a real Xterm, it doesn't work.

Vim's definitions when TERM=xterm are:

:set <f1>
t_k1 <F1> ^[[11;*~

:set <xf1>
<xF1> ^[O*P

According to terminfo, this is what Konsole should send, not
what Xterm should send. With kf13 representing Shift-F1:

infocmp xterm | egrep -o 'kf13\S+'
kf13=\E[1;2P,

infocmp konsole | egrep -o 'kf13\S+'
kf13=\EO2P,

Empirically, Konsole sends \EOP for <F1> and \EO*P for modified
versions of <F1>, whereas Xterm sends \EOP for <F1> and \E[1;*P
for modified versions of <F1>. Do you think that Vim's code was
based on old behavior of Xterm, or was it perhaps developed on
Konsole with the belief that Konsole's claim of Xterm
compatibility was accurate?

For reference, here is a portion of Vim's term.c which defines
the built-in "xterm" terminal settings.

# if defined(UNIX) || defined(ALL_BUILTIN_TCAPS) ||
defined(SOME_BUILTIN_TCAPS) || defined(__EMX__)
{(int)KS_NAME, "xterm"},
[...]
/* An extra set of function keys for vt100 mode */
{K_XF1, IF_EB("\033O*P", ESC_STR "O*P")},
{K_XF2, IF_EB("\033O*Q", ESC_STR "O*Q")},
{K_XF3, IF_EB("\033O*R", ESC_STR "O*R")},
{K_XF4, IF_EB("\033O*S", ESC_STR "O*S")},
{K_F1, IF_EB("\033[11;*~", ESC_STR "[11;*~")},
{K_F2, IF_EB("\033[12;*~", ESC_STR "[12;*~")},
{K_F3, IF_EB("\033[13;*~", ESC_STR "[13;*~")},
{K_F4, IF_EB("\033[14;*~", ESC_STR "[14;*~")},
{K_F5, IF_EB("\033[15;*~", ESC_STR "[15;*~")},
{K_F6, IF_EB("\033[17;*~", ESC_STR "[17;*~")},
{K_F7, IF_EB("\033[18;*~", ESC_STR "[18;*~")},
{K_F8, IF_EB("\033[19;*~", ESC_STR "[19;*~")},
{K_F9, IF_EB("\033[20;*~", ESC_STR "[20;*~")},
{K_F10, IF_EB("\033[21;*~", ESC_STR "[21;*~")},
{K_F11, IF_EB("\033[23;*~", ESC_STR "[23;*~")},
{K_F12, IF_EB("\033[24;*~", ESC_STR "[24;*~")},

Thanks for your patience, and I apologize again for my previous
(and possible current :-) confusion.

Michael Henry

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: