mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-28 04:19:41 -08:00
parent
4879756886
commit
481878262b
|
@ -64,8 +64,9 @@ func (e *Engine) canWriteRightBlock(rprompt bool) bool {
|
|||
func (e *Engine) PrintPrimary() string {
|
||||
// cache a pointer to the color cycle
|
||||
cycle = &e.Config.Cycle
|
||||
firstLine := e.Env.Getenv("POSH_CURSOR_LINE") == "1"
|
||||
for i, block := range e.Config.Blocks {
|
||||
e.renderBlock(block, (i == 0 && e.PromptCount == 1))
|
||||
e.renderBlock(block, (i == 0 && (e.PromptCount == 1 || firstLine)))
|
||||
}
|
||||
if len(e.Config.ConsoleTitleTemplate) > 0 {
|
||||
title := e.getTitleTemplateText()
|
||||
|
|
|
@ -9,6 +9,14 @@ 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() {
|
||||
echo -ne "\033[6n" # ask the terminal for the position
|
||||
read -s -d\[ garbage # discard the first part of the response
|
||||
read -s -d R pos # store the position in bash variable 'pos'
|
||||
export POSH_CURSOR_LINE=${pos%;*}
|
||||
export POSH_CURSOR_COLUMN=${pos#*;}
|
||||
}
|
||||
|
||||
function _omp_start_timer() {
|
||||
::OMP:: get millis
|
||||
}
|
||||
|
@ -28,6 +36,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
|
||||
}
|
||||
|
|
|
@ -18,6 +18,12 @@ local function get_priority_number(name, default)
|
|||
end
|
||||
end
|
||||
|
||||
-- Environment variables
|
||||
|
||||
local function environment_onbeginedit()
|
||||
os.setenv("POSH_CURSOR_LINE", console.getnumlines())
|
||||
end
|
||||
|
||||
-- Local state
|
||||
|
||||
local endedit_time = 0
|
||||
|
@ -245,6 +251,7 @@ end
|
|||
local function builtin_modules_onbeginedit()
|
||||
cache_onbeginedit()
|
||||
duration_onbeginedit()
|
||||
environment_onbeginedit()
|
||||
end
|
||||
|
||||
local function builtin_modules_onendedit(input)
|
||||
|
|
|
@ -353,6 +353,11 @@ Example:
|
|||
if (-not $terminalWidth) {
|
||||
$terminalWidth = 0
|
||||
}
|
||||
|
||||
# set the cursor positions, they are zero based so align with other platforms
|
||||
$env:POSH_CURSOR_LINE = $Host.UI.RawUI.CursorPosition.Y + 1
|
||||
$env:POSH_CURSOR_COLUMN = $Host.UI.RawUI.CursorPosition.X + 1
|
||||
|
||||
$standardOut = @(Start-Utf8Process $script:OMPExecutable @("print", $script:PromptType, "--error=$script:ErrorCode", "--pswd=$cleanPSWD", "--execution-time=$script:ExecutionTime", "--stack-count=$stackCount", "--config=$env:POSH_THEME", "--shell-version=$script:PSVersion", "--terminal-width=$terminalWidth", "--shell=$script:ShellName"))
|
||||
# make sure PSReadLine knows if we have a multiline prompt
|
||||
Set-PSReadLineOption -ExtraPromptLineCount (($standardOut | Measure-Object -Line).Lines - 1)
|
||||
|
|
|
@ -7,6 +7,14 @@ export POSH_PROMPT_COUNT=0
|
|||
# set secondary prompt
|
||||
PS2="$(::OMP:: print secondary --config="$POSH_THEME" --shell=zsh)"
|
||||
|
||||
function _set_posh_cursor_position() {
|
||||
echo -ne "\033[6n" # ask the terminal for the position
|
||||
read -s -d\[ garbage # discard the first part of the response
|
||||
read -s -d R pos # store the position in bash variable 'pos'
|
||||
export POSH_CURSOR_LINE=${pos%;*}
|
||||
export POSH_CURSOR_COLUMN=${pos#*;}
|
||||
}
|
||||
|
||||
# template function for context loading
|
||||
function set_poshcontext() {
|
||||
return
|
||||
|
@ -27,6 +35,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
|
||||
unset omp_now
|
||||
|
|
|
@ -86,7 +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`.
|
||||
Start the block on a new line - defaults to `false`. For `zsh`, `bash`, `pwsh` 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
|
||||
|
||||
|
|
Loading…
Reference in a new issue