string_darwin.go 882 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //go:build darwin
  2. // +build darwin
  3. package color
  4. import (
  5. "fmt"
  6. "math/rand"
  7. "strconv"
  8. )
  9. var _ = RandomColor()
  10. // RandomColor generates a random color.
  11. func RandomColor() string {
  12. return fmt.Sprintf("#%s", strconv.FormatInt(int64(rand.Intn(16777216)), 16))
  13. }
  14. // Yellow ...
  15. func Yellow(msg string) string {
  16. return fmt.Sprintf("\x1b[33m%s\x1b[0m", msg)
  17. }
  18. // Red ...
  19. func Red(msg string) string {
  20. return fmt.Sprintf("\x1b[31m%s\x1b[0m", msg)
  21. }
  22. // Redf ...
  23. func Redf(msg string, arg interface{}) string {
  24. return fmt.Sprintf("\x1b[31m%s\x1b[0m %+v\n", msg, arg)
  25. }
  26. // Blue ...
  27. func Blue(msg string) string {
  28. return fmt.Sprintf("\x1b[34m%s\x1b[0m", msg)
  29. }
  30. // Green ...
  31. func Green(msg string) string {
  32. return fmt.Sprintf("\x1b[32m%s\x1b[0m", msg)
  33. }
  34. // Greenf ...
  35. func Greenf(msg string, arg interface{}) string {
  36. return fmt.Sprintf("\x1b[32m%s\x1b[0m %+v\n", msg, arg)
  37. }