mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-28 20:39:40 -08:00
feat: ignore leading space on clear
This commit is contained in:
parent
3b7604377d
commit
c76e9fd166
|
@ -17,6 +17,7 @@ var (
|
||||||
stackCount int
|
stackCount int
|
||||||
terminalWidth int
|
terminalWidth int
|
||||||
eval bool
|
eval bool
|
||||||
|
cleared bool
|
||||||
|
|
||||||
command string
|
command string
|
||||||
shellVersion string
|
shellVersion string
|
||||||
|
@ -58,6 +59,7 @@ var printCmd = &cobra.Command{
|
||||||
ShellVersion: shellVersion,
|
ShellVersion: shellVersion,
|
||||||
Plain: plain,
|
Plain: plain,
|
||||||
Primary: args[0] == "primary",
|
Primary: args[0] == "primary",
|
||||||
|
Cleared: cleared,
|
||||||
}
|
}
|
||||||
|
|
||||||
eng := engine.New(flags)
|
eng := engine.New(flags)
|
||||||
|
@ -97,6 +99,7 @@ func init() { //nolint:gochecknoinits
|
||||||
printCmd.Flags().IntVarP(&terminalWidth, "terminal-width", "w", 0, "width of the terminal")
|
printCmd.Flags().IntVarP(&terminalWidth, "terminal-width", "w", 0, "width of the terminal")
|
||||||
printCmd.Flags().StringVar(&command, "command", "", "tooltip command")
|
printCmd.Flags().StringVar(&command, "command", "", "tooltip command")
|
||||||
printCmd.Flags().BoolVarP(&plain, "plain", "p", false, "plain text output (no ANSI)")
|
printCmd.Flags().BoolVarP(&plain, "plain", "p", false, "plain text output (no ANSI)")
|
||||||
|
printCmd.Flags().BoolVar(&cleared, "cleared", false, "do we have a clear terminal or not")
|
||||||
printCmd.Flags().BoolVar(&eval, "eval", false, "output the prompt for eval")
|
printCmd.Flags().BoolVar(&eval, "eval", false, "output the prompt for eval")
|
||||||
RootCmd.AddCommand(printCmd)
|
RootCmd.AddCommand(printCmd)
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ func (e *Engine) PrintPrimary() string {
|
||||||
var cancelNewline bool
|
var cancelNewline bool
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
row, _ := e.Env.CursorPosition()
|
row, _ := e.Env.CursorPosition()
|
||||||
cancelNewline = e.Env.Flags().PromptCount == 1 || row == 1
|
cancelNewline = e.Env.Flags().Cleared || e.Env.Flags().PromptCount == 1 || row == 1
|
||||||
}
|
}
|
||||||
e.renderBlock(block, cancelNewline)
|
e.renderBlock(block, cancelNewline)
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,6 +66,7 @@ type Flags struct {
|
||||||
Plain bool
|
Plain bool
|
||||||
Primary bool
|
Primary bool
|
||||||
PromptCount int
|
PromptCount int
|
||||||
|
Cleared bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type CommandError struct {
|
type CommandError struct {
|
||||||
|
|
|
@ -36,7 +36,12 @@ function fish_prompt
|
||||||
set --global --export omp_last_status_generation $status_generation
|
set --global --export omp_last_status_generation $status_generation
|
||||||
end
|
end
|
||||||
set_poshcontext
|
set_poshcontext
|
||||||
::OMP:: print primary --config $POSH_THEME --shell fish --error $omp_status_cache --execution-time $omp_duration --stack-count $omp_stack_count --shell-version $FISH_VERSION
|
# validate if the user cleared the screen
|
||||||
|
set --local omp_cleared false
|
||||||
|
if test (history | head -1) = "clear"
|
||||||
|
set omp_cleared true
|
||||||
|
end
|
||||||
|
::OMP:: print primary --config $POSH_THEME --shell fish --error $omp_status_cache --execution-time $omp_duration --stack-count $omp_stack_count --shell-version $FISH_VERSION --cleared=$omp_cleared
|
||||||
end
|
end
|
||||||
|
|
||||||
function fish_right_prompt
|
function fish_right_prompt
|
||||||
|
|
|
@ -18,7 +18,11 @@ export-env {
|
||||||
# See https://github.com/nushell/nushell/discussions/6402#discussioncomment-3466687.
|
# See https://github.com/nushell/nushell/discussions/6402#discussioncomment-3466687.
|
||||||
let cmd_duration = if $env.CMD_DURATION_MS == "0823" { 0 } else { $env.CMD_DURATION_MS }
|
let cmd_duration = if $env.CMD_DURATION_MS == "0823" { 0 } else { $env.CMD_DURATION_MS }
|
||||||
|
|
||||||
|
# hack to set the cursor line to 1 when the user clears the screen
|
||||||
|
# this obviously isn't bulletproof, but it's a start
|
||||||
|
let clear = (history | last 1 | get 0.command) == "clear"
|
||||||
|
|
||||||
let width = ((term size).columns | into string)
|
let width = ((term size).columns | into string)
|
||||||
^::OMP:: print primary $"--config=($env.POSH_THEME)" --shell=nu $"--shell-version=($env.NU_VERSION)" $"--execution-time=($cmd_duration)" $"--error=($env.LAST_EXIT_CODE)" $"--terminal-width=($width)"
|
^::OMP:: print primary $"--config=($env.POSH_THEME)" --shell=nu $"--shell-version=($env.NU_VERSION)" $"--execution-time=($cmd_duration)" $"--error=($env.LAST_EXIT_CODE)" $"--terminal-width=($width)" $"--cleared=($clear)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue