-
Notifications
You must be signed in to change notification settings - Fork 278
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! |
* feat: bracketed paste This introduces support for input via bracketed paste, where escape characters in the pasted input are not interpreted. Pasted input are marked as a special field in the KeyMsg. This is useful because pasted input may need sanitation in individual widgets. * fix(key): support bracketed paste with short reads Some terminal emulators feed the bracketed paste data in multiple chunks, which may not be aligned on a 256 byte boundary. So it's possible for `input.Read` to return less than 256 bytes read but while there's still more data to be read to complete a bracketed paste input. --------- Co-authored-by: Christian Muehlhaeuser <[email protected]>
Add optional
RenderCell
function. If it is not specified thenStyles.Cell.Render
is used. The changes are not breaking.In action:
![image](https://private-user-images.githubusercontent.com/19246753/255407774-f9a461be-9e02-4ef2-82a4-8f745a7c3d83.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkzOTIxMDYsIm5iZiI6MTczOTM5MTgwNiwicGF0aCI6Ii8xOTI0Njc1My8yNTU0MDc3NzQtZjlhNDYxYmUtOWUwMi00ZWYyLTgyYTQtOGY3NDVhN2MzZDgzLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEyVDIwMjMyNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTE0Yzk0MWRmZDYxNDMwOGVmNmMzYTJjNDM5NGUyZjRjOTI4YjVkZmY0ZDhkOThmOTRiODNlZjE1NjZhOTg4OGMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.9twk_5UlZG5a4wGDbMBKzCtTmCgujUSYBcSTK5CLYrw)
Relates: #246