diff --git a/examples/_1248/main.go b/examples/_1248/main.go index f51c924969..9cee8e576f 100644 --- a/examples/_1248/main.go +++ b/examples/_1248/main.go @@ -6,26 +6,16 @@ import ( "github.com/charmbracelet/lipgloss/v2" ) -var baseStyle = lipgloss.NewStyle(). - BorderStyle(lipgloss.NormalBorder()). - BorderForeground(lipgloss.Color("240")) - func NewTable() table.Model { - rows := []table.Row{ + rows := [][]string{ {"1", "issue", "v1.2.3", "24/11/22", "EnterAltScreen"}, } - columns := []table.Column{ - {Title: "ID", Width: 4}, - {Title: "NAME", Width: 28}, - {Title: "VERSION", Width: 18}, - {Title: "DATE", Width: 15}, - {Title: "REMARK", Width: 4}, - } + headers := []string{"ID", "NAME", "VERSION", "DATE", "REMARK"} t := table.New( - table.WithColumns(columns), - table.WithRows(rows), + table.WithHeaders(headers...), + table.WithRows(rows...), table.WithFocused(true), - table.WithHeight(7), + table.WithHeight(10), ) s := table.DefaultStyles() s.Header = s.Header. @@ -33,12 +23,8 @@ func NewTable() table.Model { BorderForeground(lipgloss.Color("240")). BorderBottom(true). Bold(false) - s.Selected = s.Selected. - Foreground(lipgloss.Color("229")). - Background(lipgloss.Color("57")). - Bold(false) t.SetStyles(s) - return t + return *t } type Model struct { @@ -79,7 +65,11 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } func (m Model) View() string { - return baseStyle.Render(m.currentModel.View()) + "\n" + m.currentModel.HelpView() + "\n" + return lipgloss.JoinVertical( + lipgloss.Left, + m.currentModel.View(), + m.currentModel.HelpView(), + ) } func NewModel() (model Model, err error) { diff --git a/examples/go.mod b/examples/go.mod index 1de4807747..582b1d0d6b 100644 --- a/examples/go.mod +++ b/examples/go.mod @@ -5,12 +5,12 @@ go 1.23.1 replace github.com/charmbracelet/bubbletea/v2 => ../ require ( - github.com/charmbracelet/bubbles/v2 v2.0.0-beta.1.0.20250526131538-b3f0c9e42318 + github.com/charmbracelet/bubbles/v2 v2.0.0-beta.1.0.20250603141547-8b46d0b4e219 github.com/charmbracelet/bubbletea/v2 v2.0.0-beta.1.0.20250420102230-7ecd51915026 github.com/charmbracelet/colorprofile v0.3.1 github.com/charmbracelet/glamour/v2 v2.0.0-20250513163904-eeeced3bb3c6 github.com/charmbracelet/harmonica v0.2.0 - github.com/charmbracelet/lipgloss/v2 v2.0.0-beta.1.0.20250513162854-28902d027c40 + github.com/charmbracelet/lipgloss/v2 v2.0.0-beta.1.0.20250603140710-946081c6f1a5 github.com/charmbracelet/x/ansi v0.9.3-0.20250602153603-fb931ed90413 github.com/charmbracelet/x/exp/charmtone v0.0.0-20250514204301-7f4ee4d0d5fe github.com/charmbracelet/x/exp/teatest/v2 v2.0.0-20250324105510-c72bdbf70572 diff --git a/examples/go.sum b/examples/go.sum index 146efa5580..36a430b320 100644 --- a/examples/go.sum +++ b/examples/go.sum @@ -12,18 +12,16 @@ github.com/aymanbagabas/go-udiff v0.2.0 h1:TK0fH4MteXUDspT88n8CKzvK0X9O2xu9yQjWp github.com/aymanbagabas/go-udiff v0.2.0/go.mod h1:RE4Ex0qsGkTAJoQdQQCA0uG+nAzJO/pI/QwceO5fgrA= github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk= github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4= -github.com/charmbracelet/bubbles/v2 v2.0.0-beta.1.0.20250526131538-b3f0c9e42318 h1:f8Q0ybZGxT+St1JfPM7yoz/XFpbmtodcIehaom/9XT8= -github.com/charmbracelet/bubbles/v2 v2.0.0-beta.1.0.20250526131538-b3f0c9e42318/go.mod h1:6HamsBKWqEC/FVHuQMHgQL+knPyvHH55HwJDHl/adMw= +github.com/charmbracelet/bubbles/v2 v2.0.0-beta.1.0.20250603141547-8b46d0b4e219 h1:5lzG1M/SNTItaKYbzfrS57/JR4YcHu3ZviUYd4Nj/jI= +github.com/charmbracelet/bubbles/v2 v2.0.0-beta.1.0.20250603141547-8b46d0b4e219/go.mod h1:yeCn/feXmWXU7QmJPVI9JpPdQGmv2xadb3qjXmbZqWI= github.com/charmbracelet/colorprofile v0.3.1 h1:k8dTHMd7fgw4bnFd7jXTLZrSU/CQrKnL3m+AxCzDz40= github.com/charmbracelet/colorprofile v0.3.1/go.mod h1:/GkGusxNs8VB/RSOh3fu0TJmQ4ICMMPApIIVn0KszZ0= github.com/charmbracelet/glamour/v2 v2.0.0-20250513163904-eeeced3bb3c6 h1:AKhOV8dSRU3KpqMgpGME9JU7ouumB2S6hMmD6PRJeTc= github.com/charmbracelet/glamour/v2 v2.0.0-20250513163904-eeeced3bb3c6/go.mod h1:7xBAUTCSADx9mHG0uBf4NDoVpYxMzIQ2j/NMLGdFsFM= github.com/charmbracelet/harmonica v0.2.0 h1:8NxJWRWg/bzKqqEaaeFNipOu77YR5t8aSwG4pgaUBiQ= github.com/charmbracelet/harmonica v0.2.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao= -github.com/charmbracelet/lipgloss/v2 v2.0.0-beta.1.0.20250513162854-28902d027c40 h1:SxOUomYAVo5zh+6WCH1bGshlAnSKP0ZeovI0FHAl9kg= -github.com/charmbracelet/lipgloss/v2 v2.0.0-beta.1.0.20250513162854-28902d027c40/go.mod h1:tRlx/Hu0lo/j9viunCN2H+Ze6JrmdjQlXUQvvArgaOc= -github.com/charmbracelet/x/ansi v0.9.3-0.20250516160309-24eee56f89fa h1:JU05TLAB6nOEL46bxHDV/+e8umBX32ODsGbVkc7o7bk= -github.com/charmbracelet/x/ansi v0.9.3-0.20250516160309-24eee56f89fa/go.mod h1:3RQDQ6lDnROptfpWuUVIUG64bD2g2BgntdxH0Ya5TeE= +github.com/charmbracelet/lipgloss/v2 v2.0.0-beta.1.0.20250603140710-946081c6f1a5 h1:vq3WdrGHQ6T0ZBYdRhn2toyQXDD+uneu3IdcMni7J5g= +github.com/charmbracelet/lipgloss/v2 v2.0.0-beta.1.0.20250603140710-946081c6f1a5/go.mod h1:EJWvaCrhOhNGVZMvcjc0yVryl4qqpMs8tz0r9WyEkdQ= github.com/charmbracelet/x/ansi v0.9.3-0.20250602153603-fb931ed90413 h1:L07QkDqRF274IZ2UJ/mCTL8DR95efU9BNWLYCDXEjvQ= github.com/charmbracelet/x/ansi v0.9.3-0.20250602153603-fb931ed90413/go.mod h1:3RQDQ6lDnROptfpWuUVIUG64bD2g2BgntdxH0Ya5TeE= github.com/charmbracelet/x/cellbuf v0.0.14-0.20250516160309-24eee56f89fa h1:lphz0Z3rsiOtMYiz8axkT24i9yFiueDhJbzyNUADmME= diff --git a/examples/table/main.go b/examples/table/main.go index 17c90ea5ee..a445788004 100644 --- a/examples/table/main.go +++ b/examples/table/main.go @@ -9,10 +9,6 @@ import ( "github.com/charmbracelet/lipgloss/v2" ) -var baseStyle = lipgloss.NewStyle(). - BorderStyle(lipgloss.NormalBorder()). - BorderForeground(lipgloss.Color("240")) - type model struct { table table.Model } @@ -43,18 +39,17 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } func (m model) View() string { - return baseStyle.Render(m.table.View()) + "\n " + m.table.HelpView() + "\n" + return lipgloss.JoinVertical( + lipgloss.Left, + m.table.View(), + m.table.HelpView(), + ) } func main() { - columns := []table.Column{ - {Title: "Rank", Width: 4}, - {Title: "City", Width: 10}, - {Title: "Country", Width: 10}, - {Title: "Population", Width: 10}, - } + headers := []string{"Rank", "City", "Country", "Population"} - rows := []table.Row{ + rows := [][]string{ {"1", "Tokyo", "Japan", "37,274,000"}, {"2", "Delhi", "India", "32,065,760"}, {"3", "Shanghai", "China", "28,516,904"}, @@ -158,12 +153,19 @@ func main() { } t := table.New( - table.WithColumns(columns), - table.WithRows(rows), + table.WithHeaders(headers...), + table.WithRows(rows...), table.WithFocused(true), - table.WithHeight(7), + table.WithHeight(20), ) + // This is another way to initialize the same table. + // t := table.New(). + // SetHeaders(headers...). + // SetRows(rows...). + // SetFocused(true). + // SetHeight(20) + s := table.DefaultStyles() s.Header = s.Header. BorderStyle(lipgloss.NormalBorder()). @@ -174,9 +176,10 @@ func main() { Foreground(lipgloss.Color("229")). Background(lipgloss.Color("57")). Bold(false) + t.SetStyles(s) - m := model{t} + m := model{*t} if _, err := tea.NewProgram(m).Run(); err != nil { fmt.Println("Error running program:", err) os.Exit(1)