diff --git a/src/shell/scripts/omp.bash b/src/shell/scripts/omp.bash index 2adce612..b10823e3 100644 --- a/src/shell/scripts/omp.bash +++ b/src/shell/scripts/omp.bash @@ -9,6 +9,26 @@ PS0='${omp_start_time:0:$((omp_start_time="$(_omp_start_timer)",0))}' # set secondary prompt PS2="$(::OMP:: print secondary --config="$POSH_THEME" --shell=bash --shell-version="$BASH_VERSION")" +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 + return + fi + + local oldstty=$(stty -g) + stty raw -echo min 0 + + local COL + local ROW + IFS=';' read -sdR -p $'\E[6n' ROW COL + + stty $oldstty + + export POSH_CURSOR_LINE=${ROW#*[} + export POSH_CURSOR_COLUMN=${COL} +} + function _omp_start_timer() { ::OMP:: get millis } @@ -28,6 +48,7 @@ function _omp_hook() { omp_start_time="" fi set_poshcontext + _set_posh_cursor_position PS1="$(::OMP:: print primary --config="$POSH_THEME" --shell=bash --shell-version="$BASH_VERSION" --error="$ret" --execution-time="$omp_elapsed" --stack-count="$omp_stack_count" | tr -d '\0')" return $ret } diff --git a/src/shell/scripts/omp.zsh b/src/shell/scripts/omp.zsh index 329faacb..1d9a4046 100644 --- a/src/shell/scripts/omp.zsh +++ b/src/shell/scripts/omp.zsh @@ -7,6 +7,28 @@ export POSH_PROMPT_COUNT=0 # set secondary prompt 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 + return + fi + + local oldstty=$(stty -g) + stty raw -echo min 0 + + local pos + echo -en "\033[6n" > /dev/tty + read -r -d R pos + pos=${pos:2} # strip off the esc-[ + local parts=(${(s:;:)pos}) + + stty $oldstty + + export POSH_CURSOR_LINE=${parts[1]} + export POSH_CURSOR_COLUMN=${parts[2]} +} + # template function for context loading function set_poshcontext() { return @@ -27,6 +49,7 @@ function prompt_ohmyposh_precmd() { count=$((POSH_PROMPT_COUNT+1)) export POSH_PROMPT_COUNT=$count set_poshcontext + _set_posh_cursor_position eval "$(::OMP:: print primary --config="$POSH_THEME" --error="$omp_last_error" --execution-time="$omp_elapsed" --stack-count="$omp_stack_count" --eval --shell=zsh --shell-version="$ZSH_VERSION")" unset omp_start_time } diff --git a/website/docs/configuration/block.mdx b/website/docs/configuration/block.mdx index fb732578..1bb4b59e 100644 --- a/website/docs/configuration/block.mdx +++ b/website/docs/configuration/block.mdx @@ -86,8 +86,9 @@ Tells the engine what to do with the block. There are two options: ### Newline -Start the block on a new line - defaults to `false`. For `pwsh` and `cmd` this will not print a newline that's defined -on the first block when the prompt is on the first line (when using clear), or when the shell session starts (1st prompt). +Start the block on a new line - defaults to `false`. For `bash`, `zsh`, `pwsh` and `cmd` this will not print a newline +that's defined on the first block when the prompt is on the first line (when using clear), or when the shell session +starts (1st prompt). ### Alignment