output.h 918 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #pragma once
  2. #include "colors.h"
  3. // Note: this is an old interface for printing colors to stream.
  4. // Consider printing elements of `EAnsiCode` directly.
  5. namespace NColorizer {
  6. typedef TStringBuf (TColors::*TColorFunc)() const;
  7. struct TColorHandle {
  8. const TColors* C;
  9. TColorFunc F;
  10. inline TColorHandle(const TColors* c, TColorFunc f) noexcept
  11. : C(c)
  12. , F(f)
  13. {
  14. }
  15. };
  16. #define DEF(X) \
  17. static inline TColorHandle X() noexcept { \
  18. return TColorHandle(&StdErr(), &TColors::X##Color); \
  19. }
  20. DEF(Old)
  21. DEF(Black)
  22. DEF(Green)
  23. DEF(Cyan)
  24. DEF(Red)
  25. DEF(Purple)
  26. DEF(Brown)
  27. DEF(LightGray)
  28. DEF(DarkGray)
  29. DEF(LightBlue)
  30. DEF(LightGreen)
  31. DEF(LightCyan)
  32. DEF(LightRed)
  33. DEF(LightPurple)
  34. DEF(Yellow)
  35. DEF(White)
  36. #undef DEF
  37. }