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) {
|
func Init(noColor bool) {
|
||||||
color.Init(noColor)
|
color.Init(noColor, false)
|
||||||
if !noColor {
|
if !noColor {
|
||||||
HeaderBgColor = tablewriter.BgBlackColor
|
HeaderBgColor = tablewriter.BgBlackColor
|
||||||
HeaderFgColor = tablewriter.FgGreenColor
|
HeaderFgColor = tablewriter.FgGreenColor
|
||||||
|
|
|
@ -4,17 +4,22 @@ import (
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Color is an alias to color.Color
|
||||||
|
type Color = color.Color
|
||||||
|
|
||||||
var (
|
var (
|
||||||
BoldGreen *color.Color
|
BoldGreen *Color
|
||||||
BoldRed *color.Color
|
BoldRed *Color
|
||||||
BoldYellow *color.Color
|
BoldYellow *Color
|
||||||
BoldFgCyan *color.Color
|
BoldFgCyan *Color
|
||||||
)
|
)
|
||||||
|
|
||||||
func Init(noColor bool) {
|
func Init(noColor bool, force bool) {
|
||||||
toggleColor := func(c *color.Color) *color.Color {
|
toggleColor := func(c *Color) *Color {
|
||||||
if noColor {
|
if noColor {
|
||||||
c.DisableColor()
|
c.DisableColor()
|
||||||
|
} else if force {
|
||||||
|
c.EnableColor()
|
||||||
}
|
}
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,14 +8,23 @@ func TestInit(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
noColor bool
|
noColor bool
|
||||||
|
force bool
|
||||||
}{{
|
}{{
|
||||||
noColor: true,
|
noColor: true,
|
||||||
|
force: false,
|
||||||
|
}, {
|
||||||
|
noColor: true,
|
||||||
|
force: true,
|
||||||
}, {
|
}, {
|
||||||
noColor: false,
|
noColor: false,
|
||||||
|
force: false,
|
||||||
|
}, {
|
||||||
|
noColor: false,
|
||||||
|
force: true,
|
||||||
}}
|
}}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
Init(tt.noColor)
|
Init(tt.noColor, tt.force)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue