go-pretty icon indicating copy to clipboard operation
go-pretty copied to clipboard

Custom top and bottom table style

Open manoelmozzer opened this issue 1 year ago • 5 comments

First, thanks for the great library. It is excellent.

It would be nice to be able to customize the first and last rows of the table different from the middle ones.

From what I've seen, MiddleHorizontal (t.Style().Box.MiddleHorizontal) controls the style of all horizontal lines. However, it would be nice to have independent Top and Bottom options.

These options could generate the following tables, which I didn't get in the current settings:

   #   FIRST NAME   LAST NAME   SALARY                                  <- no top line
----- ------------ ----------- -------- -----------------------------
   1   Arya         Stark         3000                               
  20   Jon          Snow          2000   You know nothing, Jon Snow! 
 300   Tyrion       Lannister     5000                               
----- ------------ ----------- -------- -----------------------------
                    TOTAL        10000                               
----- ------------ ----------- -------- ----------------------------- <- with bottom line
=====+============+===========+========+============================= <- diferrent styles
   # | FIRST NAME | LAST NAME | SALARY |                             
-----+------------+-----------+--------+----------------------------- <- diferrent styles
   1 | Arya       | Stark     |   3000 |                             
  20 | Jon        | Snow      |   2000 | You know nothing, Jon Snow! 
 300 | Tyrion     | Lannister |   5000 |                             
-----+------------+-----------+--------+-----------------------------
     |            | TOTAL     |  10000 |                             
=====+============+===========+========+=============================
^^^^^+^^^^^^^^^^^^+^^^^^^^^^^^+^^^^^^^^+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ <- diferrent styles
   # | FIRST NAME | LAST NAME | SALARY |                             
-----+------------+-----------+--------+----------------------------- <- diferrent styles
   1 | Arya       | Stark     |   3000 |                             
  20 | Jon        | Snow      |   2000 | You know nothing, Jon Snow! 
 300 | Tyrion     | Lannister |   5000 |                             
-----+------------+-----------+--------+-----------------------------
     |            | TOTAL     |  10000 |                             
~~~~~+~~~~~~~~~~~~+~~~~~~~~~~~+~~~~~~~~+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <- diferrent styles

With this feature, custom styles would become more generic.

manoelmozzer avatar Aug 05 '22 02:08 manoelmozzer

This is possible to do. Will try to get this implemented.

jedib0t avatar Aug 05 '22 23:08 jedib0t

The implementation is complex simply because this introduces a LOT of edge cases (literally). Just thought I'd let you know to not expect this soon. Will update this thread when I make some progress.

jedib0t avatar Aug 06 '22 00:08 jedib0t

Hey @manoelmozzer ... I honestly tried to make this customization work, but the more I worked on it, the more it felt like a lot of code quality/simplicity/maintainability had to be sacrificed to make this work.

I have code that can stylize Title/Header/Rows/Footers all separately in their own individual styles. But this change required a bunch of backward-incompatible changes and a major version bump along with making the code really hard to read/reason/maintain.

I'll leave this issue open, and if a lot more folks ask for this feature, I'll see what I can do. But for now, I'm gonna stop working on this. Sorry! 😞

jedib0t avatar Nov 06 '22 23:11 jedib0t

No problem, thanks for your try. Anyway, your library is great. xD

manoelmozzer avatar Jan 17 '23 01:01 manoelmozzer

RST grid table can be rendered if this feature is implemented.

stingshen avatar Apr 21 '23 11:04 stingshen