Printer.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #ifndef QLOW_LOGGING_H
  2. #define QLOW_LOGGING_H
  3. #include <iostream>
  4. namespace qlow
  5. {
  6. class Printer;
  7. }
  8. class qlow::Printer :
  9. public std::ostream,
  10. private std::streambuf
  11. {
  12. std::ostream& target;
  13. bool isTty;
  14. static Printer instance;
  15. inline Printer(std::ostream& target, bool isTty) :
  16. std::ostream{ static_cast<std::streambuf*> (this) },
  17. target{ target },
  18. isTty{ isTty } {}
  19. public:
  20. Printer(const Printer&) = delete;
  21. Printer(Printer&&) = delete;
  22. Printer& operator=(const Printer&) = delete;
  23. Printer& operator=(Printer&&) = delete;
  24. enum Color {
  25. BLACK = 0,
  26. RED,
  27. GREEN,
  28. YELLOW,
  29. BLUE,
  30. MAGENTA,
  31. CYAN,
  32. WHITE
  33. };
  34. void foreground(Color color, bool bright);
  35. void background(Color color, bool bright);
  36. void bold(void);
  37. void removeFormatting(void);
  38. inline static Printer& getInstance(void) { return instance; }
  39. protected:
  40. int sync(void) override;
  41. int overflow(int c) override;
  42. };
  43. #endif // QLOW_LOGGING_H