From 3b3c566073d38f6770b7bbb8859ccda56eacdcf6 Mon Sep 17 00:00:00 2001 From: bashbunni Date: Tue, 24 Sep 2024 17:28:49 -0700 Subject: [PATCH 1/4] refactor(table): update example to work with new table bubble --- examples/table/main.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/examples/table/main.go b/examples/table/main.go index 76736f37de..e7434ab1d0 100644 --- a/examples/table/main.go +++ b/examples/table/main.go @@ -43,16 +43,11 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } func (m model) View() string { - return baseStyle.Render(m.table.View()) + "\n" + return m.table.View() } 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{ {"1", "Tokyo", "Japan", "37,274,000"}, @@ -158,11 +153,11 @@ func main() { } t := table.New( - table.WithColumns(columns), - table.WithRows(rows), table.WithFocused(true), - table.WithHeight(7), ) + t.SetRows(rows) + t.SetHeaders(headers...) + t.SetHeight(50) s := table.DefaultStyles() s.Header = s.Header. From 23cbe3972c34dcd14c10a458371fe2967b8c13df Mon Sep 17 00:00:00 2001 From: bashbunni Date: Tue, 24 Sep 2024 17:34:54 -0700 Subject: [PATCH 2/4] chore(deps): use use-lipgloss-table branch for lipgloss + bubbles for validation --- examples/go.mod | 8 ++++---- examples/go.sum | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/go.mod b/examples/go.mod index cde0c65c7b..66a233aa6a 100644 --- a/examples/go.mod +++ b/examples/go.mod @@ -5,11 +5,11 @@ go 1.21 toolchain go1.22.5 require ( - github.com/charmbracelet/bubbles v0.19.0 - github.com/charmbracelet/bubbletea v0.27.0 + github.com/charmbracelet/bubbles v0.20.1-0.20240925002526-f1f0c4cb16a3 + github.com/charmbracelet/bubbletea v1.1.0 github.com/charmbracelet/glamour v0.8.0 github.com/charmbracelet/harmonica v0.2.0 - github.com/charmbracelet/lipgloss v0.13.0 + github.com/charmbracelet/lipgloss v0.13.1-0.20240924011622-17b470d8991e github.com/charmbracelet/x/exp/teatest v0.0.0-20240521184646-23081fb03b28 github.com/fogleman/ease v0.0.0-20170301025033-8da417bf1776 github.com/lucasb-eyer/go-colorful v1.2.0 @@ -22,7 +22,7 @@ require ( github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/aymanbagabas/go-udiff v0.2.0 // indirect github.com/aymerick/douceur v0.2.0 // indirect - github.com/charmbracelet/x/ansi v0.2.3 // indirect + github.com/charmbracelet/x/ansi v0.3.2 // indirect github.com/charmbracelet/x/exp/golden v0.0.0-20240815200342-61de596daa2b // indirect github.com/charmbracelet/x/term v0.2.0 // indirect github.com/dlclark/regexp2 v1.11.0 // indirect diff --git a/examples/go.sum b/examples/go.sum index b3d7fa67d2..799559dea2 100644 --- a/examples/go.sum +++ b/examples/go.sum @@ -14,16 +14,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 v0.19.0 h1:gKZkKXPP6GlDk6EcfujDK19PCQqRjaJZQ7QRERx1UF0= -github.com/charmbracelet/bubbles v0.19.0/go.mod h1:WILteEqZ+krG5c3ntGEMeG99nCupcuIk7V0/zOP0tOA= +github.com/charmbracelet/bubbles v0.20.1-0.20240925002526-f1f0c4cb16a3 h1:wM9AkHxMC2L8AJO1A6mfy1nMpmLUHhQRagKdApXtsDk= +github.com/charmbracelet/bubbles v0.20.1-0.20240925002526-f1f0c4cb16a3/go.mod h1:AMUMeIdzUOkHygI2fJ4JN7f6LOjzlgNbQfcUlBM+CGc= github.com/charmbracelet/glamour v0.8.0 h1:tPrjL3aRcQbn++7t18wOpgLyl8wrOHUEDS7IZ68QtZs= github.com/charmbracelet/glamour v0.8.0/go.mod h1:ViRgmKkf3u5S7uakt2czJ272WSg2ZenlYEZXT2x7Bjw= 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 v0.13.0 h1:4X3PPeoWEDCMvzDvGmTajSyYPcZM4+y8sCA/SsA3cjw= -github.com/charmbracelet/lipgloss v0.13.0/go.mod h1:nw4zy0SBX/F/eAO1cWdcvy6qnkDUxr8Lw7dvFrAIbbY= -github.com/charmbracelet/x/ansi v0.2.3 h1:VfFN0NUpcjBRd4DnKfRaIRo53KRgey/nhOoEqosGDEY= -github.com/charmbracelet/x/ansi v0.2.3/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw= +github.com/charmbracelet/lipgloss v0.13.1-0.20240924011622-17b470d8991e h1:sc5K4dGwO7gpZsNNigIaDOgpMoe2JLuHXekLGD9EdwA= +github.com/charmbracelet/lipgloss v0.13.1-0.20240924011622-17b470d8991e/go.mod h1:zaYVJ2xKSKEnTEEbX6uAHabh2d975RJ+0yfkFpRBz5U= +github.com/charmbracelet/x/ansi v0.3.2 h1:wsEwgAN+C9U06l9dCVMX0/L3x7ptvY1qmjMwyfE6USY= +github.com/charmbracelet/x/ansi v0.3.2/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw= github.com/charmbracelet/x/exp/golden v0.0.0-20240815200342-61de596daa2b h1:MnAMdlwSltxJyULnrYbkZpp4k58Co7Tah3ciKhSNo0Q= github.com/charmbracelet/x/exp/golden v0.0.0-20240815200342-61de596daa2b/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U= github.com/charmbracelet/x/exp/teatest v0.0.0-20240521184646-23081fb03b28 h1:sOWKNRjt8uOEVgPiJVIJCse1+mUDM2F/vYY6W0Go640= From 690a0e685721b28800369d2c32346b7798eb8dfe Mon Sep 17 00:00:00 2001 From: bashbunni Date: Wed, 16 Oct 2024 20:56:44 -0700 Subject: [PATCH 3/4] feat(example): set table height based on window height --- examples/table/main.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/table/main.go b/examples/table/main.go index e7434ab1d0..24fcf1b149 100644 --- a/examples/table/main.go +++ b/examples/table/main.go @@ -22,6 +22,8 @@ func (m model) Init() tea.Cmd { return nil } func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var cmd tea.Cmd switch msg := msg.(type) { + case tea.WindowSizeMsg: + m.table.SetHeight(msg.Height - 1) case tea.KeyMsg: switch msg.String() { case "esc": From 2e53b6b7a159d9f650d0a481a32e133af5aa48b1 Mon Sep 17 00:00:00 2001 From: bashbunni Date: Thu, 17 Oct 2024 09:29:43 -0700 Subject: [PATCH 4/4] refactor(example): remove magic number --- examples/table/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/table/main.go b/examples/table/main.go index 24fcf1b149..413ac26f46 100644 --- a/examples/table/main.go +++ b/examples/table/main.go @@ -23,7 +23,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var cmd tea.Cmd switch msg := msg.(type) { case tea.WindowSizeMsg: - m.table.SetHeight(msg.Height - 1) + m.table.SetHeight(msg.Height) case tea.KeyMsg: switch msg.String() { case "esc":