5 #include "../Basics/StringIOIndex.hpp"
6 #include "../Basics/utils.hpp"
7 #include "../Instancing/Instance.hpp"
19 std::string ToText_TableDebugView::write( std::any
const & value )
21 return ::iv::StringIOIndex::Write( value, this->
context() );
26 std::unordered_map< TableId, TableData >
const & tables = this->
Tables();
31 for(
auto & [ table_id, table ] : tables )
32 for(
auto & row : table.rows )
33 for(
auto & [ column_name, column ] : row.columns )
37 std::string base_str = column_name +
": ";
38 max_width = std::max( max_width,
utf8_size( base_str ) );
40 for(
size_t i = 0; i < column.hints.size(); i++ )
42 std::string
const & hint_name = column.hints[ i ].name;
43 std::string base_str =
" " + hint_name +
": ";
44 max_width = std::max( max_width,
utf8_size( base_str ) );
49 for(
auto & [ table_id, table ] : tables )
50 for(
auto & row : table.rows )
52 if( print_table_names )
53 out->
out() <<
"-" << table_id.persistent_value() <<
"-" << std::endl;
55 for(
auto & [ column_name, column ] : row.columns )
60 base_str += column_name +
": ";
63 out->
out() << base_str;
64 for(
size_t i =
utf8_size( base_str ); i < max_width; i++ )
68 std::string pref =
"";
69 for(
size_t i = 0; i < max_width; i++ )
72 out->
out() << this->write( column.value );
76 out->
out() << std::endl;
79 for(
size_t i = 0; i < column.hints.size(); i++ )
81 std::string
const & hint_name = column.hints[ i ].name;
82 std::any
const & hint_val = column.hints[ i ].hint;
84 std::string base_str =
" " + hint_name +
": ";
86 out->
out() << base_str;
87 for(
size_t i =
utf8_size( base_str ); i < max_width; i++ )
90 out->
out() << this->write( hint_val );
91 out->
out() << std::endl;
95 if( print_table_names )
96 out->
out() << std::endl;
102 std::unordered_map< TableId, TableData >
const & tables = this->
Tables();
104 std::map< std::string, size_t > columns;
105 for(
auto & [ table_id, table ] : tables )
109 for(
auto & row : table.rows )
111 for(
auto & [ column_name, column ] : row.columns )
113 size_t & line_size = columns[ column_name ];
116 line_size = std::max( line_size,
utf8_size( column_name ) + 4 );
119 std::string strcol = this->write( column.value );
120 line_size = std::max( line_size,
utf8_size( strcol ) + 2 );
123 for(
auto & [ hint_name, hint ] : column.hints )
125 std::string strhint = this->write( hint );
126 size_t hintsize = 4 +
utf8_size( hint_name ) + 2 +
utf8_size( this->write( hint ) ) + 1;
127 line_size = std::max( line_size, hintsize );
133 if( columns.empty() )
137 size_t title_req_width = 4 +
utf8_size( table_id.persistent_value() ) + 2;
138 size_t total_width = 1;
139 for(
auto & [ colname, colwidth ] : columns )
142 total_width += colwidth + 1;
145 if( total_width < title_req_width )
147 if( columns.empty() )
153 size_t & last_col_width = columns.rbegin()->second;
154 last_col_width += title_req_width - total_width;
159 auto write_vertical_separator = [&](
const char * left,
const char * separator,
const char * right,
const char * filler )
163 for(
auto & [ colname, colwidth ] : columns )
171 for(
size_t i = 0; i < colwidth; i++ )
174 context->out() << right << std::endl;
177 auto write_table_title = [&]( std::string
const & title )
181 auto write_symbol = [&](
const char * symbol )
183 const size_t offset = 3;
186 else if( i == offset )
188 else if( i <= offset + title.size() )
189 context->out() << title[ i - offset - 1 ];
190 else if( i <= offset + title.size() + 1 )
200 for(
auto & [ colname, colwidth ] : columns )
208 for(
size_t i = 0; i < colwidth; i++ )
215 auto write_column_titles = [&]()
219 for(
auto & [ colname, colwidth ] : columns )
226 context->out() <<
" -" << colname <<
"- ";
228 for(
size_t i =
utf8_size( colname ) + 4; i < colwidth; i++ )
231 context->out() <<
"┃" << std::endl;
240 for(
auto & [ colname, colwidth ] : columns )
247 auto it_coldata = row.columns.find( colname );
248 if( it_coldata != row.columns.end() )
251 if( coldata.
hints.size() )
254 std::string coldata_str = this->write( coldata.
value );
255 context->out() <<
' ' << coldata_str <<
' ';
256 for(
size_t i =
utf8_size( coldata_str ) + 2; i < colwidth; i++ )
261 for(
size_t i = 0; i < colwidth; i++ )
265 context->out() <<
"┃" << std::endl;
276 for(
auto & [ colname, colwidth ] : columns )
283 auto it_coldata = row.
columns.find( colname );
284 if( it_coldata != row.
columns.end() )
287 if( coldata.
hints.size() > hint_id )
290 bool last = !( coldata.
hints.size() > hint_id + 1 );
295 auto & [ hint_name, hint_any ] = coldata.
hints[ hint_id ];
296 std::string hint_str = this->write( hint_any );
306 if( !hint_name.empty() )
308 context->out() << hint_name <<
": ";
312 context->out() << hint_str <<
' ';
316 for( ; i < colwidth; i++ )
321 for(
size_t i = 0; i < colwidth; i++ )
327 for(
size_t i = 0; i < colwidth; i++ )
332 context->out() <<
"┃" << std::endl;
339 write_table_title( table_id.persistent_value() );
342 write_column_titles();
345 write_vertical_separator(
"┣",
"┿",
"┫",
"━" );
348 bool first_row =
true;
349 for(
auto const & row : table.rows )
355 write_vertical_separator(
"┠",
"┼",
"┨",
"─" );
358 if( write_column_values( row ) )
361 for(
size_t i = 0; write_column_hints( row, i ); i++ );
366 write_vertical_separator(
"┗",
"┷",
"┛",
"━" );