Skip to content

Commit

Permalink
Fix panic on mintty/Windows
Browse files Browse the repository at this point in the history
Closes #1559
  • Loading branch information
Ivan Mirić committed Jul 16, 2020
1 parent 62e1b53 commit 7e1586f
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions cmd/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ const (
maxLeftLength = 30
// Amount of padding in chars between rendered progress
// bar text and right-side terminal window edge.
termPadding = 1
termPadding = 1
defaultTermWidth = 80
)

// A writer that syncs writes with a mutex and, if the output is a TTY, clears before newlines.
Expand Down Expand Up @@ -255,7 +256,7 @@ func showProgress(
termWidth, _, err := terminal.GetSize(int(os.Stdout.Fd()))
if err != nil && stdoutTTY {
logger.WithError(err).Warn("error getting terminal size")
termWidth = 80 // TODO: something safer, return error?
termWidth = defaultTermWidth
}

// Get the longest left side string length, to align progress bars
Expand Down Expand Up @@ -331,11 +332,17 @@ func showProgress(
return
case <-winch:
// More responsive progress bar resizing on platforms with SIGWINCH (*nix)
termWidth, _, _ = terminal.GetSize(fd)
termWidth, _, err = terminal.GetSize(fd)
if err != nil {
termWidth = defaultTermWidth
}
case <-ticker.C:
// Default ticker-based progress bar resizing
if winch == nil {
termWidth, _, _ = terminal.GetSize(fd)
termWidth, _, err = terminal.GetSize(fd)
if err != nil {
termWidth = defaultTermWidth
}
}
}
renderProgressBars(true)
Expand Down

0 comments on commit 7e1586f

Please sign in to comment.