Yet another Go logging library for user-friendly applications, with colors!

colors.go 812B

12345678910111213141516171819202122232425262728293031323334
  1. package log
  2. import (
  3. "fmt"
  4. "github.com/tomnomnom/xtermcolor"
  5. )
  6. type colorLevel int
  7. // Options for color support in your logger.
  8. const (
  9. // NoColor doesn't use any color codes at all (plain text).
  10. NoColor colorLevel = iota
  11. // ANSIColor uses the standard 16 colors supported by most terminals. This
  12. // option is the most portable across platforms.
  13. ANSIColor
  14. // ExtendedColor allows the use of 256 colors supported by most modern
  15. // terminals (24-bit color codes).
  16. ExtendedColor
  17. )
  18. // HexColor is a convenient wrapper around `xtermcolor.FromHexStr` to define colors
  19. // for themes for xterm-256color codes.
  20. func HexColor(hex string) string {
  21. code, err := xtermcolor.FromHexStr(hex)
  22. if err != nil {
  23. code = 201 // bright magenta seems like a good default
  24. }
  25. return fmt.Sprintf("38;5;%d", code)
  26. }