Util.cpp 680 B

12345678910111213141516171819202122232425262728293031
  1. #include "Util.h"
  2. #include <map>
  3. #include <iostream>
  4. #include <iomanip>
  5. void printTable(const Table& t)
  6. {
  7. std::map<size_t, size_t> maxLenghts;
  8. for (const auto& arr : t) {
  9. for (int i = 0; i < arr.size(); i++) {
  10. if (arr[i].size() > maxLenghts[i])
  11. maxLenghts[i] = arr[i].size();
  12. }
  13. }
  14. bool header = true;
  15. for (const auto& arr : t) {
  16. if (header) {
  17. std::cout << "\033[1m";
  18. header = false;
  19. }
  20. for (int i = 0; i < arr.size(); i++) {
  21. std::cout << std::setw(maxLenghts[i] + 3) << std::left << arr[i];
  22. }
  23. std::cout << "\033[m" << std::endl;
  24. }
  25. }