colours.rs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 eui48: Style,
  16. pub eui64: Style,
  17. pub hinfo: Style,
  18. pub loc: Style,
  19. pub mx: Style,
  20. pub ns: Style,
  21. pub naptr: Style,
  22. pub openpgpkey: Style,
  23. pub opt: Style,
  24. pub ptr: Style,
  25. pub sshfp: Style,
  26. pub soa: Style,
  27. pub srv: Style,
  28. pub tlsa: Style,
  29. pub txt: Style,
  30. pub uri: Style,
  31. pub unknown: Style,
  32. }
  33. impl Colours {
  34. /// Create a new colour palette that has a variety of different styles
  35. /// defined. This is used by default.
  36. pub fn pretty() -> Self {
  37. Self {
  38. qname: Blue.bold(),
  39. answer: Style::default(),
  40. authority: Cyan.normal(),
  41. additional: Green.normal(),
  42. a: Green.bold(),
  43. aaaa: Green.bold(),
  44. caa: Red.normal(),
  45. cname: Yellow.normal(),
  46. eui48: Yellow.normal(),
  47. eui64: Yellow.bold(),
  48. hinfo: Yellow.normal(),
  49. loc: Yellow.normal(),
  50. mx: Cyan.normal(),
  51. naptr: Green.normal(),
  52. ns: Red.normal(),
  53. openpgpkey: Cyan.normal(),
  54. opt: Purple.normal(),
  55. ptr: Red.normal(),
  56. sshfp: Cyan.normal(),
  57. soa: Purple.normal(),
  58. srv: Cyan.normal(),
  59. tlsa: Yellow.normal(),
  60. txt: Yellow.normal(),
  61. uri: Yellow.normal(),
  62. unknown: White.on(Red),
  63. }
  64. }
  65. /// Create a new colour palette where no styles are defined, causing
  66. /// output to be rendered as plain text without any formatting.
  67. /// This is used when output is not to a terminal.
  68. pub fn plain() -> Self {
  69. Self::default()
  70. }
  71. }