Skip to content
Open
2 changes: 1 addition & 1 deletion cmd/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func startProgress() func() {
printProgress("")
fs.LogPrint = oldLogPrint
operations.SyncPrintf = oldSyncPrint
fmt.Println("")
fmt.Fprintln(terminal.Out, "")
return
}
}
Expand Down
3 changes: 0 additions & 3 deletions fs/config/crypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ var (
// When nil, no encryption will be used for saving.
configKey []byte

// PasswordPromptOutput is output of prompt for password
PasswordPromptOutput = os.Stderr

// PassConfigKeyForDaemonization if set to true, the configKey
// is obscured with obscure.Obscure and saved to a temp file
// when it is calculated from the password. The path of that
Expand Down
4 changes: 2 additions & 2 deletions fs/config/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,9 +716,9 @@ func checkPassword(password string) (string, error) {

// GetPassword asks the user for a password with the prompt given.
func GetPassword(prompt string) string {
_, _ = fmt.Fprintln(PasswordPromptOutput, prompt)
_, _ = fmt.Fprintln(terminal.Out, prompt)
for {
_, _ = fmt.Fprint(PasswordPromptOutput, "password:")
_, _ = fmt.Fprint(terminal.Out, "password:")
password := ReadPassword()
password, err := checkPassword(password)
if err == nil {
Expand Down
6 changes: 3 additions & 3 deletions fs/log/redirect_stderr_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import (
"log"
"os"

"github.com/rclone/rclone/fs/config"
"github.com/rclone/rclone/lib/terminal"
"golang.org/x/sys/unix"
)

// redirectStderr to the file passed in
func redirectStderr(f *os.File) {
passPromptFd, err := unix.Dup(int(os.Stderr.Fd()))
termFd, err := unix.Dup(int(os.Stderr.Fd()))
if err != nil {
log.Fatalf("Failed to duplicate stderr: %v", err)
}
config.PasswordPromptOutput = os.NewFile(uintptr(passPromptFd), "passPrompt")
terminal.RawOut = os.NewFile(uintptr(termFd), "termOut")
err = unix.Dup2(int(f.Fd()), int(os.Stderr.Fd()))
if err != nil {
log.Fatalf("Failed to redirect stderr to file: %v", err)
Expand Down
9 changes: 6 additions & 3 deletions lib/terminal/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,21 @@ const (
var (
// make sure that start is only called once
once sync.Once

// RawOut is the underlying *os.File intended for terminal output
RawOut = os.Stderr
)

// Start the terminal - must be called before use
func Start() {
once.Do(func() {
f := os.Stdout
f := RawOut
if !IsTerminal(int(f.Fd())) {
// If stdout not a tty then remove escape codes
// If output is not a tty then remove escape codes
Out = colorable.NewNonColorable(f)
} else if runtime.GOOS == "windows" && os.Getenv("TERM") != "" {
// If TERM is set just use stdout
Out = f
Out = os.Stdout
} else {
Out = colorable.NewColorable(f)
}
Expand Down
2 changes: 1 addition & 1 deletion lib/terminal/terminal_normal.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ func ReadPassword(fd int) ([]byte, error) {

// WriteTerminalTitle writes a string to the terminal title
func WriteTerminalTitle(title string) {
fmt.Printf(ChangeTitle + title + BEL)
fmt.Fprintf(Out, ChangeTitle + title + BEL)
}