diff --git a/cmd/restic/global.go b/cmd/restic/global.go index e603673df..18dd97d68 100644 --- a/cmd/restic/global.go +++ b/cmd/restic/global.go @@ -210,7 +210,7 @@ func clearLine(w int) string { // ANSI sequences are not supported on Windows cmd shell. if w <= 0 { - if w = terminal.StdoutTerminalWidth(); w <= 0 { + if w = terminal.StdoutWidth(); w <= 0 { return "" } } diff --git a/cmd/restic/progress.go b/cmd/restic/progress.go index 5af108944..b0d80a896 100644 --- a/cmd/restic/progress.go +++ b/cmd/restic/progress.go @@ -71,7 +71,7 @@ func printProgress(status string, final bool) { canUpdateStatus := terminal.StdoutCanUpdateStatus() - w := terminal.StdoutTerminalWidth() + w := terminal.StdoutWidth() if w > 0 { if w < 3 { status = termstatus.Truncate(status, w) diff --git a/internal/terminal/stdio.go b/internal/terminal/stdio.go index 4b11731c9..70e465ccb 100644 --- a/internal/terminal/stdio.go +++ b/internal/terminal/stdio.go @@ -20,8 +20,12 @@ func StdoutCanUpdateStatus() bool { return CanUpdateStatus(os.Stdout.Fd()) } -func StdoutTerminalWidth() int { - w, _, err := term.GetSize(int(os.Stdout.Fd())) +func StdoutWidth() int { + return Width(os.Stdout.Fd()) +} + +func Width(fd uintptr) int { + w, _, err := term.GetSize(int(fd)) if err != nil { return 0 } diff --git a/internal/ui/termstatus/status.go b/internal/ui/termstatus/status.go index e4d9f19bf..71be8ec4e 100644 --- a/internal/ui/termstatus/status.go +++ b/internal/ui/termstatus/status.go @@ -10,7 +10,6 @@ import ( "strings" "unicode" - "golang.org/x/term" "golang.org/x/text/width" "github.com/restic/restic/internal/terminal" @@ -321,9 +320,8 @@ func (t *Terminal) SetStatus(lines []string) { // only truncate interactive status output var width int if t.canUpdateStatus { - var err error - width, _, err = term.GetSize(int(t.fd)) - if err != nil || width <= 0 { + width = terminal.Width(t.fd) + if width <= 0 { // use 80 columns by default width = 80 }