Render tables
swsnr opened this issue · 14 comments
Need a good library to render tables to TTY?
The prettytable is quite nice. The default rendering style is orgmode like, but I recently discoverd that with its formatting features and a few special characters you can do somethinng like this:
#[macro_use] extern crate prettytable;
use prettytable::format::{TableFormat,LinePosition,LineSeparator};
let mut format = TableFormat::new();
format.column_separator('│');
format.borders('│');
format.separator(LinePosition::Top, LineSeparator::new('─', '┬', '┌', '┐'));
format.separator(LinePosition::Title, LineSeparator::new('─', '┼', '├', '┤'));
format.separator(LinePosition::Intern, LineSeparator::new('─', '┼', '├', '┤'));
format.separator(LinePosition::Bottom, LineSeparator::new('─', '┴', '└', '┘'));
format.padding(1, 1);
// Example
let mut table = table!(["A", "B", "C"],
["foo", "bar", "baz"]);
table.set_format(format);
table.printstd();
That will print the table like this:
┌─────┬─────┬─────┐
│ A │ B │ C │
├─────┼─────┼─────┤
│ foo │ bar │ baz │
└─────┴─────┴─────┘
(In the terminal it looks nicer. I get gaps between lines in the browser, which shouln't be there.)
I'd like to take a crack at it! Do you think the program would have to detect if the terminal properly supports Unicode, or would it be ok to use it directly?
And do you have any idea about how wrapping a table would work? Or can that situation be ignored?
@ericonr You can assume a modern terminal with decent font, unicode and all. It's 2020 after all.
As for wrapping, no, I don't. That's something you'll need to figure out if you'd like to try it. I don't know how it could look like, it just needs to, well, kinda work for the general case, as measured by my gut feeling 😉 )
Maybe something like html-table-to-markdown-converter. An then we can write a simple display module. I am assuming the pushdown_markdown parser generates HTML. Maybe this converter could be used when we see a Hmtl table as well.
Are there any recent plans to add support for this in mdcat?
Are there any recent plans to add support for this in mdcat?
No, I do not have any such plans, hence the "Help wanted" label.
This won't get done any time soon unless some opens a good pull request about it.
I am thinking of working on this issue during my holiday/lockdown break. It will depend on my availability with my family. I will need to familiarize myself with all the latest changes first.
Any update on this? It seems like Clima can kinda do this, but doesn't work on everything, specifically only local files
No there's not. If there was you'd see it. Meanwhile, pull requests welcome. My last comment still stands.
Just tested mdcat with https://github.com/sainnhe/gruvbox-material/blob/master/README.md and that did not go well... uses images inside of tables. So I guess, that might be a good test case.
Closing this, because I don't intend to do implement table support any time soon.
Pull requests are welcome.
If you don't mind a little work, I have a script in my dot files which renders markdown, with images, tables etc. Its still rough but mostly works, more of an experiment. See https://github.com/jimcornmell/dotfiles#catmd