| 40 | namespace tabulate { |
| 41 | |
| 42 | class Printer { |
| 43 | public: |
| 44 | static std::pair<std::vector<size_t>, std::vector<size_t>> |
| 45 | compute_cell_dimensions(TableInternal &table); |
| 46 | |
| 47 | static void print_table(std::ostream &stream, TableInternal &table); |
| 48 | |
| 49 | static void print_row_in_cell(std::ostream &stream, TableInternal &table, |
| 50 | const std::pair<size_t, size_t> &index, |
| 51 | const std::pair<size_t, size_t> &dimension, size_t num_columns, |
| 52 | size_t row_index, |
| 53 | const std::vector<std::string> &splitted_cell_text); |
| 54 | |
| 55 | static bool print_cell_border_top(std::ostream &stream, TableInternal &table, |
| 56 | const std::pair<size_t, size_t> &index, |
| 57 | const std::pair<size_t, size_t> &dimension, size_t num_columns); |
| 58 | static bool print_cell_border_bottom(std::ostream &stream, TableInternal &table, |
| 59 | const std::pair<size_t, size_t> &index, |
| 60 | const std::pair<size_t, size_t> &dimension, |
| 61 | size_t num_columns); |
| 62 | |
| 63 | static void apply_element_style(std::ostream &stream, Color foreground_color, |
| 64 | Color background_color, |
| 65 | const std::vector<FontStyle> &font_style) { |
| 66 | apply_foreground_color(stream, foreground_color); |
| 67 | apply_background_color(stream, background_color); |
| 68 | for (auto &style : font_style) |
| 69 | apply_font_style(stream, style); |
| 70 | } |
| 71 | |
| 72 | static void reset_element_style(std::ostream &stream) { stream << termcolor::reset; } |
| 73 | |
| 74 | private: |
| 75 | static void print_content_left_aligned(std::ostream &stream, const std::string &cell_content, |
| 76 | const Format &format, size_t text_with_padding_size, |
| 77 | size_t column_width) { |
| 78 | |
| 79 | // Apply font style |
| 80 | apply_element_style(stream, *format.font_color_, *format.font_background_color_, |
| 81 | *format.font_style_); |
| 82 | stream << cell_content; |
| 83 | // Only apply font_style to the font |
| 84 | // Not the padding. So calling apply_element_style with font_style = {} |
| 85 | reset_element_style(stream); |
| 86 | apply_element_style(stream, *format.font_color_, *format.font_background_color_, {}); |
| 87 | |
| 88 | if (text_with_padding_size < column_width) { |
| 89 | for (size_t j = 0; j < (column_width - text_with_padding_size); ++j) { |
| 90 | stream << " "; |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | static void print_content_center_aligned(std::ostream &stream, const std::string &cell_content, |
| 96 | const Format &format, size_t text_with_padding_size, |
| 97 | size_t column_width) { |
| 98 | auto num_spaces = column_width - text_with_padding_size; |
| 99 | if (num_spaces % 2 == 0) { |
nothing calls this directly
no outgoing calls
no test coverage detected