charmbracelet / charmbracelet/bubbles
table: set cell's background style override others
- Dominant language
- Go
- Stars
- 8.9k
- Forks
- 457
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 5
Description
**Describe the bug**
when set a background style to table's cell, it override to others, selected row, and ignore its foreground color and bold font which are default.
**Setup**
Please complete the following information along with version numbers, if applicable.
- OS: macOS
- Shell: zsh
- Terminal Emulator: alacritty, cursor(vscode) default
- Terminal Multiplexer: no
- Locale: en_US.UTF-8
**To Reproduce**
Steps to reproduce the behavior:
1. Run following codes(`go run ./test.go`)
**Source Code**
```go
# test.go
package main
import (
"fmt"
"github.com/charmbracelet/bubbles/table"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)
type model struct {
defaultTable table.Model
styledTable table.Model
}
func newModel() model {
rows := []table.Row{
{"Chocolate Digestives", "UK", "Yes"},
{"Tim Tams", "Australia", "No"},
{"Hobnobs", "UK", "Yes"},
}
columns := []table.Column{
{Title: "Name", Width: 25},
{Title: "Country of Origin", Width: 16},
{Title: "Dunk-able", Width: 12},
}
defaultTable := table.New(table.WithRows(rows), table.WithColumns(columns))
styledTable := table.New(table.WithRows(rows), table.WithColumns(columns))
styledTable.SetStyles(table.Styles{
Header: table.DefaultStyles().Header,
Selected: table.DefaultStyles().Selected,
Cell: table.DefaultStyles().Cell.Background(lipgloss.Color("220")),
})
return model{defaultTable, styledTable}
}
func (m model) Init() tea.Cmd {
return nil
}
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
if msg.String() == "q" {
return m, tea.Quit
}
}
return m, nil
}
func (m model) View() string {
return lipgloss.JoinHorizontal(
lipgloss.Top,
m.defaultTable.View(),
m.styledTable.View(),
)
}
func main() {
p := tea.NewProgram(newModel())
if _, err := p.Run(); err != nil {
fmt.Println("Error running program:", err)
}
}
```
**Expected behavior**
cell's background do not override other styles
**Screenshots**
(right side is `Background(lipgloss.Color("220"))` added to default cell style)
**Additional context**
Contributor guide
Assessment
This issue has not been assessed yet.