usage.go 887 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package cmd
  2. import (
  3. "fmt"
  4. "github.com/gookit/color"
  5. )
  6. var colorRender = []func(v any) string{
  7. func(v any) string {
  8. return color.LightRed.Render(v)
  9. },
  10. func(v any) string {
  11. return color.LightGreen.Render(v)
  12. },
  13. func(v any) string {
  14. return color.LightYellow.Render(v)
  15. },
  16. func(v any) string {
  17. return color.LightBlue.Render(v)
  18. },
  19. func(v any) string {
  20. return color.LightMagenta.Render(v)
  21. },
  22. func(v any) string {
  23. return color.LightCyan.Render(v)
  24. },
  25. }
  26. func blue(s string) string {
  27. return color.LightBlue.Render(s)
  28. }
  29. func green(s string) string {
  30. return color.LightGreen.Render(s)
  31. }
  32. func rainbow(s string) string {
  33. s0 := s[0]
  34. return colorRender[int(s0)%(len(colorRender)-1)](s)
  35. }
  36. // rpadx adds padding to the right of a string.
  37. func rpadx(s string, padding int) string {
  38. template := fmt.Sprintf("%%-%ds", padding)
  39. return rainbow(fmt.Sprintf(template, s))
  40. }