feat(cmd): toggle rprompt from configuration

This commit is contained in:
Jan De Dobbeleer 2022-10-26 07:46:39 +02:00 committed by Jan De Dobbeleer
parent 450ee25f77
commit 877ac59f5f
3 changed files with 8 additions and 7 deletions

View file

@ -64,6 +64,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 {
if block.Type == engine.RPrompt {
shell.RPrompt = true
}
}
if print {
init := shell.PrintInit(env)
fmt.Print(init)

View file

@ -38,6 +38,7 @@ var (
Transient bool
ErrorLine bool
Tooltips bool
RPrompt bool
)
func getExecutablePath(env platform.Environment) (string, error) {
@ -225,6 +226,7 @@ func PrintInit(env platform.Environment) string {
"::TRANSIENT::", toggleSetting(Transient),
"::ERROR_LINE::", toggleSetting(ErrorLine),
"::TOOLTIPS::", toggleSetting(Tooltips),
"::RPROMPT::", strconv.FormatBool(RPrompt),
).Replace(script)
}

View file

@ -23,10 +23,7 @@ end
local endedit_time = 0
local last_duration = 0
local tooltips_enabled = ::TOOLTIPS::
local rprompt_enabled = true
-- REVIEW: OMP could set rprompt_enabled = ::HASRPROMPT:: which could speed up
-- performance for configs that don't have an rprompt, by not needing to invoke
-- OMP an extra time for the rprompt.
local rprompt_enabled = ::RPROMPT::
local cached_prompt = {}
-- Fields in cached_prompt:
@ -232,9 +229,6 @@ function p:rightfilter(prompt)
return (cached_prompt.tooltip or cached_prompt.right), false
end
function p:transientfilter(prompt)
-- REVIEW: this can potentially be expensive and noticable for users; consider
-- optimizing this so the Lua script can natively generate the transient prompt
-- when feasible.
local prompt_exe = string.format('%s print transient --shell=cmd --config=%s %s', omp_exe(), omp_config(), error_level_option())
prompt = run_posh_command(prompt_exe)
if prompt == "" then