Skip to content

feat(table): v2 table bubble #772

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

Open
wants to merge 12 commits into
base: v2-exp
Choose a base branch
from
Open

feat(table): v2 table bubble #772

wants to merge 12 commits into from

Conversation

bashbunni
Copy link
Member

@bashbunni bashbunni commented Apr 4, 2025

uses Lip Gloss table to render the table. Also allows users to create bubbles tables from existing Lip Gloss tables.

Depends on charmbracelet/lipgloss#512

Runnable example: charmbracelet/bubbletea#1380

image


github.com/charmbracelet/bubbles/table

incompatible changes

removed: FromValues -> seems unnecessary

Allow chaining setters

New -> changed from func(...Option) Model to func(...Option) *Model
(*Model).SetCursor: changed from func(int) to func(int) *Model
(*Model).SetHeight: changed from func(int) to func(int) *Model
(*Model).SetRows: changed from func([]Row) to func(...[]string) *Model
(*Model).SetStyles: changed from func(Styles) to func(Styles) *Model
(*Model).SetWidth: changed from func(int) to func(int) *Model

Height and Width calculations now delegated to Lip Gloss

removed: Model.Width
removed: Model.Height

Removed wrapper types Column and Row

Row

removed: Row -> using [][]string instead
refactor: WithRows -> changed from func([]Row) Option to func(...[]string) Option
refactor: Model.Rows -> changed from func() []Row to func() [][]string
refactor: Model.SelectedRow -> changed from func() Row to func() []string

Columns, now headers

refactor: WithColumns() -> WithHeaders()
refactor: Model.Columns -> Model.Headers
refactor: (*Model).SetColumns -> (*Model).SetHeaders
removed: Column

Removed viewport

removed: (*Model).UpdateViewport

compatible changes

Support Lip Gloss Border customizations

(*Model).Border: added
(*Model).BorderBottom: added
(*Model).BorderColumn: added
(*Model).BorderHeader: added
(*Model).BorderLeft: added
(*Model).BorderRight: added
(*Model).BorderRow: added
(*Model).BorderStyle: added
(*Model).BorderTop: added
(*Model).SetBorder: added

Manage styles

(*Model).OverwriteStyles: added
(*Model).OverwriteStylesFromLipgloss: added
(*Model).SetStyleFunc: added
(*Model).SetYOffset: added
NewFromTemplate: added
WithStyleFunc: added

@bashbunni bashbunni requested a review from aymanbagabas as a code owner April 4, 2025 05:30
Comment on lines +132 to +135
// We can't get the rows and headers from the table, so the user needs to
// provide them as arguments.
m.rows = rows
m.headers = headers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: I wrote a helper function on lipgloss to convert the internal Data into a [][]string:

https://github.com/charmbracelet/lipgloss/blob/c6b946e574dddb956f8642c9f84fa0219b777ed3/table/rows.go#L116

To avoid having to ask for the data again here, I think we should have a GetHeaders() and GetData() functions on lipgloss.

There is a small decision to make here. I'm not sure if GetData() should return a [][]string directly. For me, it makes more sense to make it return the internal table.Data interface and expose dataToMatrix as a public function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I think it makes more sense to only store the data once instead of managing the same set of values in two places (Model and lipgloss Table).

I vote that we add GetData() that returns a Data then the user can call DataToMatrix. Performance-wise it would be the same as we would probably be doing that type conversion under the hood if we were returning [][]string. This might lead users to want to include non-string values in the table... Is that something we want to support? I guess that feature could sit in the backlog for a bit while we think about it.


// OverwriteStylesFromLipgloss sets the [Model]'s style attributes from an
// existing [lipgloss.Table].
func (m *Model) OverwriteStylesFromLipgloss(t *table.Table) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we could improve the name of this function...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could probably make it StyleFromLipgloss ?

@andreynering
Copy link
Member

It seems to be working well in my tests 👏

Let me know if you have specific scenarios that you want help testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants