-
Notifications
You must be signed in to change notification settings - Fork 42
/
color_usage.go
78 lines (60 loc) · 1.64 KB
/
color_usage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package cmd
import (
"fmt"
"github.com/gookit/cliapp"
"github.com/gookit/color"
)
var colorOpts = struct {
id int
c string
dir string
}{}
// ColorCommand command definition
func ColorCommand() *cliapp.Command {
cmd := cliapp.Command{
Name: "color",
UseFor: "this is a example for cli color usage",
Aliases: []string{"clr", "colors"},
Func: colorUsage,
Examples: "{$binName} {$cmd} --id 12 -c val ag0 ag1",
}
cmd.IntOpt(&colorOpts.id, "id", "", 2, "the id option")
cmd.StrOpt(&colorOpts.c, "c", "", "value", "the config option")
cmd.StrOpt(&colorOpts.dir, "dir", "", "", "the dir option")
return &cmd
}
func colorUsage(cmd *cliapp.Command, args []string) int {
// simple usage
color.FgCyan.Printf("Simple to use %s\n", "color")
// custom color
color.New(color.FgMagenta, color.BgBlack).Println("custom color style")
// can also:
color.Style{color.FgCyan, color.OpBold}.Println("custom color style")
// use defined color tag
color.Print("<suc>he</><comment>llo</>, <cyan>wel</><red>come</>\n")
// use custom color tag
color.Print("<fg=yellow;bg=black;op=underscore;>hello, welcome</>\n")
// set a color tag
color.Tag("info").Println("info style message")
// prompt message
color.Info.Prompt("prompt style message")
color.Warn.Prompt("prompt style message")
// tips message
color.Info.Tips("tips style message")
color.Warn.Tips("tips style message")
i := 0
fmt.Print("\n- All Available color Tags: \n\n")
for tag, _ := range color.GetColorTags() {
i++
color.Tag(tag).Print(tag)
if i%5 == 0 {
fmt.Print("\n")
} else {
fmt.Print(" ")
}
}
fmt.Print("\n")
return 0
}
func byte8color() {
}