mirror of
https://github.com/rclone/rclone.git
synced 2025-12-11 22:14:05 +01:00
fs: Add global flag '--color' to control terminal colors
* fs: add TerminalColorMode type * fs: add new config(flags) for TerminalColorMode * lib/terminal: use TerminalColorMode to determine how to handle colors * Add documentation for '--terminal-color-mode' * tree: remove obsolete --color replaced by global --color This changes the default behaviour of tree. It now displays colors by default instead of only displaying them when the flag -C/--color was active. Old behaviour (no color) can be achieved by setting --color to 'never'. Fixes: #6604
This commit is contained in:
74
fs/terminalcolormode_test.go
Normal file
74
fs/terminalcolormode_test.go
Normal file
@@ -0,0 +1,74 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestTerminalColorModeString(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
in TerminalColorMode
|
||||
want string
|
||||
}{
|
||||
{TerminalColorModeAuto, "AUTO"},
|
||||
{TerminalColorModeAlways, "ALWAYS"},
|
||||
{TerminalColorModeNever, "NEVER"},
|
||||
{36, "TerminalColorMode(36)"},
|
||||
} {
|
||||
tcm := test.in
|
||||
assert.Equal(t, test.want, tcm.String(), test.in)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTerminalColorModeSet(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
in string
|
||||
want TerminalColorMode
|
||||
expectError bool
|
||||
}{
|
||||
{"auto", TerminalColorModeAuto, false},
|
||||
{"ALWAYS", TerminalColorModeAlways, false},
|
||||
{"Never", TerminalColorModeNever, false},
|
||||
{"INVALID", 0, true},
|
||||
} {
|
||||
tcm := TerminalColorMode(0)
|
||||
err := tcm.Set(test.in)
|
||||
if test.expectError {
|
||||
require.Error(t, err, test.in)
|
||||
} else {
|
||||
require.NoError(t, err, test.in)
|
||||
}
|
||||
assert.Equal(t, test.want, tcm, test.in)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTerminalColorModeUnmarshalJSON(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
in string
|
||||
want TerminalColorMode
|
||||
expectError bool
|
||||
}{
|
||||
{`"auto"`, TerminalColorModeAuto, false},
|
||||
{`"ALWAYS"`, TerminalColorModeAlways, false},
|
||||
{`"Never"`, TerminalColorModeNever, false},
|
||||
{`"Invalid"`, 0, true},
|
||||
{strconv.Itoa(int(TerminalColorModeAuto)), TerminalColorModeAuto, false},
|
||||
{strconv.Itoa(int(TerminalColorModeAlways)), TerminalColorModeAlways, false},
|
||||
{strconv.Itoa(int(TerminalColorModeNever)), TerminalColorModeNever, false},
|
||||
{`99`, 0, true},
|
||||
{`-99`, 0, true},
|
||||
} {
|
||||
var tcm TerminalColorMode
|
||||
err := json.Unmarshal([]byte(test.in), &tcm)
|
||||
if test.expectError {
|
||||
require.Error(t, err, test.in)
|
||||
} else {
|
||||
require.NoError(t, err, test.in)
|
||||
}
|
||||
assert.Equal(t, test.want, tcm, test.in)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user