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

feat(table): More granular table styles #246 #340

Closed
wants to merge 1 commit into from

Conversation

pja237
Copy link

@pja237 pja237 commented Feb 27, 2023

@jlec et al.
PR regarding #246

This was an idea of how one might extend the table styling without causing too much havoc in the table code and to maintain backwards compatibility.
I'm more then happy to receive feedback, ideas and pointers on how to make this better and eventually merged.

@jlec
Copy link

jlec commented Mar 2, 2023

This week is nuts. Hopefully, on the weekend, I will be able to tinker with your code

@jlec
Copy link

jlec commented Mar 5, 2023

Works for me. docs are missing.

@bashbunni
Copy link
Member

Part of me wonders if it would be more streamlined to extend the existing Styles struct to include an optional value for Row. It looks like there are already options for Selected and Cell in the Styles struct. The user would be able to set these styles to whatever lipgloss.Style definitions they'd like when they initialize the table.

The Row field could probably just initialize a new style (lipgloss.NewStyle()), so all fields could call lipgloss.Render without issue and users can add their own customizations without it breaking. Let me know your thoughts on that

Copy link
Member

@bashbunni bashbunni left a comment

Choose a reason for hiding this comment

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

Thank you so much for the PR! Looking forward to seeing the updates. It'll be great to be able to customize these tables further

renderedCell := m.styles.Cell.Render(style.Render(runewidth.Truncate(value, m.cols[i].Width, "…")))
overlayedStyle := cellStyles[i].Inherit(rowStyle)
overlayedStyle = overlayedStyle.Copy().Inherit(selStyle).Padding(0, 1)
//renderedCell := cellStyles[i].Inherit(rowStyle).Render(style.Render(runewidth.Truncate(value, m.cols[i].Width, "…")))
Copy link
Member

Choose a reason for hiding this comment

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

delete commented code

for i, value := range m.rows[rowID] {
style := lipgloss.NewStyle().Width(m.cols[i].Width).MaxWidth(m.cols[i].Width).Inline(true)
renderedCell := m.styles.Cell.Render(style.Render(runewidth.Truncate(value, m.cols[i].Width, "…")))
overlayedStyle := cellStyles[i].Inherit(rowStyle)
Copy link
Member

Choose a reason for hiding this comment

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

what does this overlayedStyle do?

if m.CustomRowStyle != nil {
rowStyle = m.CustomRowStyle.Style(rowID, m.rows[rowID])
} else {
// We don't have rowstyle separately, what now?
Copy link
Member

Choose a reason for hiding this comment

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

I think it is worth having a field in Styles for Row, this would make this chunk a lot simpler

selStyle = m.styles.Selected
}
} else {
selStyle = lipgloss.NewStyle()
Copy link
Member

Choose a reason for hiding this comment

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

what does this do?

@maaslalani
Copy link
Contributor

Hey @pja237, thanks so much for this contribution.

Our plan is to replace the table renderer with Lip Gloss tables which will allow fully customizable Cell and Row styles with the StyleFunc.

I am going to close this PR for now (doing some cleaning up) but feel free to re-open this or create new issues / PRs if needed!

@maaslalani maaslalani closed this Feb 28, 2024
@maaslalani
Copy link
Contributor

Here is the Lip Gloss table documentation for reference:

https://github.com/charmbracelet/lipgloss/tree/master?tab=readme-ov-file#rendering-tables

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.

4 participants