only move cursor up if pos > 0

This commit is contained in:
Michael Yang 2023-11-15 14:04:57 -08:00
parent d6ecaa2cbf
commit 7ea905871a

View file

@ -25,7 +25,7 @@ type Progress struct {
}
func NewProgress(w io.Writer) *Progress {
p := &Progress{pos: -1, w: w}
p := &Progress{w: w}
go p.start()
return p
}
@ -71,7 +71,10 @@ func (p *Progress) render() error {
p.mu.Lock()
defer p.mu.Unlock()
fmt.Fprintf(p.w, "\033[%dA", p.pos)
if p.pos > 0 {
fmt.Fprintf(p.w, "\033[%dA", p.pos)
}
for _, state := range p.states {
fmt.Fprintln(p.w, state.String())
}