PackageManager just because
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.1 KiB

  1. package Color
  2. import (
  3. "fmt"
  4. "regexp"
  5. "runtime"
  6. )
  7. var (
  8. Success = Green
  9. Info = Teal
  10. Warning = Yellow
  11. Fatal = Red
  12. )
  13. var (
  14. Black = Color("\033[1;30m%s\033[0m")
  15. Red = Color("\033[1;31m%s\033[0m")
  16. Green = Color("\033[1;32m%s\033[0m")
  17. Yellow = Color("\033[1;33m%s\033[0m")
  18. Purple = Color("\033[1;34m%s\033[0m")
  19. Magenta = Color("\033[1;35m%s\033[0m")
  20. Teal = Color("\033[1;36m%s\033[0m")
  21. White = Color("\033[1;37m%s\033[0m")
  22. )
  23. func init() {
  24. if runtime.GOOS != "windows" {
  25. return
  26. }
  27. Black = Color("%s")
  28. Red = Color("%s")
  29. Green = Color("%s")
  30. Yellow = Color("%s")
  31. Purple = Color("%s")
  32. Magenta = Color("%s")
  33. Teal = Color("%s")
  34. White = Color("%s")
  35. }
  36. func Color(colorString string) func(...interface{}) string {
  37. var sprint func(args ...interface{}) string = func(args ...interface{}) string {
  38. return fmt.Sprintf(colorString,
  39. fmt.Sprint(args...))
  40. }
  41. return sprint
  42. }
  43. func Strip(s string) string {
  44. var (
  45. reg *regexp.Regexp
  46. res string
  47. )
  48. reg = regexp.MustCompile(`\033\[.{1,4}m`)
  49. res = reg.ReplaceAllString(s, "${1}")
  50. return res
  51. }