terminal: reuse PasswordPromptOutput for progress output

PasswordPromptOutput is a dup'ed copy of the stderr that the program
started with - in particular, before any redirection for --log-file
was applied.
This commit is contained in:
Carl Edquist 2022-10-04 11:15:34 -05:00
parent 7130a6d2e4
commit 458c477ad8

View File

@ -8,6 +8,8 @@ import (
"runtime" "runtime"
"sync" "sync"
"github.com/rclone/rclone/fs/config"
colorable "github.com/mattn/go-colorable" colorable "github.com/mattn/go-colorable"
) )
@ -73,9 +75,9 @@ var (
// Start the terminal - must be called before use // Start the terminal - must be called before use
func Start() { func Start() {
once.Do(func() { once.Do(func() {
f := os.Stderr f := config.PasswordPromptOutput
if !IsTerminal(int(f.Fd())) { if !IsTerminal(int(f.Fd())) {
// If stderr not a tty then remove escape codes // If output is not a tty then remove escape codes
Out = colorable.NewNonColorable(f) Out = colorable.NewNonColorable(f)
} else if runtime.GOOS == "windows" && os.Getenv("TERM") != "" { } else if runtime.GOOS == "windows" && os.Getenv("TERM") != "" {
// If TERM is set just use stderr // If TERM is set just use stderr