tablewriter
tablewriter copied to clipboard
Request: Add optional title to top of table spanning all columns
Thank you for the tablewriter library. It's been such a handy resource for a text-based interface project.
Would it be possible to add an optional title banner across the top of a table spanning all columns similar to the optional footer?
I'm happy to submit a pull request with the change. I'd need a little guidance on this as thus far I've gotten a little lost in the code in trying to understand how it could be added.
Could you please paint or draw a picture you expected?
@mattn Sure thing…
+----------------------+
| TITLE |
+------+--------+------+
| HEAD | HEAD | HEAD |
+------+--------+------+
| Vals | Values | Vals |
| Vals | Values | Vals |
| Vals | Values | Vals |
| Vals | Values | Vals |
| Vals | Values | Vals |
| Vals | Values | Vals |
| Vals | Values | Vals |
+------+---------------+
Footer text
To my knowledge there's no means to add a title spanning the table with the current feature set. It's unclear to me how to manipulate the inner data structures to add a new row of a single cell that spans all columns and aligns text within it properly.
I also wanted to add a prominent string to my tables. Turns out it's not too hard to add a title in post if you render the table to a strings.Builder
. I tried three different styles and ended up liking a rather simple centered-title rendering.
/p/v/f/k/z/T/tmp.T5i1kAZa $ go run floating.go
*** Some of your data ***
+--------------------------------------+-------------------+---------+
| ID | NAME | STATUS |
+--------------------------------------+-------------------+---------+
| 2bb86ea2-4657-4de5-8ccd-a68cab57faf4 | qwerty | Pending |
| 39b17f4f-48be-42b6-b2bb-e156fd21cd48 | asdf | Done |
| cb08cba8-e624-443b-80da-c9340bd4f8f6 | zxcvzxcvzxcv | Done |
| cc712740-fc70-46cc-bbd9-1168b77a33b5 | 111! 222!! 333!!! | Done |
+--------------------------------------+-------------------+---------+
/p/v/f/k/z/T/tmp.T5i1kAZa $ go run enclosed.go
+--------------------------------------------------------------------+
| Some of your data |
+--------------------------------------+-------------------+---------+
| ID | NAME | STATUS |
+--------------------------------------+-------------------+---------+
| 43f7effc-a200-4323-bec6-27f1baf5883d | qwerty | Pending |
| b3f35bb0-2f87-47ea-9262-845c3222c0d5 | asdf | Done |
| 8e66b0d9-1a4c-4d7d-bcb1-a383d7cd51f6 | zxcvzxcvzxcv | Done |
| abdc8e35-a905-46eb-879c-9182a3ffd9e5 | 111! 222!! 333!!! | Done |
+--------------------------------------+-------------------+---------+
/p/v/f/k/z/T/tmp.T5i1kAZa $ go run enclosed.go --no-head-divider
+--------------------------------------------------------------------+
| Some of your data |
| |
| ID | NAME | STATUS |
+--------------------------------------+-------------------+---------+
| 6ac147a0-24f8-4a82-93b1-20e1289d5b34 | qwerty | Pending |
| e3744ec1-82df-404e-8a90-5fab39e874a4 | asdf | Done |
| 83bced5f-cf8a-4d45-a494-0add68fbd163 | zxcvzxcvzxcv | Done |
| 5cb8044a-fe84-4d76-976d-d3a7f8cac0f0 | 111! 222!! 333!!! | Done |
+--------------------------------------+-------------------+---------+
Source for these examples: https://gist.github.com/danopia/4b62f8190458ab1f63b85b6ccc0162fd