feat: render rprompt separately

This commit is contained in:
Jan De Dobbeleer 2021-11-13 19:35:15 +01:00 committed by Jan De Dobbeleer
parent 19544bff9b
commit 1d192d63d8
2 changed files with 30 additions and 0 deletions

View file

@ -254,3 +254,24 @@ func (e *engine) renderTransientPrompt() string {
}
return ""
}
func (e *engine) renderRPrompt() string {
filterRPromptBlock := func(blocks []*Block) *Block {
for _, block := range blocks {
if block.Type == RPrompt {
return block
}
}
return nil
}
block := filterRPromptBlock(e.config.Blocks)
if block == nil {
return ""
}
block.init(e.env, e.writer, e.ansi)
block.setStringValues()
if !block.enabled() {
return ""
}
return block.renderSegments()
}

View file

@ -56,6 +56,7 @@ type args struct {
Author *string
CursorPadding *int
RPromptOffset *int
RPrompt *bool
BGColor *string
StackCount *int
Command *string
@ -141,6 +142,10 @@ func main() {
"rprompt-offset",
40,
"Offset the right prompt with x when using --export-img"),
RPrompt: flag.Bool(
"rprompt",
false,
"Only print the rprompt block"),
BGColor: flag.String(
"bg-color",
"#151515",
@ -230,6 +235,10 @@ func main() {
fmt.Print(engine.renderTooltip(*args.Command))
return
}
if *args.RPrompt {
fmt.Print(engine.renderRPrompt())
return
}
prompt := engine.render()
if !*args.ExportPNG {
fmt.Print(prompt)