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:
LaSombra 2020-10-06 16:34:26 +01:00 committed by GitHub
parent 6dc28ef50a
commit aac2406e19
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 33 additions and 0 deletions

View file

@ -60,6 +60,9 @@ const (
HiMagentaBg = "\x1b[105m"
HiCyanBg = "\x1b[106m"
HiWhiteBg = "\x1b[107m"
ChangeTitle = "\033]0;"
BEL = "\007"
)
var (

View file

@ -3,6 +3,7 @@
package terminal
import (
"fmt"
"os"
"golang.org/x/crypto/ssh/terminal"
@ -29,3 +30,8 @@ func IsTerminal(fd int) bool {
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)
}

View file

@ -21,3 +21,8 @@ func IsTerminal(fd int) bool {
func ReadPassword(fd int) ([]byte, error) {
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
}