Merge pull request #1737 from estesp/progress-line-fixup
Handle progress line length properly for formatting
This commit is contained in:
commit
d15cee0358
@ -4,11 +4,16 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/containerd/console"
|
"github.com/containerd/console"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
regexCleanLine = regexp.MustCompile("\x1b\\[[0-9]+m[\x1b]?")
|
||||||
|
)
|
||||||
|
|
||||||
// Writer buffers writes until flush, at which time the last screen is cleared
|
// Writer buffers writes until flush, at which time the last screen is cleared
|
||||||
// and the current buffer contents are written. This is useful for
|
// and the current buffer contents are written. This is useful for
|
||||||
// implementing progress displays, such as those implemented in docker and
|
// implementing progress displays, such as those implemented in docker and
|
||||||
@ -48,7 +53,7 @@ func (w *Writer) Flush() error {
|
|||||||
strlines := strings.Split(w.buf.String(), "\n")
|
strlines := strings.Split(w.buf.String(), "\n")
|
||||||
w.lines = -1
|
w.lines = -1
|
||||||
for _, line := range strlines {
|
for _, line := range strlines {
|
||||||
w.lines += len(line)/int(ws.Width) + 1
|
w.lines += (len(stripLine(line))-1)/int(ws.Width) + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := w.w.Write(w.buf.Bytes()); err != nil {
|
if _, err := w.w.Write(w.buf.Bytes()); err != nil {
|
||||||
@ -71,3 +76,7 @@ func (w *Writer) clear() error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func stripLine(line string) string {
|
||||||
|
return string(regexCleanLine.ReplaceAll([]byte(line), []byte{}))
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user