formatted_output.h 888 B

1234567891011121314151617181920212223242526272829303132
  1. #pragma once
  2. #include <util/generic/algorithm.h>
  3. #include <util/generic/vector.h>
  4. #include <util/string/builder.h>
  5. #include <util/memory/tempbuf.h>
  6. namespace NLastGetopt {
  7. /// Utility for printing indented lines. Used by completion generators.
  8. class TFormattedOutput {
  9. public:
  10. struct IndentGuard {
  11. explicit IndentGuard(TFormattedOutput* output);
  12. virtual ~IndentGuard();
  13. TFormattedOutput* Output;
  14. };
  15. public:
  16. /// Increase indentation and return a RAII object that'll decrease it back automatically.
  17. IndentGuard Indent();
  18. /// Append a new indented line to the stream.
  19. TStringBuilder& Line();
  20. /// Collect all lines into a stream.
  21. void Print(IOutputStream& out);
  22. private:
  23. int IndentLevel_ = 0;
  24. TVector<std::pair<int, TStringBuilder>> Lines_;
  25. };
  26. }