From 8d3bcc025a405beb411ee17287f72ddf97fc4979 Mon Sep 17 00:00:00 2001 From: nielash Date: Sat, 23 Dec 2023 15:31:33 -0500 Subject: [PATCH] bisync: fix --colors flag quick fix to get around lack of support in fs.Infof etc. --- cmd/bisync/bisync_test.go | 3 +-- cmd/bisync/log.go | 5 +++++ cmd/bisync/operations.go | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/cmd/bisync/bisync_test.go b/cmd/bisync/bisync_test.go index 2d85edf49..a3e08fefa 100644 --- a/cmd/bisync/bisync_test.go +++ b/cmd/bisync/bisync_test.go @@ -189,8 +189,6 @@ type bisyncTest struct { TestFn bisync.TestFunc } -const TerminalColorMode = fs.TerminalColorModeAlways - var color = bisync.Color // TestBisync is a test engine for bisync test cases. @@ -206,6 +204,7 @@ func TestBisync(t *testing.T) { if *argRefreshTimes { ci.RefreshTimes = true } + bisync.Colors = true baseDir, err := os.Getwd() require.NoError(t, err, "get current directory") diff --git a/cmd/bisync/log.go b/cmd/bisync/log.go index efc91eaed..9d2e5b046 100644 --- a/cmd/bisync/log.go +++ b/cmd/bisync/log.go @@ -62,8 +62,13 @@ func quotePath(path string) string { return escapePath(path, true) } +var Colors bool // Colors controls whether terminal colors are enabled + // Color handles terminal colors for bisync func Color(style string, s string) string { + if !Colors { + return s + } terminal.Start() return style + s + terminal.Reset } diff --git a/cmd/bisync/operations.go b/cmd/bisync/operations.go index 228f88e71..79ed630f3 100644 --- a/cmd/bisync/operations.go +++ b/cmd/bisync/operations.go @@ -17,6 +17,7 @@ import ( "github.com/rclone/rclone/cmd/bisync/bilib" "github.com/rclone/rclone/fs" "github.com/rclone/rclone/fs/accounting" + "github.com/rclone/rclone/fs/log" "github.com/rclone/rclone/fs/operations" "github.com/rclone/rclone/lib/atexit" "github.com/rclone/rclone/lib/terminal" @@ -80,6 +81,10 @@ func Bisync(ctx context.Context, fs1, fs2 fs.Fs, optArg *Options) (err error) { ci := fs.GetConfig(ctx) opt.OrigBackupDir = ci.BackupDir + if ci.TerminalColorMode == fs.TerminalColorModeAlways || (ci.TerminalColorMode == fs.TerminalColorModeAuto && !log.Redirected()) { + Colors = true + } + err = b.setCompareDefaults(ctx) if err != nil { return err