ansi.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package richtext
  2. type AnsiPalette (func(string) string)
  3. var defaultPalette = lightPalette
  4. func DefaultPalette() AnsiPalette { return defaultPalette }
  5. const bold = "\033[1m"
  6. const red = "\033[31m"
  7. const green = "\033[32m"
  8. const orange = "\033[33m"
  9. const blue = "\033[34m"
  10. const magenta = "\033[35m"
  11. const cyan = "\033[36m"
  12. const reset = "\033[0m"
  13. func LightPalette() AnsiPalette { return lightPalette }
  14. var lightPalette AnsiPalette = func(tag string) string {
  15. switch tag {
  16. case TAG_EM: return bold
  17. case TAG_HIGHLIGHT: return (bold + red)
  18. case TAG_ERR_NORMAL: return bold
  19. case TAG_ERR_INLINE: return (bold + red)
  20. case TAG_ERR_NOTE: return (bold + magenta)
  21. default: return ""
  22. }
  23. }
  24. func DarkPalette() AnsiPalette { return darkPalette }
  25. var darkPalette AnsiPalette = func(tag string) string {
  26. switch tag {
  27. case TAG_EM: return bold
  28. case TAG_HIGHLIGHT: return (bold + orange)
  29. case TAG_ERR_NORMAL: return bold
  30. case TAG_ERR_INLINE: return (bold + orange)
  31. case TAG_ERR_NOTE: return (bold + cyan)
  32. default: return ""
  33. }
  34. }