background.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package ansi
  2. import (
  3. "image/color"
  4. )
  5. // SetForegroundColor returns a sequence that sets the default terminal
  6. // foreground color.
  7. //
  8. // OSC 10 ; color ST
  9. // OSC 10 ; color BEL
  10. //
  11. // Where color is the encoded color number.
  12. //
  13. // See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
  14. func SetForegroundColor(c color.Color) string {
  15. return "\x1b]10;" + colorToHexString(c) + "\x07"
  16. }
  17. // RequestForegroundColor is a sequence that requests the current default
  18. // terminal foreground color.
  19. //
  20. // See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
  21. const RequestForegroundColor = "\x1b]10;?\x07"
  22. // SetBackgroundColor returns a sequence that sets the default terminal
  23. // background color.
  24. //
  25. // OSC 11 ; color ST
  26. // OSC 11 ; color BEL
  27. //
  28. // Where color is the encoded color number.
  29. //
  30. // See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
  31. func SetBackgroundColor(c color.Color) string {
  32. return "\x1b]11;" + colorToHexString(c) + "\x07"
  33. }
  34. // RequestBackgroundColor is a sequence that requests the current default
  35. // terminal background color.
  36. //
  37. // See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
  38. const RequestBackgroundColor = "\x1b]11;?\x07"
  39. // SetCursorColor returns a sequence that sets the terminal cursor color.
  40. //
  41. // OSC 12 ; color ST
  42. // OSC 12 ; color BEL
  43. //
  44. // Where color is the encoded color number.
  45. //
  46. // See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
  47. func SetCursorColor(c color.Color) string {
  48. return "\x1b]12;" + colorToHexString(c) + "\x07"
  49. }
  50. // RequestCursorColor is a sequence that requests the current terminal cursor
  51. // color.
  52. //
  53. // See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
  54. const RequestCursorColor = "\x1b]12;?\x07"