mirror of
https://github.com/rclone/rclone.git
synced 2024-11-26 18:34:41 +01:00
aac2406e19
Adds a flag, --progress-terminal-title, that when used with --progress, will print the string `ETA: %s` to the terminal title. This also adds WriteTerminalTitle to lib/terminal
38 lines
867 B
Go
38 lines
867 B
Go
//+build !js
|
|
|
|
package terminal
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"golang.org/x/crypto/ssh/terminal"
|
|
)
|
|
|
|
// GetSize reads the dimensions of the current terminal or returns a
|
|
// sensible default
|
|
func GetSize() (w, h int) {
|
|
w, h, err := terminal.GetSize(int(os.Stdout.Fd()))
|
|
if err != nil {
|
|
w, h = 80, 25
|
|
}
|
|
return w, h
|
|
}
|
|
|
|
// IsTerminal returns whether the fd passed in is a terminal or not
|
|
func IsTerminal(fd int) bool {
|
|
return terminal.IsTerminal(fd)
|
|
}
|
|
|
|
// ReadPassword reads a line of input from a terminal without local echo. This
|
|
// is commonly used for inputting passwords and other sensitive data. The slice
|
|
// returned does not include the \n.
|
|
func ReadPassword(fd int) ([]byte, error) {
|
|
return terminal.ReadPassword(fd)
|
|
}
|
|
|
|
// WriteTerminalTitle writes a string to the terminal title
|
|
func WriteTerminalTitle(title string) {
|
|
fmt.Printf(ChangeTitle + title + BEL)
|
|
}
|