From e8563df4edb1bb88be8623820060d206e22a2a0c Mon Sep 17 00:00:00 2001 From: Marlon Richert Date: Fri, 28 May 2021 00:18:03 +0300 Subject: [PATCH] Be smarter about setting terminal keypad mode Fixes issue #273. --- module/.autocomplete.key | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/module/.autocomplete.key b/module/.autocomplete.key index 04b1db4f..9479f57d 100644 --- a/module/.autocomplete.key +++ b/module/.autocomplete.key @@ -3,13 +3,11 @@ zmodload -Fa zsh/terminfo b:echoti p:terminfo builtin autoload -Uz add-zle-hook-widget .autocomplete.key.precmd() { - if [[ -v terminfo[rmkx] ]]; then - .autocomplete.key.normal-mode() { - echoti rmkx - return 0 - } - add-zle-hook-widget line-init .autocomplete.key.normal-mode - fi + .autocomplete.key.set-keypad-mode() { + echoti ${${${key[Up]:#$terminfo[kcuu1]}:+rmkx}:-smkx} 2> /dev/null + return 0 + } + add-zle-hook-widget line-init .autocomplete.key.set-keypad-mode } if [[ ${(t)key} != association ]]; then @@ -17,18 +15,16 @@ if [[ ${(t)key} != association ]]; then typeset -gA key=() fi -key+=( - Control-Space $'\0' - Tab $'\t' - Return $'\r' - Escape $'\e' - Up $'\e[A' - Down $'\e[B' - Right $'\e[C' - Left $'\e[D' - End $'\e[F' - Home $'\e[H' - Shift-Tab $'\e[Z' - PageUp $'\e[5~' - PageDown $'\e[6~' -) +: ${key[Control-Space]:=$'\0'} +: ${key[Tab]:=$'\t'} +: ${key[Return]:=$'\r'} +: ${key[Escape]:=$'\e'} +: ${key[Up]:=$'\e[A'} +: ${key[Down]:=$'\e[B'} +: ${key[Right]:=$'\e[C'} +: ${key[Left]:=$'\e[D'} +: ${key[End]:=$'\e[F'} +: ${key[Home]:=$'\e[H'} +: ${key[Shift-Tab]:=$'\e[Z'} +: ${key[PageUp]:=$'\e[5~'} +: ${key[PageDown]:=$'\e[6~'}