+## set up zkbd-style key array
+if [[ ! -v _sev_force_zkbd && ( -v terminfo || -v termcap ) ]] {
+ # use application (keypad transmit) mode if the terminal supports it
+ # NOTE: we have to do this because termcap/terminfo keys are usually
+ # defined in application mode. terminals that do not define these
+ # capabilities are assumed to always be in application mode.
+ if [[ ( -v terminfo[smkx] && -v terminfo[rmkx] ) ||
+ ( -v termcap[ks] && -v terminfo[ke] ) ]] {
+ autoload -Uz add-zle-hook-widget
+ function _enter-application-mode {
+ [[ -v terminfo[smkx] ]] && echoti smkx || echotc ks
+ }
+ add-zle-hook-widget line-init _enter-application-mode
+ function _exit-application-mode {
+ [[ -v terminfo[rmkx] ]] && echoti rmkx || echotc ke
+ }
+ add-zle-hook-widget line-finish _exit-application-mode
+ trap _exit-application-mode EXIT
+ }
+ # pull keys from terminfo/termcap
+ # TODO: Menu and more Shift- modifiers
+ typeset -gA key
+ typeset -lA newkey
+ if [[ -v terminfo ]] {
+ src=terminfo
+ newkey=(F1 kf1 F2 kf2 F3 kf3 F4 kf4 F5 kf5 F6 kf6 F7 kf7 F8 kf8 F9 kf9
+ F10 kf10 F11 kf11 F12 kf12
+ Backspace kbs
+ Shift-Tab kcbt
+ Insert kich1
+ Home khome
+ PageUp kpp
+ Delete kdch1
+ End kend
+ PageDown knp
+ Up kcuu1
+ Down kcud1
+ Left kcub1
+ Right kcuf1
+ )
+ } elif [[ -v termcap ]] {
+ src=termcap
+ newkey=(F1 k1 F2 k2 F3 k3 F4 k4 F5 k5 F6 k6 F7 k7 F8 k8 F9 k9
+ F10 k\; F11 F1 F12 F2
+ Backspace kb
+ Shift-Tab kB
+ Insert kI
+ Home kh
+ PageUp kP
+ Delete kD
+ End @7
+ PageDown kN
+ Up ku
+ Down kd
+ Left kl
+ Right kr
+ )
+ }
+ for k v (${(kv)newkey}) {
+ key[$k]=${${(P)src}[$v]}
+ }
+ unset k v src newkey
+} else {
+ # use zkbd if termcap/terminfo unavailable