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.ErrorLine = cfg.ErrorLine != nil || cfg.ValidLine != nil
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 {
shell.RPrompt = true
}

View file

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

View file

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

View file

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