summaryrefslogtreecommitdiffstats
path: root/src/testdir/term_util.vim
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-11-27 12:45:41 +0000
committerBram Moolenaar <Bram@vim.org>2022-11-27 12:45:41 +0000
commit9f14557d6a5b4f832029c292d7b3359b68336058 (patch)
tree8165f2a622102d586725e06021c65d6bdeca5bc4 /src/testdir/term_util.vim
parentcc0907165d388e4e8842d3bda9e24ed4d932d6b8 (diff)
patch 9.0.0956: terminal tests fail when using key with modifierv9.0.0956
Problem: Terminal tests fail when using key with modifier. Solution: Use the modifyOtherKeys encoding when using RunVimInTerminal().
Diffstat (limited to 'src/testdir/term_util.vim')
-rw-r--r--src/testdir/term_util.vim39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/testdir/term_util.vim b/src/testdir/term_util.vim
index d748ed057b..dac5a72744 100644
--- a/src/testdir/term_util.vim
+++ b/src/testdir/term_util.vim
@@ -189,4 +189,43 @@ func Term_getlines(buf, lines)
return join(map(a:lines, 'term_getline(a:buf, v:val)'), '')
endfunc
+" When using RunVimInTerminal() we expect modifyOtherKeys level 2 to be enabled
+" automatically. The key + modifier Escape codes must then use the
+" modifyOtherKeys encoding. They are recognized anyway, thus it's safer to use
+" than the raw code.
+
+" Return the modifyOtherKeys level 2 encoding for "key" with "modifier"
+" (number value, e.g. CTRL is 5).
+func GetEscCodeCSI27(key, modifier)
+ let key = printf("%d", char2nr(a:key))
+ let mod = printf("%d", a:modifier)
+ return "\<Esc>[27;" .. mod .. ';' .. key .. '~'
+endfunc
+
+" Return the modifyOtherKeys level 2 encoding for "key" with "modifier"
+" (character value, e.g. CTRL is "C").
+func GetEscCodeWithModifier(modifier, key)
+ let modifier = get({'C': 5}, a:modifier, '')
+ if modifier == ''
+ echoerr 'Unknown modifier: ' .. a:modifier
+ endif
+ return GetEscCodeCSI27(a:key, modifier)
+endfunc
+
+" Return the kitty keyboard protocol encoding for "key" with "modifier"
+" (number value, e.g. CTRL is 5).
+func GetEscCodeCSIu(key, modifier)
+ let key = printf("%d", char2nr(a:key))
+ let mod = printf("%d", a:modifier)
+ return "\<Esc>[" .. key .. ';' .. mod .. 'u'
+endfunc
+
+" Return the kitty keyboard protocol encoding for "key" without a modifier.
+" Used for the Escape key.
+func GetEscCodeCSIuWithoutModifier(key)
+ let key = printf("%d", char2nr(a:key))
+ return "\<Esc>[" .. key .. 'u'
+endfunc
+
+
" vim: shiftwidth=2 sts=2 expandtab