zsh shell integration: Restore cursor to blinking block before running external commands

This commit is contained in:
Kovid Goyal 2022-01-24 22:06:52 +05:30
parent b5a2f94185
commit 1fea4777fa
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -119,21 +119,6 @@ _ksi_deferred_init() {
fpath=($comp_dir ${fpath:#$comp_dir})
fi
# Enable cursor shape changes depending on the current keymap.
if (( ! opt[(Ie)no-cursor] )); then
# This implementation leaks blinking block cursor into external commands
# executed from zle. For example, users of fzf-based widgets may find
# themselves with a blinking block cursor within fzf.
_ksi_zle_line_init _ksi_zle_line_finish _ksi_zle_keymap_select() {
case ${KEYMAP-} in
# Blinking block cursor.
vicmd|visual) builtin print -nu "$_ksi_fd" '\e[1 q';;
# Blinking bar cursor.
*) builtin print -nu "$_ksi_fd" '\e[5 q';;
esac
}
fi
# Enable semantic markup with OSC 133.
if (( ! opt[(Ie)no-prompt-mark] )); then
_ksi_precmd() {
@ -253,6 +238,24 @@ _ksi_deferred_init() {
builtin print -rnu $_ksi_fd \$'\\e]2;'\"\${(V)1}\"\$'\\a'"
fi
# Enable cursor shape changes depending on the current keymap.
if (( ! opt[(Ie)no-cursor] )); then
# This implementation leaks blinking block cursor into external commands
# executed from zle. For example, users of fzf-based widgets may find
# themselves with a blinking block cursor within fzf.
_ksi_zle_line_init _ksi_zle_line_finish _ksi_zle_keymap_select() {
case ${KEYMAP-} in
# Blinking block cursor.
vicmd|visual) builtin print -nu "$_ksi_fd" '\e[1 q';;
# Blinking bar cursor.
*) builtin print -nu "$_ksi_fd" '\e[5 q';;
esac
}
functions[_ksi_preexec]+="
builtin print -rnu $_ksi_fd \$'\\e[1 q'"
fi
# Some zsh users manually run `source ~/.zshrc` in order to apply rc file
# changes to the current shell. This is a terrible practice that breaks many
# things, including our shell integration. For example, Oh My Zsh and Prezto