vdmeer / asciitable

Several implementations of a text table, originally using ASCII and UTF-8 characters for borders.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

I did not find a suitable theme

i-panov opened this issue · comments

The library is very cool, but still I could not find a suitable theme for the table. And it must have been just to have all the boundaries except the top and bottom. Tried to combine through GridOptions, but it did not work out yet. Do not tell me how it can be done?

| cell | cell |
|-------------|
| cell | cell |
|-------------|
| cell | cell |

Yes, there is no theme defined for your purpose. But you can easily define your own theme realizing what you need (though: I didn't write documentation on that yet, sorry!). The code attached should solve your problem.

AsciiTable at = new AsciiTable();
at.addRule();
at.addRow("cell", "cell");
at.addRule();
at.addRow("cell", "cell");
at.addRule();
at.addRow("cell", "cell");
at.addRule();
int gridTheme = 
	HAS_MID_CONNECTOR | HAS_MID_BORDER_LEFT | HAS_MID_BORDER_RIGHT | HAS_MID_LINE |
	HAS_CONTENT_LEFT | HAS_CONTENT_MID | HAS_CONTENT_RIGHT;
at.getContext().setGridTheme(gridTheme);
System.out.println(at.render());

The code simply creates a table with rows and rules. Then defines a grid theme using the full theme and removing top/bottom line related parts. Set the new grid theme on the table context, then render and print.

Does that help?
/sven

Just forgot: test code in https://github.com/vdmeer/asciitable/blob/dev/src/test/java/de/vandermeer/asciitable/issues/Test_Issues12.java (dev branch).

Expected output

│cell                                   │cell                                  │
├───────────────────────────────────────┼──────────────────────────────────────┤
│cell                                   │cell                                  │
├───────────────────────────────────────┼──────────────────────────────────────┤
│cell                                   │cell                                  │

Thank you, this is what I need.