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