Skip to content

Commit

Permalink
fix(cli ui package): change colors lib (#622)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicufk authored Dec 8, 2021
1 parent 2ff735a commit 3af1fee
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 34 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ go 1.16

require (
github.com/Masterminds/semver v1.5.0
github.com/bclicn/color v0.0.0-20180711051946-108f2023dc84
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
github.com/denisbrodbeck/machineid v1.0.1
github.com/dustinkirkland/golang-petname v0.0.0-20191129215211-8e5a1ed0cff0
github.com/gofiber/adaptor/v2 v2.1.14
github.com/gofiber/fiber/v2 v2.22.0
github.com/gookit/color v1.5.0
github.com/kelseyhightower/envconfig v1.4.0
github.com/kubeshop/testkube-operator v0.6.4
github.com/minio/minio-go/v7 v7.0.14
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hC
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/bclicn/color v0.0.0-20180711051946-108f2023dc84 h1:cutFptzj+ospnc1PETUqcSVTH3VQ44Bi0rpt3nE9gvo=
github.com/bclicn/color v0.0.0-20180711051946-108f2023dc84/go.mod h1:Va9ap1qxjAWkIVaW1E9rH0aNgE8SDI5A4n8Ds8P0fAA=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
Expand Down Expand Up @@ -286,6 +284,8 @@ github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5m
github.com/googleapis/gnostic v0.4.1/go.mod h1:LRhVm6pbyptWbWbuZ38d1eyptfvIytN3ir6b65WBswg=
github.com/googleapis/gnostic v0.5.5 h1:9fHAtK0uDfpveeqqo1hkEZJcFvYXAiCN3UutL8F9xHw=
github.com/googleapis/gnostic v0.5.5/go.mod h1:7+EbHbldMins07ALC74bsA81Ovc97DwqyJO1AENw9kA=
github.com/gookit/color v1.5.0 h1:1Opow3+BWDwqor78DcJkJCIwnkviFi+rrOANki9BUFw=
github.com/gookit/color v1.5.0/go.mod h1:43aQb+Zerm/BWh2GnrgOQm7ffz7tvQXEKV6BFMl7wAo=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
Expand Down Expand Up @@ -557,6 +557,8 @@ github.com/xdg-go/scram v1.0.2/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+
github.com/xdg-go/stringprep v1.0.2 h1:6iq84/ryjjeRmMJwxutI51F2GIPlP5BfTvXHeYjyhBc=
github.com/xdg-go/stringprep v1.0.2/go.mod h1:8F9zXuvzgwmyT5DUm4GUfZGDdT3W+LCvS6+da4O5kxM=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8=
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs=
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c h1:3lbZUMbMiGUW/LMkfsEABsc5zNT9+b1CvsJx47JzJ8g=
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c/go.mod h1:UrdRz5enIKZ63MEE3IF9l2/ebyx59GyGgPi+tICQdmM=
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA=
Expand Down
10 changes: 4 additions & 6 deletions pkg/ui/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package ui
import (
"fmt"
"os"

"github.com/bclicn/color"
)

func ExitOnError(item string, errors ...error) {
Expand All @@ -19,7 +17,7 @@ func printAndExit(item string, exitOnError bool, errors ...error) {
if len(errors) > 0 && hasErrors(errors...) {
for _, err := range errors {
if err != nil {
fmt.Printf("%s %s (error: %s)\n\n", color.LightRed("⨯"), color.Red(item), err)
fmt.Printf("%s %s (error: %s)\n\n", LightRed("⨯"), Red(item), err)
if exitOnError {
os.Exit(1)
}
Expand All @@ -28,22 +26,22 @@ func printAndExit(item string, exitOnError bool, errors ...error) {
}

if Verbose {
fmt.Printf("%s %s\n", color.Blue("\xE2\x9C\x94"), color.Green(item))
fmt.Printf("%s %s\n", Blue("\xE2\x9C\x94"), Green(item))
}
}

func WarnOnError(item string, errors ...error) {
if len(errors) > 0 && hasErrors(errors...) {
for _, err := range errors {
if err != nil {
fmt.Printf("%s %s (error: %s)\n\n", color.LightYellow("⨯"), color.Yellow(item), err)
fmt.Printf("%s %s (error: %s)\n\n", LightYellow("⨯"), Yellow(item), err)
return
}
}
}

if Verbose {
fmt.Printf("%s %s\n", color.Blue("\xE2\x9C\x94"), color.Green(item))
fmt.Printf("%s %s\n", Blue("\xE2\x9C\x94"), Green(item))
}
}

Expand Down
4 changes: 1 addition & 3 deletions pkg/ui/logo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package ui

import (
"fmt"

"github.com/bclicn/color"
)

var logo = `
Expand All @@ -17,7 +15,7 @@ var logo = `
`

func Logo() {
fmt.Print(color.Blue(logo))
fmt.Print(Blue(logo))
fmt.Println()
}

Expand Down
42 changes: 20 additions & 22 deletions pkg/ui/printers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"fmt"
"os"
"strings"

"github.com/bclicn/color"
)

// IconMedal emoji
Expand All @@ -21,41 +19,41 @@ func NL() {

// Warn shows warning in terminal
func Success(message string, subMessages ...string) {
fmt.Printf("%s", color.LightYellow(message))
fmt.Printf("%s", LightYellow(message))
for _, sub := range subMessages {
fmt.Printf(" %s", color.LightCyan(sub))
fmt.Printf(" %s", LightCyan(sub))
}
fmt.Printf(" " + IconMedal)
fmt.Println()
}

// Warn shows warning in terminal
func Warn(message string, subMessages ...string) {
fmt.Printf("%s", color.LightYellow(message))
fmt.Printf("%s", LightYellow(message))
for _, sub := range subMessages {
fmt.Printf(" %s", color.LightCyan(sub))
fmt.Printf(" %s", LightCyan(sub))
}
fmt.Println()
}

func LogLine(message string) {
fmt.Printf("%s\n", color.DarkGray(message))
fmt.Printf("%s\n", DarkGray(message))
}

func Info(message string, subMessages ...string) {
fmt.Printf("%s", color.DarkGray(message))
fmt.Printf("%s", DarkGray(message))
for _, sub := range subMessages {
fmt.Printf(" %s", color.LightGray(sub))
fmt.Printf(" %s", LightGray(sub))
}
fmt.Println()
}

func Err(err error) {
fmt.Printf("%s %s %s\n", color.LightRed("⨯"), color.Red(err.Error()), IconError)
fmt.Printf("%s %s %s\n", LightRed("⨯"), Red(err.Error()), IconError)
}

func Errf(err string, params ...interface{}) {
fmt.Printf("%s %s\n", color.LightRed("⨯"), color.Red(fmt.Sprintf(err, params...)))
fmt.Printf("%s %s\n", LightRed("⨯"), Red(fmt.Sprintf(err, params...)))
}

func Fail(err error) {
Expand All @@ -71,8 +69,8 @@ func Failf(err string, params ...interface{}) {
}

func CommandOutput(output []byte, command string, params ...string) {
fullCommand := fmt.Sprintf("%s %s", color.LightCyan(command), color.DarkGray(strings.Join(params, " ")))
fmt.Printf("command: %s\noutput:\n%s\n", color.LightGray(fullCommand), color.DarkGray(string(output)))
fullCommand := fmt.Sprintf("%s %s", LightCyan(command), DarkGray(strings.Join(params, " ")))
fmt.Printf("command: %s\noutput:\n%s\n", LightGray(fullCommand), DarkGray(string(output)))
}

func Medal() {
Expand All @@ -82,41 +80,41 @@ func Medal() {
func Completed(main string, sub ...string) {
fmt.Println()
if len(sub) == 1 {
fmt.Printf("%s: %s\n", color.LightGray(main), color.LightBlue(sub[0]))
fmt.Printf("%s: %s\n", LightGray(main), LightBlue(sub[0]))
} else {
fmt.Println(color.LightGray(main), color.LightBlue(strings.Join(sub, " ")))
fmt.Println(LightGray(main), LightBlue(strings.Join(sub, " ")))
}
}

func GroupCompleted(main string, sub ...string) {
fmt.Println()
line := strings.Repeat("=", calculateMessageLength(main, sub...))
fmt.Println(color.LightBlue(line))
fmt.Println(LightBlue(line))
if len(sub) == 1 {
fmt.Printf("%s: %s", color.LightGray(main), color.LightBlue(sub[0]))
fmt.Printf("%s: %s", LightGray(main), LightBlue(sub[0]))
} else {
fmt.Println(color.LightGray(main))
fmt.Println(LightGray(main))
}
}

func InfoGrid(table map[string]string) {
for k, v := range table {
fmt.Printf(" %s: %s\n", color.DarkGray(k), color.LightBlue(v))
fmt.Printf(" %s: %s\n", DarkGray(k), LightBlue(v))
}
fmt.Println()
}

func Vector(table []string) {
for _, v := range table {
fmt.Printf(" %s\n", color.DarkGray(v))
fmt.Printf(" %s\n", DarkGray(v))
}
}

// Warn shows warning in terminal
func ShellCommand(title string, commands ...string) {
fmt.Printf("%s:\n", color.White(title))
fmt.Printf("%s:\n", White(title))
for _, sub := range commands {
fmt.Printf("$ %s\n", color.LightGray(sub))
fmt.Printf("$ %s\n", LightGray(sub))
}
fmt.Println()
}
Expand Down
17 changes: 17 additions & 0 deletions pkg/ui/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ui

import "github.com/gookit/color"

var (
White = color.FgWhite.Render
Blue = color.FgBlue.Render
Green = color.FgGreen.Render
Yellow = color.FgYellow.Render
Red = color.FgRed.Render
LightYellow = color.FgLightYellow.Render
LightCyan = color.FgLightCyan.Render
LightGray = color.FgGray.Render
LightRed = color.FgLightRed.Render
LightBlue = color.FgLightBlue.Render
DarkGray = color.FgDarkGray.Render
)

0 comments on commit 3af1fee

Please sign in to comment.