Skip to content

Commit aa7686a

Browse files
dssysolyatintnamoradze
authored andcommitted
Change \b to \r<spaces>\r (#3)
1 parent a934721 commit aa7686a

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

progress.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,25 @@ func (p *progressBarImpl) write(s string) error {
119119
}
120120

121121
func (p *progressBarImpl) erase(n int) {
122-
for i := 0; i < n; i++ {
123-
p.writer.Write([]byte{'\b'})
122+
// Don't use '\b' - it's only move cursor to back
123+
b := make([]byte, 0, n+2)
124+
b = append(b, '\r')
125+
for i := 0; i < n; i ++ {
126+
b = append(b, ' ')
124127
}
128+
b = append(b, '\r')
129+
p.writer.Write(b)
125130
}
126131

127132
func (p *progressBarImpl) done() {
128133
p.wMutex.Lock()
129134
defer p.wMutex.Unlock()
130135

131-
p.erase(p.writtenLen)
132-
fmt.Fprintln(p.writer, p.final)
136+
if p.final != "" {
137+
p.erase(p.writtenLen)
138+
fmt.Fprintln(p.writer, p.final)
139+
}
140+
133141
}
134142

135143
func (p *progressBarImpl) output() string {

0 commit comments

Comments
 (0)