forked from TrueCloudLab/rclone
cmd: Make --progress work on Windows
This commit is contained in:
parent
18685e6b0b
commit
1cccfa7331
3 changed files with 38 additions and 1 deletions
|
@ -114,5 +114,5 @@ func printProgress(logMessage string) {
|
|||
out("\n")
|
||||
}
|
||||
}
|
||||
os.Stdout.Write(buf.Bytes())
|
||||
writeToTerminal(buf.Bytes())
|
||||
}
|
||||
|
|
9
cmd/progress_other.go
Normal file
9
cmd/progress_other.go
Normal file
|
@ -0,0 +1,9 @@
|
|||
//+build !windows
|
||||
|
||||
package cmd
|
||||
|
||||
import "os"
|
||||
|
||||
func writeToTerminal(b []byte) {
|
||||
_, _ = os.Stdout.Write(b)
|
||||
}
|
28
cmd/progress_windows.go
Normal file
28
cmd/progress_windows.go
Normal file
|
@ -0,0 +1,28 @@
|
|||
//+build windows
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
ansiterm "github.com/Azure/go-ansiterm"
|
||||
"github.com/Azure/go-ansiterm/winterm"
|
||||
)
|
||||
|
||||
var (
|
||||
initAnsiParser sync.Once
|
||||
ansiParser *ansiterm.AnsiParser
|
||||
)
|
||||
|
||||
func writeToTerminal(b []byte) {
|
||||
initAnsiParser.Do(func() {
|
||||
winEventHandler := winterm.CreateWinEventHandler(os.Stdout.Fd(), os.Stdout)
|
||||
ansiParser = ansiterm.CreateParser("Ground", winEventHandler)
|
||||
})
|
||||
_, err := ansiParser.Parse(b)
|
||||
if err != nil {
|
||||
_, _ = fmt.Fprintf(os.Stderr, "\n*** Error from ANSI parser: %v\n", err)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue