prettytable-rs icon indicating copy to clipboard operation
prettytable-rs copied to clipboard

Could we get some form of Format Macro?

Open EmeraldPandaTurtle opened this issue 2 years ago • 1 comments

It would be pretty cool to see a way to make a format with a macro!

Something Like

let format = table_format!(
// This could be the title format
// C would signify that the cell goes here
Title->{
   +===+===+
   | C | C |
   +===+===+
},
// The Other Formats
Row-> {
   +---+---+
   | C   C |
   +---+---+
}
);

// Then to make a table out of it
let mut table = table!(format, 
["Hello World!", "This is a cool format tool"]
);

table.set_titles(row!["Cool Title", "Part 2"]);

table.print_tty(true);

Which would result in

+==============+============================+
| Cool Title   | Part 2                     |
+==============+============================+
| Hello World! | This is a cool format tool |
+--------------+----------------------------+

I'm not remotely familiar with how macro writing would work, but would this be possible, I'm happy to work through it, if interested.

EmeraldPandaTurtle avatar Jun 10 '23 02:06 EmeraldPandaTurtle

Just a drive-by comment, but this seems like a thing that could be done in a separate crate relatively easily.

autarch avatar Jan 28 '24 07:01 autarch