p-ranav / tabulate

Table Maker for Modern C++

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unexpected format when using Table output

neog24 opened this issue · comments

When I try to output the original raw string, the result is as expected as below:

std::cout << plan->toString() << std::endl;
└──Project(v)
    └──Limit(1)
        └──HashJoin
            ├──DelimScan(1)
            └──DelimProduce(1)
                └──NodeScan

But when I try to put the result in a linenoise Table, the format was unexpected:

Table outputTable;
outputTable.add_row({"Plan"});
outputTable.add_row({plan->toString()});
std::cout << outputTable << std::endl;
+--------------------------------------+
| Plan                                 |
+--------------------------------------+
| └──Project(v)                  |
| └──Limit(1)                    |
| └──HashJoin                    |
| ├──DelimScan(1)                |
| └──DelimProduce(1)             |
| └──NodeScan                    |
+--------------------------------------+

Is there anything to do with this?

Two reasons:

  1. tabulate performs a trim operation on each line of each cell to remove whitespace characters from either side of line.
  2. The characters you have there for the tree view are multi-byte characters. So enable multi-byte support in the formatting - that will do the right thing in computing the display width (not the same as character width) for those characters.
#include "tabulate.hpp"
using namespace tabulate;

int main() {
    std::string plan =
	    "└──Project(v)\n"
        "    └──Limit(1)\n"
        "        └──HashJoin\n"
        "            ├──DelimScan(1)\n"
        "            └──DelimProduce(1)\n"
        "                └──NodeScan\n";
        
    Table outputTable;
    outputTable.format()
        .multi_byte_characters(true)
        .trim_mode(Format::TrimMode::kNone);
    outputTable.add_row({"Plan"});
    outputTable.add_row({plan});
    std::cout << outputTable << std::endl;
}

prints

image

That solve my problem, thanks soooo much!