forked from TrueCloudLab/rclone
cmd: add --progress-terminal-title to print ETA to terminal title
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
This commit is contained in:
parent
6dc28ef50a
commit
aac2406e19
8 changed files with 33 additions and 0 deletions
|
@ -36,6 +36,7 @@ import (
|
||||||
"github.com/rclone/rclone/fs/rc/rcflags"
|
"github.com/rclone/rclone/fs/rc/rcflags"
|
||||||
"github.com/rclone/rclone/fs/rc/rcserver"
|
"github.com/rclone/rclone/fs/rc/rcserver"
|
||||||
"github.com/rclone/rclone/lib/atexit"
|
"github.com/rclone/rclone/lib/atexit"
|
||||||
|
"github.com/rclone/rclone/lib/terminal"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
)
|
)
|
||||||
|
@ -289,6 +290,11 @@ func Run(Retry bool, showStats bool, cmd *cobra.Command, f func() error) {
|
||||||
}
|
}
|
||||||
fs.Debugf(nil, "%d go routines active\n", runtime.NumGoroutine())
|
fs.Debugf(nil, "%d go routines active\n", runtime.NumGoroutine())
|
||||||
|
|
||||||
|
if fs.Config.Progress && fs.Config.ProgressTerminalTitle {
|
||||||
|
// Clear terminal title
|
||||||
|
terminal.WriteTerminalTitle("")
|
||||||
|
}
|
||||||
|
|
||||||
// dump all running go-routines
|
// dump all running go-routines
|
||||||
if fs.Config.Dump&fs.DumpGoRoutines != 0 {
|
if fs.Config.Dump&fs.DumpGoRoutines != 0 {
|
||||||
err := pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
|
err := pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
|
||||||
|
|
|
@ -1108,6 +1108,11 @@ Note: On Windows until [this bug](https://github.com/Azure/go-ansiterm/issues/26
|
||||||
is fixed all non-ASCII characters will be replaced with `.` when
|
is fixed all non-ASCII characters will be replaced with `.` when
|
||||||
`--progress` is in use.
|
`--progress` is in use.
|
||||||
|
|
||||||
|
### --progress-terminal-title ###
|
||||||
|
|
||||||
|
This flag, when used with `-P/--progress`, will print the string `ETA: %s`
|
||||||
|
to the terminal title.
|
||||||
|
|
||||||
### -q, --quiet ###
|
### -q, --quiet ###
|
||||||
|
|
||||||
This flag will limit rclone's output to error messages only.
|
This flag will limit rclone's output to error messages only.
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"github.com/rclone/rclone/fs"
|
"github.com/rclone/rclone/fs"
|
||||||
"github.com/rclone/rclone/fs/fserrors"
|
"github.com/rclone/rclone/fs/fserrors"
|
||||||
"github.com/rclone/rclone/fs/rc"
|
"github.com/rclone/rclone/fs/rc"
|
||||||
|
"github.com/rclone/rclone/lib/terminal"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MaxCompletedTransfers specifies maximum number of completed transfers in startedTransfers list
|
// MaxCompletedTransfers specifies maximum number of completed transfers in startedTransfers list
|
||||||
|
@ -282,6 +283,11 @@ func (s *StatsInfo) String() string {
|
||||||
xfrchkString,
|
xfrchkString,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if fs.Config.ProgressTerminalTitle {
|
||||||
|
// Writes ETA to the terminal title
|
||||||
|
terminal.WriteTerminalTitle("ETA: " + etaString(currentSize, totalSize, speed))
|
||||||
|
}
|
||||||
|
|
||||||
if !fs.Config.StatsOneLine {
|
if !fs.Config.StatsOneLine {
|
||||||
_, _ = buf.WriteRune('\n')
|
_, _ = buf.WriteRune('\n')
|
||||||
errorDetails := ""
|
errorDetails := ""
|
||||||
|
|
|
@ -107,6 +107,7 @@ type ConfigInfo struct {
|
||||||
StatsOneLineDateFormat string // If we want to customize the prefix
|
StatsOneLineDateFormat string // If we want to customize the prefix
|
||||||
ErrorOnNoTransfer bool // Set appropriate exit code if no files transferred
|
ErrorOnNoTransfer bool // Set appropriate exit code if no files transferred
|
||||||
Progress bool
|
Progress bool
|
||||||
|
ProgressTerminalTitle bool
|
||||||
Cookie bool
|
Cookie bool
|
||||||
UseMmap bool
|
UseMmap bool
|
||||||
CaCert string // Client Side CA
|
CaCert string // Client Side CA
|
||||||
|
|
|
@ -110,6 +110,7 @@ func AddFlags(flagSet *pflag.FlagSet) {
|
||||||
flags.StringVarP(flagSet, &fs.Config.StatsOneLineDateFormat, "stats-one-line-date-format", "", fs.Config.StatsOneLineDateFormat, "Enables --stats-one-line-date and uses custom formatted date. Enclose date string in double quotes (\"). See https://golang.org/pkg/time/#Time.Format")
|
flags.StringVarP(flagSet, &fs.Config.StatsOneLineDateFormat, "stats-one-line-date-format", "", fs.Config.StatsOneLineDateFormat, "Enables --stats-one-line-date and uses custom formatted date. Enclose date string in double quotes (\"). See https://golang.org/pkg/time/#Time.Format")
|
||||||
flags.BoolVarP(flagSet, &fs.Config.ErrorOnNoTransfer, "error-on-no-transfer", "", fs.Config.ErrorOnNoTransfer, "Sets exit code 9 if no files are transferred, useful in scripts")
|
flags.BoolVarP(flagSet, &fs.Config.ErrorOnNoTransfer, "error-on-no-transfer", "", fs.Config.ErrorOnNoTransfer, "Sets exit code 9 if no files are transferred, useful in scripts")
|
||||||
flags.BoolVarP(flagSet, &fs.Config.Progress, "progress", "P", fs.Config.Progress, "Show progress during transfer.")
|
flags.BoolVarP(flagSet, &fs.Config.Progress, "progress", "P", fs.Config.Progress, "Show progress during transfer.")
|
||||||
|
flags.BoolVarP(flagSet, &fs.Config.ProgressTerminalTitle, "progress-terminal-title", "", fs.Config.ProgressTerminalTitle, "Show progress on the terminal title. Requires -P/--progress.")
|
||||||
flags.BoolVarP(flagSet, &fs.Config.Cookie, "use-cookies", "", fs.Config.Cookie, "Enable session cookiejar.")
|
flags.BoolVarP(flagSet, &fs.Config.Cookie, "use-cookies", "", fs.Config.Cookie, "Enable session cookiejar.")
|
||||||
flags.BoolVarP(flagSet, &fs.Config.UseMmap, "use-mmap", "", fs.Config.UseMmap, "Use mmap allocator (see docs).")
|
flags.BoolVarP(flagSet, &fs.Config.UseMmap, "use-mmap", "", fs.Config.UseMmap, "Use mmap allocator (see docs).")
|
||||||
flags.StringVarP(flagSet, &fs.Config.CaCert, "ca-cert", "", fs.Config.CaCert, "CA certificate used to verify servers")
|
flags.StringVarP(flagSet, &fs.Config.CaCert, "ca-cert", "", fs.Config.CaCert, "CA certificate used to verify servers")
|
||||||
|
|
|
@ -60,6 +60,9 @@ const (
|
||||||
HiMagentaBg = "\x1b[105m"
|
HiMagentaBg = "\x1b[105m"
|
||||||
HiCyanBg = "\x1b[106m"
|
HiCyanBg = "\x1b[106m"
|
||||||
HiWhiteBg = "\x1b[107m"
|
HiWhiteBg = "\x1b[107m"
|
||||||
|
|
||||||
|
ChangeTitle = "\033]0;"
|
||||||
|
BEL = "\007"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
package terminal
|
package terminal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"golang.org/x/crypto/ssh/terminal"
|
"golang.org/x/crypto/ssh/terminal"
|
||||||
|
@ -29,3 +30,8 @@ func IsTerminal(fd int) bool {
|
||||||
func ReadPassword(fd int) ([]byte, error) {
|
func ReadPassword(fd int) ([]byte, error) {
|
||||||
return terminal.ReadPassword(fd)
|
return terminal.ReadPassword(fd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WriteTerminalTitle writes a string to the terminal title
|
||||||
|
func WriteTerminalTitle(title string) {
|
||||||
|
fmt.Printf(ChangeTitle + title + BEL)
|
||||||
|
}
|
||||||
|
|
|
@ -21,3 +21,8 @@ func IsTerminal(fd int) bool {
|
||||||
func ReadPassword(fd int) ([]byte, error) {
|
func ReadPassword(fd int) ([]byte, error) {
|
||||||
return nil, errors.New("can't read password")
|
return nil, errors.New("can't read password")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WriteTerminalTitle writes a string to the terminal title
|
||||||
|
func WriteTerminalTitle(title string) {
|
||||||
|
// Since there's nothing to return, this is a NOOP
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue