| 123 | }; |
| 124 | |
| 125 | void TableMetadataLine::RenderLine(ShellHighlight &highlight, const vector<ShellTableRenderInfo> &table_list, |
| 126 | idx_t line_idx, bool last_line) { |
| 127 | // figure out the table to render |
| 128 | idx_t table_idx = 0; |
| 129 | for (; table_idx < tables.size(); table_idx++) { |
| 130 | idx_t line_count = table_list[tables[table_idx]].LineCount(); |
| 131 | if (line_idx < line_count) { |
| 132 | // line belongs to this table - render it |
| 133 | break; |
| 134 | } |
| 135 | // line belongs to a subsequent table - subtract line count and move to next table |
| 136 | line_idx -= line_count; |
| 137 | } |
| 138 | if (table_idx == tables.size()) { |
| 139 | // we didn't render any table - break |
| 140 | if (!last_line) { |
| 141 | // we need to add spaces if this is not the last line |
| 142 | highlight.PrintText(string(render_width, ' '), PrintOutput::STDOUT, HighlightElementType::LAYOUT); |
| 143 | } |
| 144 | return; |
| 145 | } |
| 146 | auto &render_table = table_list[tables[table_idx]]; |
| 147 | auto &table = render_table.table; |
| 148 | auto layout_type = table.is_view ? HighlightElementType::VIEW_LAYOUT : HighlightElementType::TABLE_LAYOUT; |
| 149 | duckdb::BoxRendererConfig config; |
| 150 | if (line_idx == 0) { |
| 151 | // first line - render layout |
| 152 | string top_line; |
| 153 | top_line = config.LTCORNER; |
| 154 | for (idx_t i = 0; i < render_width - 2; i++) { |
| 155 | top_line += config.HORIZONTAL; |
| 156 | } |
| 157 | top_line += config.RTCORNER; |
| 158 | highlight.PrintText(top_line, PrintOutput::STDOUT, layout_type); |
| 159 | return; |
| 160 | } |
| 161 | if (line_idx == 1) { |
| 162 | // table name |
| 163 | string table_name; |
| 164 | idx_t space_count = render_width - render_table.table_name_length - 2; |
| 165 | idx_t lspace = space_count / 2; |
| 166 | idx_t rspace = space_count - lspace; |
| 167 | string table_line = config.VERTICAL; |
| 168 | table_line += string(lspace, ' '); |
| 169 | highlight.PrintText(table_line, PrintOutput::STDOUT, layout_type); |
| 170 | highlight.PrintText(table.table_name, PrintOutput::STDOUT, HighlightElementType::TABLE_NAME); |
| 171 | table_line = string(rspace, ' '); |
| 172 | table_line += config.VERTICAL; |
| 173 | highlight.PrintText(table_line, PrintOutput::STDOUT, layout_type); |
| 174 | return; |
| 175 | } |
| 176 | if (line_idx > 2 && line_idx < render_table.ColumnLines() + 3) { |
| 177 | idx_t column_idx = line_idx - 3; |
| 178 | // column line |
| 179 | |
| 180 | // if we have a long table name the table name might have stretched out the box |
| 181 | // in that case we need to add padding here |
| 182 | // compute the required padding |
no test coverage detected