Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Tables support borders #604

Open
joshka opened this issue Nov 2, 2023 · 13 comments
Open

Make Tables support borders #604

joshka opened this issue Nov 2, 2023 · 13 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@joshka
Copy link
Member

joshka commented Nov 2, 2023

This issue is marked as a "Good First Issue". I'd ask anyone considering working on this to please first consider the open questions mentioned below, and to design the user facing API in this issue to validate it upfront before going forward with an implementation.

Problem

The current table implementation uses spaces to separate columns and does not have any way to separate the header. It would be nice to be able to add borders around cells. e.g. using the line drawing characters we might have something like:

┌─┬─┐
│A│B│
├─┼─┤
│1│2│
├─┼─┤
│3│4│
└─┴─┘

We should also be able easily configure something more like:

A│B
─┼─
1│2
3│4

And

A B
───
1 2
3 4

And

A│B
1│2
3│4

And possible even:

┌─┬─┐
│A│B│
╞═╪═╡ 
│1│2│
├─┼─┤
│3│4│
└─┴─┘

Solution

  1. We should be able to set the characters used (this is probably a symbols::line::Set, but may need to add a new table_borders::Set if we want to individually set header borders like the last example.
  2. We should be able to configure which borders are used (TOP, LEFT, RIGHT, BOTTOM, INNER VERTICAL, INNER HORIZONTAL, HEADER TOP, HEADER LEFT, perhaps footer?
  3. It's conceivable that we might want to handle the bottom row or right hand column differently - so we should design for that - I'm not sure what this will look like in code - let's design this before implementation.

Alternatives

Additional context

For some inspiration:

Rich (Python)
rich table

Bubble Tea (Go):
bubbletea table

@joshka joshka added the enhancement New feature or request label Nov 2, 2023
@orhun
Copy link
Sponsor Member

orhun commented Nov 4, 2023

Maybe mark this as good first issue or help wanted in case someone is interested?

@joshka joshka added the help wanted Extra attention is needed label Nov 4, 2023
@joshka joshka added the good first issue Good for newcomers label Nov 21, 2023
@polarathene
Copy link

polarathene commented Nov 22, 2023

I came across this crate recently, which might be of interest?: https://github.com/zhiburt/tabled/tree/master#style

img


Regarding the linked issue with text on collapsed border lines, tabled has similar functionality already: https://github.com/zhiburt/tabled/tree/master#column-names

┌header 0─┬header 1──┐
│ Hello   │ World    │
├─────────┼──────────┤
│ Bonjour │ le monde │
├─────────┼──────────┤
│ Hallo   │ Welt     │
└─────────┴──────────┘

https://github.com/zhiburt/tabled/tree/master#merge

+---+---+---+
| 0 | 1 | 2 |
+---+---+---+
| A | B     |
+   +---+---+
|   | W | E |
+---+---+---+
| Z         |
+---+---+---+

@joshka
Copy link
Member Author

joshka commented Nov 23, 2023

I came across this crate recently, which might be of interest?:

Wow. That crate is super deep and comprehensive. It makes me not want to consider adding all that same level of functionality as it's chasing a much better result. I wonder whether it would be possible to easily use that in one of the following approaches:

  1. As a configuration layer for Ratatui tables
  2. As a new widget implementation on top of it in a Table crate
  3. Perhaps just by converting the output to Ratatui text and rendering it raw
  4. By forking and abstracting then abstracting the style and color options in the original with the equivalent Ratatui types.
  5. Some other approach?

@im-stanly
Copy link

Hi @joshka , I'm interested in working on this issue, but could you elaborate a bit more on your thoughts regarding this API?

@joshka
Copy link
Member Author

joshka commented Feb 20, 2024

Hey, I don't have any concrete suggestions other than to try a few things and show what could work. When an API like this is ambiguous, it's often a useful approach to start with the user code in mind instead of jumping to any implementation (as that will lead to less rework). So given that, what do you think a Ratatui app that uses this would look like in the ideal case?

Use some of the examples from the tabled crate and write out just the functions that build up the model of the Table widget. It's not important to implement this until you have a good idea of what it looks like from the user's perspective...

@im-stanly
Copy link

Many thanks for your help. Can you please assign this issue to me?

@im-stanly
Copy link

Hi Joshka, I was trying to solve this issue as a project at uni, but I'm not able to do this. I will leave this issue and unassign myself

@im-stanly im-stanly removed their assignment Mar 6, 2024
@joshka
Copy link
Member Author

joshka commented Mar 6, 2024

Hi Joshka, I was trying to solve this issue as a project at uni, but I'm not able to do this. I will leave this issue and unassign myself

No problem :)

@opiredev
Copy link

opiredev commented Apr 28, 2024

@nabby27 created a $50.00 reward using Opire

How to earn this reward?

Since this project does not have Opire bot installed yet 😞 you need to go to Opire and claim the rewards through your programmer's dashboard once you have your PR ready 💪

@mobley-trent
Copy link

Hello @joshka is this issue still open ?

@joshka
Copy link
Member Author

joshka commented May 21, 2024

Hello @joshka is this issue still open ?

It is, but this is definitely something that needs some discussion about exactly how this might look. If you haven't worked with Ratatui much before, it's probably not the best task to pick up. Also, I mentioned in another PR that it might not be a bad idea to move the table out of Ratatui, and iterate fast in a breaking manner rather than slower keeping backwards compatibility. That's still something to consider.

I don't know anything about the bounty - it was added by an outside contributor, so you'll have to work that out with them if this is the driving factor on this.

@nabby27
Copy link

nabby27 commented May 21, 2024

Hi 👋 (for reference), I am Co-founder of Opire and I have created this reward because I like to collaborate on open-source projects, unfortunately, I don't have as much time as I would like (nor knowledge in all areas) but I really like this project and I wanted to help with this issue since I think it would be nice if ratatui had this functionality

@joshka
Copy link
Member Author

joshka commented May 21, 2024

Hi 👋 (for reference), I am Co-founder of Opire and I have created this reward because I like to collaborate on open-source projects, unfortunately, I don't have as much time as I would like (nor knowledge in all areas) but I really like this project and I wanted to help with this issue since I think it would be nice if ratatui had this functionality

Sounds good. :) Thanks for doing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

7 participants