doc.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. Package ansi is a small, fast library to create ANSI colored strings and codes.
  3. Installation
  4. # this installs the color viewer and the package
  5. go get -u github.com/mgutz/ansi/cmd/ansi-mgutz
  6. Example
  7. // colorize a string, SLOW
  8. msg := ansi.Color("foo", "red+b:white")
  9. // create a closure to avoid recalculating ANSI code compilation
  10. phosphorize := ansi.ColorFunc("green+h:black")
  11. msg = phosphorize("Bring back the 80s!")
  12. msg2 := phospohorize("Look, I'm a CRT!")
  13. // cache escape codes and build strings manually
  14. lime := ansi.ColorCode("green+h:black")
  15. reset := ansi.ColorCode("reset")
  16. fmt.Println(lime, "Bring back the 80s!", reset)
  17. Other examples
  18. Color(s, "red") // red
  19. Color(s, "red+b") // red bold
  20. Color(s, "red+B") // red blinking
  21. Color(s, "red+u") // red underline
  22. Color(s, "red+bh") // red bold bright
  23. Color(s, "red:white") // red on white
  24. Color(s, "red+b:white+h") // red bold on white bright
  25. Color(s, "red+B:white+h") // red blink on white bright
  26. To view color combinations, from terminal
  27. ansi-mgutz
  28. Style format
  29. "foregroundColor+attributes:backgroundColor+attributes"
  30. Colors
  31. black
  32. red
  33. green
  34. yellow
  35. blue
  36. magenta
  37. cyan
  38. white
  39. Attributes
  40. b = bold foreground
  41. B = Blink foreground
  42. u = underline foreground
  43. h = high intensity (bright) foreground, background
  44. i = inverse
  45. Wikipedia ANSI escape codes [Colors](http://en.wikipedia.org/wiki/ANSI_escape_code#Colors)
  46. */
  47. package ansi