mirror of
https://github.com/restic/restic.git
synced 2025-12-12 05:31:54 +00:00
terminal: cleanup determining width
This commit is contained in:
@@ -210,7 +210,7 @@ func clearLine(w int) string {
|
|||||||
|
|
||||||
// ANSI sequences are not supported on Windows cmd shell.
|
// ANSI sequences are not supported on Windows cmd shell.
|
||||||
if w <= 0 {
|
if w <= 0 {
|
||||||
if w = terminal.StdoutTerminalWidth(); w <= 0 {
|
if w = terminal.StdoutWidth(); w <= 0 {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ func printProgress(status string, final bool) {
|
|||||||
|
|
||||||
canUpdateStatus := terminal.StdoutCanUpdateStatus()
|
canUpdateStatus := terminal.StdoutCanUpdateStatus()
|
||||||
|
|
||||||
w := terminal.StdoutTerminalWidth()
|
w := terminal.StdoutWidth()
|
||||||
if w > 0 {
|
if w > 0 {
|
||||||
if w < 3 {
|
if w < 3 {
|
||||||
status = termstatus.Truncate(status, w)
|
status = termstatus.Truncate(status, w)
|
||||||
|
|||||||
@@ -20,8 +20,12 @@ func StdoutCanUpdateStatus() bool {
|
|||||||
return CanUpdateStatus(os.Stdout.Fd())
|
return CanUpdateStatus(os.Stdout.Fd())
|
||||||
}
|
}
|
||||||
|
|
||||||
func StdoutTerminalWidth() int {
|
func StdoutWidth() int {
|
||||||
w, _, err := term.GetSize(int(os.Stdout.Fd()))
|
return Width(os.Stdout.Fd())
|
||||||
|
}
|
||||||
|
|
||||||
|
func Width(fd uintptr) int {
|
||||||
|
w, _, err := term.GetSize(int(fd))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
"golang.org/x/term"
|
|
||||||
"golang.org/x/text/width"
|
"golang.org/x/text/width"
|
||||||
|
|
||||||
"github.com/restic/restic/internal/terminal"
|
"github.com/restic/restic/internal/terminal"
|
||||||
@@ -321,9 +320,8 @@ func (t *Terminal) SetStatus(lines []string) {
|
|||||||
// only truncate interactive status output
|
// only truncate interactive status output
|
||||||
var width int
|
var width int
|
||||||
if t.canUpdateStatus {
|
if t.canUpdateStatus {
|
||||||
var err error
|
width = terminal.Width(t.fd)
|
||||||
width, _, err = term.GetSize(int(t.fd))
|
if width <= 0 {
|
||||||
if err != nil || width <= 0 {
|
|
||||||
// use 80 columns by default
|
// use 80 columns by default
|
||||||
width = 80
|
width = 80
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user