56 if( columns_.size() == 0 ) {
60 size_t len = columns_[0].length();
61 for(
auto const& c : columns_ ) {
62 if( len != c.length() ) {
63 throw std::length_error(
"Table columns are unevenly filled.");
70 assert( current_col_ == 0 );
94 for(
auto& c : columns_ ) {
107 auto const len =
length();
108 columns_.push_back(
Column(label) );
109 for(
size_t i = 0; i < len; ++i ) {
110 columns_.back().append(
"");
112 return columns_.back();
127 columns_[ current_col_ ].append( value );
130 if( current_col_ >= columns_.size() ) {
139 columns_[ current_col_ ].append( style, value );
142 if( current_col_ >= columns_.size() ) {
158 while( current_col_ < columns_.size() ) {
159 columns_[ current_col_ ].append(
"");
174 for(
auto const& c : columns_ ) {
181 for(
size_t i = 0; i <
length(); ++i ) {
182 for(
auto const& c : columns_ ) {
195 out << line.left_border;
196 for(
size_t ci = 0; ci < columns_.size(); ++ci ) {
198 for(
size_t i = 0; i < columns_[ci].width(); ++i ) {
201 if( ci < columns_.size() - 1 ) {
202 out << line.separator;
205 out << line.right_border <<
"\n";
210 write_line(layout.
top);
214 for(
size_t ci = 0; ci < columns_.size(); ++ci ) {
215 columns_[ci].write_label(out);
216 if( ci < columns_.size() - 1 ) {
226 for(
size_t i = 0; i <
length(); ++i ) {
228 for(
size_t ci = 0; ci < columns_.size(); ++ci ) {
229 columns_[ci].write_row(out, i);
230 if( ci < columns_.size() - 1 ) {
238 write_line(layout.
bottom);
243 std::stringstream ss;
250 std::stringstream ss;
271 width_ = std::max( width_, value.size() );
299 if( value > width_ ) {
319 size_t mx = label_.size();
320 for(
auto const& v : data_ ) {
321 mx = std::max( mx, v.second.size() );
338 return data_.at( i ).second;
347 width_ = label_.size();
353 width_ = std::max( width_, value.size() );
354 data_.push_back({
Style(), value });
359 width_ = std::max( width_, value.size() );
360 data_.push_back({ style, value });
370 auto data = data_.at(row);
371 write( stream, data.first, data.second );
379 void Table::Column::write( std::ostream& stream,
Style style, std::string text )
const
381 assert( text.size() <= width_ );
383 if( just_ == Justification::kLeft ) {
384 text = text + std::string(width_ - text.size(),
' ');
386 if( just_ == Justification::kCentered ) {
387 const size_t pad = (width_ - text.size()) / 2;
388 text = std::string(pad,
' ') + text + std::string(width_ - text.size() - pad,
' ');
390 if( just_ == Justification::kRight ) {
391 text = std::string(width_ - text.size(),
' ') + text;
394 stream << style( text );
432 return Binder(*
this, table);
449 f.header.left_border = (condensed ?
"" :
" ");
450 f.header.separator = (condensed ?
" " :
" ");
451 f.header.right_border = (condensed ?
"" :
" ");
453 f.separator.enabled =
true;
454 f.separator.left_border = (condensed ?
"" :
"-");
455 f.separator.filler =
"-";
456 f.separator.separator = (condensed ?
" " :
"- -");
457 f.separator.right_border = (condensed ?
"" :
"-");
468 f.header.left_border = (condensed ?
"" :
" ");
469 f.header.separator = (condensed ?
"|" :
" | ");
470 f.header.right_border = (condensed ?
"" :
" ");
472 f.separator.enabled =
true;
473 f.separator.left_border = (condensed ?
"" :
"-");
474 f.separator.filler =
"-";
475 f.separator.separator = (condensed ?
"+" :
"-+-");
476 f.separator.right_border = (condensed ?
"" :
"-");
487 f.top.enabled =
true;
488 f.top.left_border = (condensed ?
"+" :
"+-");
490 f.top.separator = (condensed ?
"+" :
"-+-");
491 f.top.right_border = (condensed ?
"+" :
"-+");
493 f.header.left_border = (condensed ?
"|" :
"| ");
494 f.header.separator = (condensed ?
"|" :
" | ");
495 f.header.right_border = (condensed ?
"|" :
" |");
508 f.header.left_border = (condensed ?
"" :
" ");
509 f.header.separator = (condensed ?
"│" :
" │ ");
510 f.header.right_border = (condensed ?
"" :
" ");
512 f.separator.enabled =
true;
513 f.separator.left_border = (condensed ?
"" :
"─");
514 f.separator.filler =
"─";
515 f.separator.separator = (condensed ?
"┼" :
"─┼─");
516 f.separator.right_border = (condensed ?
"" :
"─");
527 f.top.enabled =
true;
528 f.top.left_border = (condensed ?
"┌" :
"┌─");
530 f.top.separator = (condensed ?
"┬" :
"─┬─");
531 f.top.right_border = (condensed ?
"┐" :
"─┐");
533 f.header.left_border = (condensed ?
"│" :
"│ ");
534 f.header.separator = (condensed ?
"│" :
" │ ");
535 f.header.right_border = (condensed ?
"│" :
" │");
537 f.separator.enabled =
true;
538 f.separator.left_border = (condensed ?
"├" :
"├─");
539 f.separator.filler =
"─";
540 f.separator.separator = (condensed ?
"┼" :
"─┼─");
541 f.separator.right_border = (condensed ?
"┤" :
"─┤");
545 f.bottom.enabled =
true;
546 f.bottom.left_border = (condensed ?
"└" :
"└─");
547 f.bottom.filler =
"─";
548 f.bottom.separator = (condensed ?
"┴" :
"─┴─");
549 f.bottom.right_border = (condensed ?
"┘" :
"─┘");
558 f.header.left_border = (condensed ?
"" :
" ");
559 f.header.separator = (condensed ?
"║" :
" ║ ");
560 f.header.right_border = (condensed ?
"" :
" ");
562 f.separator.enabled =
true;
563 f.separator.left_border = (condensed ?
"" :
"═");
564 f.separator.filler =
"═";
565 f.separator.separator = (condensed ?
"╬" :
"═╬═");
566 f.separator.right_border = (condensed ?
"" :
"═");
577 f.top.enabled =
true;
578 f.top.left_border = (condensed ?
"╔" :
"╔═");
580 f.top.separator = (condensed ?
"╦" :
"═╦═");
581 f.top.right_border = (condensed ?
"╗" :
"═╗");
583 f.header.left_border = (condensed ?
"║" :
"║ ");
584 f.header.separator = (condensed ?
"║" :
" ║ ");
585 f.header.right_border = (condensed ?
"║" :
" ║");
587 f.separator.enabled =
true;
588 f.separator.left_border = (condensed ?
"╠" :
"╠═");
589 f.separator.filler =
"═";
590 f.separator.separator = (condensed ?
"╬" :
"═╬═");
591 f.separator.right_border = (condensed ?
"╣" :
"═╣");
595 f.bottom.enabled =
true;
596 f.bottom.left_border = (condensed ?
"╚" :
"╚═");
597 f.bottom.filler =
"═";
598 f.bottom.separator = (condensed ?
"╩" :
"═╩═");
599 f.bottom.right_border = (condensed ?
"╝" :
"═╝");