-
Notifications
You must be signed in to change notification settings - Fork 263
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: support custom styles for cells #397
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Since it's a change to the API, I'll discuss with the team to confirm naming is all good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I'm not sure this is behaving as expected. Just tested with our table example in Bubble Tea and found it broke existing rendering. Other rows kept the Selected
styles just fine. Let me know your thoughts :)
Here's what I added to highlight Tokyo:
s.RenderCell = func(value string, rowID, columnID int) string {
if strings.Contains(value, "Tokyo") {
return lipgloss.NewStyle().Foreground(lipgloss.Color("42")).Render(value)
}
return value
}
Hi @bashbunni , thanks for the review! The issue is due to Control Sequence Introducer with Reset So currently, the following code breaks colors: row.Render(
lipgloss.JoinHorizontal(
cell1.Render(), // It clears styles...
cell2.Render(),
cell3.Render(),
),
) So that is why I added Example: s.RenderCell = func(model table.Model, value string, position table.Position) string {
if position.RowID == model.Cursor() {
return s.Cell.Copy().
Foreground(lipgloss.Color("229")).
Background(lipgloss.Color("57")).
Render(value)
}
return s.Cell.Copy().Foreground(lipgloss.Color("21")).Render(value)
} Reference:
What do you think? |
I prepared the full example: |
@bashbunni Hi, could you please check the review changes? |
@bashbunni @maaslalani Hi, Is there any chance this to be merged? Thank you! Example of usage: |
Are there any updates on this PR. I could really use the ability to apply specific cell styles in my project |
Hey! I really like this idea. The long term plan is to switch over to using Lip Gloss tables which should cover this use case: Lip Gloss tables have a |
Thank you again for this contribution, I'm cleaning up some old PRs so I will close this for now but this feature will definitely be introduced once we switch over to the new Lip Gloss tables! |
Add optional
RenderCell
function. If it is not specified thenStyles.Cell.Render
is used. The changes are not breaking.In action:
Relates: #246