Ver código fonte

cmd: fix progress bar flickering

Previous code cleared the display before writing new content, creating a
window where the terminal could (and in some cases did) render empty lines.

Instead, we now write new content over the old content, only clearing
the trailing end of lines for cases where the new line is shorter.

Fixes #1664
Jeremy Schlatter 2 meses atrás
pai
commit
faf67db089
1 arquivos alterados com 5 adições e 6 exclusões
  1. 5 6
      progress/progress.go

+ 5 - 6
progress/progress.go

@@ -84,17 +84,16 @@ func (p *Progress) render() {
 	fmt.Fprint(p.w, "\033[?25l")
 	fmt.Fprint(p.w, "\033[?25l")
 	defer fmt.Fprint(p.w, "\033[?25h")
 	defer fmt.Fprint(p.w, "\033[?25h")
 
 
-	// clear already rendered progress lines
-	for i := range p.pos {
-		if i > 0 {
-			fmt.Fprint(p.w, "\033[A")
-		}
-		fmt.Fprint(p.w, "\033[2K\033[1G")
+	// move the cursor back to the beginning
+	for range p.pos - 1 {
+		fmt.Fprint(p.w, "\033[A")
 	}
 	}
+	fmt.Fprint(p.w, "\033[1G")
 
 
 	// render progress lines
 	// render progress lines
 	for i, state := range p.states {
 	for i, state := range p.states {
 		fmt.Fprint(p.w, state.String())
 		fmt.Fprint(p.w, state.String())
+		fmt.Fprintf(p.w, "\033[K")
 		if i < len(p.states)-1 {
 		if i < len(p.states)-1 {
 			fmt.Fprint(p.w, "\n")
 			fmt.Fprint(p.w, "\n")
 		}
 		}