From e72264e01cb24431455ed6e398a769bca0da7ffe Mon Sep 17 00:00:00 2001 From: Roman Perepelitsa Date: Thu, 21 Jul 2022 13:54:51 +0200 Subject: [PATCH] don't trust cnorm as it's incorrect in some combinations of terminals and terminfo (#1699) --- internal/p10k.zsh | 12 ++++++++++-- internal/wizard.zsh | 7 ++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/internal/p10k.zsh b/internal/p10k.zsh index 7c2037f..cf0c7f2 100644 --- a/internal/p10k.zsh +++ b/internal/p10k.zsh @@ -6999,7 +6999,7 @@ function _p9k_reset_prompt() { zle .reset-prompt (( ${+functions[z4h]} )) || zle -R } always { - (( _p9k__can_hide_cursor )) && echoti cnorm + (( _p9k__can_hide_cursor )) && print -rn -- $_p9k__cnorm _p9k__cursor_hidden=0 } fi @@ -7121,6 +7121,14 @@ _p9k_init_vars() { typeset -gi _p9k__restore_prompt_fd typeset -gi _p9k__redraw_fd typeset -gi _p9k__can_hide_cursor=$(( $+terminfo[civis] && $+terminfo[cnorm] )) + if (( _p9k__can_hide_cursor )); then + # See https://github.com/romkatv/powerlevel10k/issues/1699 + if [[ $terminfo[cnorm] == *$'\e[?25h'(|'\e'*) ]]; then + typeset -g _p9k__cnorm=$'\e[?25h' + else + typeset -g _p9k__cnorm=$terminfo[cnorm] + fi + fi typeset -gi _p9k__cursor_hidden typeset -gi _p9k__non_hermetic_expansion typeset -g _p9k__time @@ -7656,7 +7664,7 @@ function _p9k_on_widget_deactivate-region() { _p9k_check_visual_mode; } function _p9k_on_widget_zle-line-init() { (( _p9k__cursor_hidden )) || return 0 _p9k__cursor_hidden=0 - echoti cnorm + print -rn -- $_p9k__cnorm } function _p9k_on_widget_zle-line-finish() { diff --git a/internal/wizard.zsh b/internal/wizard.zsh index 5d6215a..2ffb606 100644 --- a/internal/wizard.zsh +++ b/internal/wizard.zsh @@ -222,7 +222,12 @@ function hide_cursor() { } function show_cursor() { - echoti cnorm 2>/dev/null + local cnorm=${terminfo[cnorm]-} + if [[ $cnorm == *$'\e[?25h'(|'\e'*) ]]; then + print -n '\e[?25h' + else + print -n $cnorm + fi } function consume_input() {