colours.rs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //! Colours, colour schemes, and terminal styling.
  2. use ansi_term::Style;
  3. use ansi_term::Color::*;
  4. /// The **colours** are used to paint the input.
  5. #[derive(Debug, Default)]
  6. pub struct Colours {
  7. pub qname: Style,
  8. pub answer: Style,
  9. pub authority: Style,
  10. pub additional: Style,
  11. pub a: Style,
  12. pub aaaa: Style,
  13. pub caa: Style,
  14. pub cname: Style,
  15. pub hinfo: Style,
  16. pub loc: Style,
  17. pub mx: Style,
  18. pub ns: Style,
  19. pub naptr: Style,
  20. pub opt: Style,
  21. pub ptr: Style,
  22. pub sshfp: Style,
  23. pub soa: Style,
  24. pub srv: Style,
  25. pub tlsa: Style,
  26. pub txt: Style,
  27. pub unknown: Style,
  28. }
  29. impl Colours {
  30. /// Create a new colour palette that has a variety of different styles
  31. /// defined. This is used by default.
  32. pub fn pretty() -> Self {
  33. Self {
  34. qname: Blue.bold(),
  35. answer: Style::default(),
  36. authority: Cyan.normal(),
  37. additional: Green.normal(),
  38. a: Green.bold(),
  39. aaaa: Green.bold(),
  40. caa: Red.normal(),
  41. cname: Yellow.normal(),
  42. hinfo: Yellow.normal(),
  43. loc: Yellow.normal(),
  44. mx: Cyan.normal(),
  45. naptr: Green.normal(),
  46. ns: Red.normal(),
  47. opt: Purple.normal(),
  48. ptr: Red.normal(),
  49. sshfp: Cyan.normal(),
  50. soa: Purple.normal(),
  51. srv: Cyan.normal(),
  52. tlsa: Yellow.normal(),
  53. txt: Yellow.normal(),
  54. unknown: White.on(Red),
  55. }
  56. }
  57. /// Create a new colour palette where no styles are defined, causing
  58. /// output to be rendered as plain text without any formatting.
  59. /// This is used when output is not to a terminal.
  60. pub fn plain() -> Self {
  61. Self::default()
  62. }
  63. }