fix(engine): reset segments after write

resolves #5202
This commit is contained in:
Jan De Dobbeleer 2024-07-04 14:23:29 +02:00 committed by Jan De Dobbeleer
parent b97ea11059
commit 51e4faf557

View file

@ -21,7 +21,7 @@ type Engine struct {
Env runtime.Environment Env runtime.Environment
Plain bool Plain bool
console strings.Builder prompt strings.Builder
currentLineLength int currentLineLength int
rprompt string rprompt string
rpromptLength int rpromptLength int
@ -31,12 +31,12 @@ type Engine struct {
} }
func (e *Engine) write(text string) { func (e *Engine) write(text string) {
e.console.WriteString(text) e.prompt.WriteString(text)
} }
func (e *Engine) string() string { func (e *Engine) string() string {
text := e.console.String() text := e.prompt.String()
e.console.Reset() e.prompt.Reset()
return text return text
} }
@ -323,6 +323,9 @@ func (e *Engine) renderBlockSegments(block *config.Block) (string, int) {
e.writeSeparator(true) e.writeSeparator(true)
e.activeSegment = nil
e.previousActiveSegment = nil
return terminal.String() return terminal.String()
} }
@ -348,6 +351,7 @@ func (e *Engine) setActiveSegment(segment *config.Segment) {
func (e *Engine) renderActiveSegment() { func (e *Engine) renderActiveSegment() {
e.writeSeparator(false) e.writeSeparator(false)
switch e.activeSegment.ResolveStyle() { switch e.activeSegment.ResolveStyle() {
case config.Plain, config.Powerline: case config.Plain, config.Powerline:
terminal.Write(color.Background, color.Foreground, e.activeSegment.Text) terminal.Write(color.Background, color.Foreground, e.activeSegment.Text)
@ -365,6 +369,7 @@ func (e *Engine) renderActiveSegment() {
terminal.Write(color.Background, color.Foreground, e.activeSegment.Text) terminal.Write(color.Background, color.Foreground, e.activeSegment.Text)
} }
} }
e.previousActiveSegment = e.activeSegment e.previousActiveSegment = e.activeSegment
terminal.SetParentColors(e.previousActiveSegment.ResolveBackground(), e.previousActiveSegment.ResolveForeground()) terminal.SetParentColors(e.previousActiveSegment.ResolveBackground(), e.previousActiveSegment.ResolveForeground())