Use a default width of 80

to prevent a panic when console.Size() returns 0 width.

Signed-off-by: Daniel Nephin <dnephin@gmail.com>
This commit is contained in:
Daniel Nephin 2018-01-10 14:02:02 -05:00
parent c602b85f80
commit c4b1684528

View File

@ -50,10 +50,14 @@ func (w *Writer) Flush() error {
if err != nil {
return fmt.Errorf("failed to get terminal width: %v", err)
}
width := int(ws.Width)
if width == 0 {
width = 80
}
strlines := strings.Split(w.buf.String(), "\n")
w.lines = -1
for _, line := range strlines {
w.lines += (len(stripLine(line))-1)/int(ws.Width) + 1
w.lines += (len(stripLine(line))-1)/width + 1
}
if _, err := w.w.Write(w.buf.Bytes()); err != nil {