string_linux.go 863 B

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