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:
parent
c602b85f80
commit
c4b1684528
@ -50,10 +50,14 @@ func (w *Writer) Flush() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to get terminal width: %v", err)
|
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")
|
strlines := strings.Split(w.buf.String(), "\n")
|
||||||
w.lines = -1
|
w.lines = -1
|
||||||
for _, line := range strlines {
|
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 {
|
if _, err := w.w.Write(w.buf.Bytes()); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user