MCPcopy Create free account
hub / github.com/p-ranav/tabulate / Printer

Class Printer

include/tabulate/printer.hpp:42–251  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40namespace tabulate {
41
42class Printer {
43public:
44 static std::pair<std::vector<size_t>, std::vector<size_t>>
45 compute_cell_dimensions(TableInternal &table);
46
47 // Word-wraps and splits a cell's text into the lines that will be printed,
48 // given the column width it will be rendered at. Shared by print_table()
49 // and TableInternal::print_row() so incremental, per-row printing applies
50 // the exact same word-wrapping as a full print.
51 static std::vector<std::string> split_cell_text(Cell &cell, size_t column_width);
52
53 static void print_table(std::ostream &stream, TableInternal &table);
54
55 static void print_row_in_cell(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 size_t row_index,
59 const std::vector<std::string> &splitted_cell_text);
60
61 static bool print_cell_border_top(std::ostream &stream, TableInternal &table,
62 const std::pair<size_t, size_t> &index,
63 const std::pair<size_t, size_t> &dimension, size_t num_columns);
64 static bool print_cell_border_bottom(std::ostream &stream, TableInternal &table,
65 const std::pair<size_t, size_t> &index,
66 const std::pair<size_t, size_t> &dimension,
67 size_t num_columns);
68
69 static void apply_element_style(std::ostream &stream, Color foreground_color,
70 Color background_color,
71 const std::vector<FontStyle> &font_style) {
72 apply_foreground_color(stream, foreground_color);
73 apply_background_color(stream, background_color);
74 for (auto &style : font_style)
75 apply_font_style(stream, style);
76 }
77
78 static void reset_element_style(std::ostream &stream) { stream << termcolor::reset; }
79
80private:
81 static void print_content_left_aligned(std::ostream &stream, const std::string &cell_content,
82 const Format &format, size_t text_with_padding_size,
83 size_t column_width) {
84
85 // Apply font style
86 apply_element_style(stream, *format.font_color_, *format.font_background_color_,
87 *format.font_style_);
88 stream << cell_content;
89 // Only apply font_style to the font
90 // Not the padding. So calling apply_element_style with font_style = {}
91 reset_element_style(stream);
92 apply_element_style(stream, *format.font_color_, *format.font_background_color_, {});
93
94 if (text_with_padding_size < column_width) {
95 stream << std::string(column_width - text_with_padding_size, ' ');
96 }
97 }
98
99 static void print_content_center_aligned(std::ostream &stream, const std::string &cell_content,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected