mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-14 11:57:48 +00:00
feat: add force color in color ext pkg (#8767)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
parent
703f7a7666
commit
bd72e42bfe
3 changed files with 22 additions and 8 deletions
|
@ -13,7 +13,7 @@ var (
|
|||
)
|
||||
|
||||
func Init(noColor bool) {
|
||||
color.Init(noColor)
|
||||
color.Init(noColor, false)
|
||||
if !noColor {
|
||||
HeaderBgColor = tablewriter.BgBlackColor
|
||||
HeaderFgColor = tablewriter.FgGreenColor
|
||||
|
|
|
@ -4,17 +4,22 @@ import (
|
|||
"github.com/fatih/color"
|
||||
)
|
||||
|
||||
// Color is an alias to color.Color
|
||||
type Color = color.Color
|
||||
|
||||
var (
|
||||
BoldGreen *color.Color
|
||||
BoldRed *color.Color
|
||||
BoldYellow *color.Color
|
||||
BoldFgCyan *color.Color
|
||||
BoldGreen *Color
|
||||
BoldRed *Color
|
||||
BoldYellow *Color
|
||||
BoldFgCyan *Color
|
||||
)
|
||||
|
||||
func Init(noColor bool) {
|
||||
toggleColor := func(c *color.Color) *color.Color {
|
||||
func Init(noColor bool, force bool) {
|
||||
toggleColor := func(c *Color) *Color {
|
||||
if noColor {
|
||||
c.DisableColor()
|
||||
} else if force {
|
||||
c.EnableColor()
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
|
|
@ -8,14 +8,23 @@ func TestInit(t *testing.T) {
|
|||
tests := []struct {
|
||||
name string
|
||||
noColor bool
|
||||
force bool
|
||||
}{{
|
||||
noColor: true,
|
||||
force: false,
|
||||
}, {
|
||||
noColor: true,
|
||||
force: true,
|
||||
}, {
|
||||
noColor: false,
|
||||
force: false,
|
||||
}, {
|
||||
noColor: false,
|
||||
force: true,
|
||||
}}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
Init(tt.noColor)
|
||||
Init(tt.noColor, tt.force)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue