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:
tabulate
performs a trim operation on each line of each cell to remove whitespace characters from either side of line.- 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](https://private-user-images.githubusercontent.com/8450091/341217335-809d59ae-ed96-430a-a032-8e611af5fdb0.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE5Nzc4MjQsIm5iZiI6MTcyMTk3NzUyNCwicGF0aCI6Ii84NDUwMDkxLzM0MTIxNzMzNS04MDlkNTlhZS1lZDk2LTQzMGEtYTAzMi04ZTYxMWFmNWZkYjAucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcyNiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MjZUMDcwNTI0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9M2M5M2NkNTFhNmMzODkzNTY1ZDRiNGM3MWQwN2YyOTRiMTQ4MTE0YTU3NmNjNmVlOTM3MTViYTc3MzAyNzIzNiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.7rliqB9881r_Mh9OlO52_h0tKYEhsPADKSUy_ZQTDmI)
That solve my problem, thanks soooo much!