From 61e179ee78a17651156f52d56e954533b17665fb Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Mon, 28 Mar 2022 22:24:15 +0200 Subject: [PATCH] switch to golang.org/x/term --- cmd/restic/global.go | 16 ++++++++-------- go.mod | 1 + internal/ui/termstatus/status.go | 4 ++-- internal/ui/termstatus/terminal_unix.go | 4 ++-- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/cmd/restic/global.go b/cmd/restic/global.go index 945d2091f..8978600af 100644 --- a/cmd/restic/global.go +++ b/cmd/restic/global.go @@ -37,7 +37,7 @@ import ( "os/exec" - "golang.org/x/crypto/ssh/terminal" + "golang.org/x/term" ) var version = "0.13.0-dev (compiled manually)" @@ -145,13 +145,13 @@ func checkErrno(err error) error { } func stdinIsTerminal() bool { - return terminal.IsTerminal(int(os.Stdin.Fd())) + return term.IsTerminal(int(os.Stdin.Fd())) } func stdoutIsTerminal() bool { // mintty on windows can use pipes which behave like a posix terminal, // but which are not a terminal handle - return terminal.IsTerminal(int(os.Stdout.Fd())) || stdoutCanUpdateStatus() + return term.IsTerminal(int(os.Stdout.Fd())) || stdoutCanUpdateStatus() } func stdoutCanUpdateStatus() bool { @@ -159,7 +159,7 @@ func stdoutCanUpdateStatus() bool { } func stdoutTerminalWidth() int { - w, _, err := terminal.GetSize(int(os.Stdout.Fd())) + w, _, err := term.GetSize(int(os.Stdout.Fd())) if err != nil { return 0 } @@ -172,12 +172,12 @@ func stdoutTerminalWidth() int { // program execution must revert changes to the terminal configuration itself. // The terminal configuration is only restored while reading a password. func restoreTerminal() { - if !terminal.IsTerminal(int(os.Stdout.Fd())) { + if !term.IsTerminal(int(os.Stdout.Fd())) { return } fd := int(os.Stdout.Fd()) - state, err := terminal.GetState(fd) + state, err := term.GetState(fd) if err != nil { fmt.Fprintf(os.Stderr, "unable to get terminal state: %v\n", err) return @@ -192,7 +192,7 @@ func restoreTerminal() { if !isReadingPassword { return nil } - err := checkErrno(terminal.Restore(fd, state)) + err := checkErrno(term.Restore(fd, state)) if err != nil { fmt.Fprintf(os.Stderr, "unable to restore terminal state: %v\n", err) } @@ -322,7 +322,7 @@ func readPassword(in io.Reader) (password string, err error) { func readPasswordTerminal(in *os.File, out io.Writer, prompt string) (password string, err error) { fmt.Fprint(out, prompt) isReadingPassword = true - buf, err := terminal.ReadPassword(int(in.Fd())) + buf, err := term.ReadPassword(int(in.Fd())) isReadingPassword = false fmt.Fprintln(out) if err != nil { diff --git a/go.mod b/go.mod index e48168643..c61ca0fd1 100644 --- a/go.mod +++ b/go.mod @@ -31,6 +31,7 @@ require ( golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914 golang.org/x/sync v0.0.0-20210220032951-036812b2e83c golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c + golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 golang.org/x/text v0.3.6 google.golang.org/api v0.50.0 gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637 diff --git a/internal/ui/termstatus/status.go b/internal/ui/termstatus/status.go index ce6593f37..88c4f898e 100644 --- a/internal/ui/termstatus/status.go +++ b/internal/ui/termstatus/status.go @@ -10,7 +10,7 @@ import ( "strings" "unicode" - "golang.org/x/crypto/ssh/terminal" + "golang.org/x/term" "golang.org/x/text/width" ) @@ -321,7 +321,7 @@ func (t *Terminal) SetStatus(lines []string) { var width int if t.canUpdateStatus { var err error - width, _, err = terminal.GetSize(int(t.fd)) + width, _, err = term.GetSize(int(t.fd)) if err != nil || width <= 0 { // use 80 columns by default width = 80 diff --git a/internal/ui/termstatus/terminal_unix.go b/internal/ui/termstatus/terminal_unix.go index 5317d0ac9..719016939 100644 --- a/internal/ui/termstatus/terminal_unix.go +++ b/internal/ui/termstatus/terminal_unix.go @@ -7,7 +7,7 @@ import ( "io" "os" - "golang.org/x/crypto/ssh/terminal" + "golang.org/x/term" ) // clearCurrentLine removes all characters from the current line and resets the @@ -24,7 +24,7 @@ func moveCursorUp(wr io.Writer, fd uintptr) func(io.Writer, uintptr, int) { // CanUpdateStatus returns true if status lines can be printed, the process // output is not redirected to a file or pipe. func CanUpdateStatus(fd uintptr) bool { - if !terminal.IsTerminal(int(fd)) { + if !term.IsTerminal(int(fd)) { return false } term := os.Getenv("TERM")