-
Notifications
You must be signed in to change notification settings - Fork 0
/
usage.go
47 lines (40 loc) · 887 Bytes
/
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
package cmd
import (
"fmt"
"github.com/gookit/color"
)
var colorRender = []func(v any) string{
func(v any) string {
return color.LightRed.Render(v)
},
func(v any) string {
return color.LightGreen.Render(v)
},
func(v any) string {
return color.LightYellow.Render(v)
},
func(v any) string {
return color.LightBlue.Render(v)
},
func(v any) string {
return color.LightMagenta.Render(v)
},
func(v any) string {
return color.LightCyan.Render(v)
},
}
func blue(s string) string {
return color.LightBlue.Render(s)
}
func green(s string) string {
return color.LightGreen.Render(s)
}
func rainbow(s string) string {
s0 := s[0]
return colorRender[int(s0)%(len(colorRender)-1)](s)
}
// rpadx adds padding to the right of a string.
func rpadx(s string, padding int) string {
template := fmt.Sprintf("%%-%ds", padding)
return rainbow(fmt.Sprintf(template, s))
}