fix(cursor): only get when needed

resolves #3446
This commit is contained in:
Jan De Dobbeleer 2023-02-04 11:17:10 +01:00 committed by Jan De Dobbeleer
parent 3673267deb
commit 441d1ff0af
4 changed files with 13 additions and 22 deletions

View file

@ -65,7 +65,11 @@ func runInit(shellName string) {
shell.Transient = cfg.TransientPrompt != nil shell.Transient = cfg.TransientPrompt != nil
shell.ErrorLine = cfg.ErrorLine != nil || cfg.ValidLine != nil shell.ErrorLine = cfg.ErrorLine != nil || cfg.ValidLine != nil
shell.Tooltips = len(cfg.Tooltips) > 0 shell.Tooltips = len(cfg.Tooltips) > 0
for _, block := range cfg.Blocks { for i, block := range cfg.Blocks {
// only fetch cursor position when relevant
if i == 0 && block.Newline {
shell.Cursor = true
}
if block.Type == engine.RPrompt { if block.Type == engine.RPrompt {
shell.RPrompt = true shell.RPrompt = true
} }

View file

@ -40,6 +40,7 @@ var (
ErrorLine bool ErrorLine bool
Tooltips bool Tooltips bool
RPrompt bool RPrompt bool
Cursor bool
) )
func getExecutablePath(env platform.Environment) (string, error) { func getExecutablePath(env platform.Environment) (string, error) {
@ -228,6 +229,7 @@ func PrintInit(env platform.Environment) string {
"::ERROR_LINE::", toggleSetting(ErrorLine), "::ERROR_LINE::", toggleSetting(ErrorLine),
"::TOOLTIPS::", toggleSetting(Tooltips), "::TOOLTIPS::", toggleSetting(Tooltips),
"::RPROMPT::", strconv.FormatBool(RPrompt), "::RPROMPT::", strconv.FormatBool(RPrompt),
"::CURSOR::", strconv.FormatBool(Cursor),
).Replace(script) ).Replace(script)
} }

View file

@ -12,7 +12,7 @@ PS2="$(::OMP:: print secondary --config="$POSH_THEME" --shell=bash --shell-versi
function _set_posh_cursor_position() { function _set_posh_cursor_position() {
# not supported in Midnight Commander # not supported in Midnight Commander
# see https://github.com/JanDeDobbeleer/oh-my-posh/issues/3415 # see https://github.com/JanDeDobbeleer/oh-my-posh/issues/3415
if [[ -v MC_SID ]]; then if [[ "::CURSOR::" != "true" ]] || [[ -v MC_SID ]]; then
return return
fi fi

View file

@ -10,7 +10,7 @@ PS2="$(::OMP:: print secondary --config="$POSH_THEME" --shell=zsh)"
function _set_posh_cursor_position() { function _set_posh_cursor_position() {
# not supported in Midnight Commander # not supported in Midnight Commander
# see https://github.com/JanDeDobbeleer/oh-my-posh/issues/3415 # see https://github.com/JanDeDobbeleer/oh-my-posh/issues/3415
if [[ -v MC_SID ]]; then if [[ "::CURSOR::" != "true" ]] || [[ -v MC_SID ]]; then
return return
fi fi
@ -54,25 +54,10 @@ function prompt_ohmyposh_precmd() {
unset omp_start_time unset omp_start_time
} }
function _install-omp-hooks() { # add hook functions
for s in "${preexec_functions[@]}"; do autoload -Uz add-zsh-hook
if [ "$s" = "prompt_ohmyposh_preexec" ]; then add-zsh-hook precmd prompt_ohmyposh_precmd
return add-zsh-hook preexec prompt_ohmyposh_preexec
fi
done
preexec_functions+=(prompt_ohmyposh_preexec)
for s in "${precmd_functions[@]}"; do
if [ "$s" = "prompt_ohmyposh_precmd" ]; then
return
fi
done
precmd_functions+=(prompt_ohmyposh_precmd)
}
if [ "$TERM" != "linux" ]; then
_install-omp-hooks
fi
# perform cleanup so a new initialization in current session works # perform cleanup so a new initialization in current session works
if [[ "$(zle -lL self-insert)" = *"_posh-tooltip"* ]]; then if [[ "$(zle -lL self-insert)" = *"_posh-tooltip"* ]]; then