From ca3e9e9cafdf6843a2e64353d25c810784ec224e Mon Sep 17 00:00:00 2001 From: Dolev Hadar Date: Sat, 12 Oct 2024 20:43:25 +0300 Subject: [PATCH 1/3] chore(examples): tree fix: comments --- examples/go.mod | 6 +- examples/go.sum | 12 +-- examples/tree-default/main.go | 62 +++++++++++++ examples/tree-file-system/main.go | 142 ++++++++++++++++++++++++++++++ examples/tree-long/main.go | 63 +++++++++++++ examples/tree-toc/main.go | 120 +++++++++++++++++++++++++ 6 files changed, 396 insertions(+), 9 deletions(-) create mode 100644 examples/tree-default/main.go create mode 100644 examples/tree-file-system/main.go create mode 100644 examples/tree-long/main.go create mode 100644 examples/tree-toc/main.go diff --git a/examples/go.mod b/examples/go.mod index 3a3453276e..2621b3aecd 100644 --- a/examples/go.mod +++ b/examples/go.mod @@ -33,7 +33,7 @@ require ( github.com/dlclark/regexp2 v1.11.0 // indirect github.com/dustin/go-humanize v1.0.1 // indirect github.com/gorilla/css v1.0.1 // indirect - github.com/mattn/go-runewidth v0.0.21 // indirect + github.com/mattn/go-runewidth v0.0.20 // indirect github.com/microcosm-cc/bluemonday v1.0.27 // indirect github.com/muesli/cancelreader v0.2.2 // indirect github.com/rivo/uniseg v0.4.7 // indirect @@ -46,3 +46,7 @@ require ( golang.org/x/sys v0.42.0 // indirect golang.org/x/text v0.24.0 // indirect ) + +replace charm.land/lipgloss/v2 v2.0.2 => ../../lipgloss + +replace charm.land/bubbles/v2 v2.1.0 => ../../bubbles diff --git a/examples/go.sum b/examples/go.sum index ea4939e6b5..abdbc7e19e 100644 --- a/examples/go.sum +++ b/examples/go.sum @@ -1,9 +1,5 @@ -charm.land/bubbles/v2 v2.1.0 h1:YSnNh5cPYlYjPxRrzs5VEn3vwhtEn3jVGRBT3M7/I0g= -charm.land/bubbles/v2 v2.1.0/go.mod h1:l97h4hym2hvWBVfmJDtrEHHCtkIKeTEb3TTJ4ZOB3wY= charm.land/glamour/v2 v2.0.0 h1:IDBoqLEy7Hdpb9VOXN+khLP/XSxtJy1VsHuW/yF87+U= charm.land/glamour/v2 v2.0.0/go.mod h1:kjq9WB0s8vuUYZNYey2jp4Lgd9f4cKdzAw88FZtpj/w= -charm.land/lipgloss/v2 v2.0.2 h1:xFolbF8JdpNkM2cEPTfXEcW1p6NRzOWTSamRfYEw8cs= -charm.land/lipgloss/v2 v2.0.2/go.mod h1:KjPle2Qd3YmvP1KL5OMHiHysGcNwq6u83MUjYkFvEkM= github.com/MakeNowJust/heredoc v1.0.0 h1:cXCdzVdstXyiTqTvfqk9SDHpKNjxuom+DOlyEeQ4pzQ= github.com/MakeNowJust/heredoc v1.0.0/go.mod h1:mG5amYoWBHf8vpLOuehzbGGw0EHxpZZ6lCpQ4fNJ8LE= github.com/alecthomas/assert/v2 v2.7.0 h1:QtqSACNS3tF7oasA8CU6A6sXZSBDqnm7RfpLl9bZqbE= @@ -14,8 +10,8 @@ github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4= github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= -github.com/aymanbagabas/go-udiff v0.4.1 h1:OEIrQ8maEeDBXQDoGCbbTTXYJMYRCRO1fnodZ12Gv5o= -github.com/aymanbagabas/go-udiff v0.4.1/go.mod h1:0L9PGwj20lrtmEMeyw4WKJ/TMyDtvAoK9bf2u/mNo3w= +github.com/aymanbagabas/go-udiff v0.4.0 h1:TKnLPh7IbnizJIBKFWa9mKayRUBQ9Kh1BPCk6w2PnYM= +github.com/aymanbagabas/go-udiff v0.4.0/go.mod h1:0L9PGwj20lrtmEMeyw4WKJ/TMyDtvAoK9bf2u/mNo3w= 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/colorprofile v0.4.3 h1:QPa1IWkYI+AOB+fE+mg/5/4HRMZcaXex9t5KX76i20Q= @@ -58,8 +54,8 @@ github.com/lucasb-eyer/go-colorful v1.3.0 h1:2/yBRLdWBZKrf7gB40FoiKfAWYQ0lqNcbuQ github.com/lucasb-eyer/go-colorful v1.3.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/mattn/go-runewidth v0.0.21 h1:jJKAZiQH+2mIinzCJIaIG9Be1+0NR+5sz/lYEEjdM8w= -github.com/mattn/go-runewidth v0.0.21/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs= +github.com/mattn/go-runewidth v0.0.20 h1:WcT52H91ZUAwy8+HUkdM3THM6gXqXuLJi9O3rjcQQaQ= +github.com/mattn/go-runewidth v0.0.20/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs= github.com/microcosm-cc/bluemonday v1.0.27 h1:MpEUotklkwCSLeH+Qdx1VJgNqLlpY2KXwXFM08ygZfk= github.com/microcosm-cc/bluemonday v1.0.27/go.mod h1:jFi9vgW+H7c3V0lb6nR74Ib/DIB5OBs92Dimizgw2cA= github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA= diff --git a/examples/tree-default/main.go b/examples/tree-default/main.go new file mode 100644 index 0000000000..2309e0161c --- /dev/null +++ b/examples/tree-default/main.go @@ -0,0 +1,62 @@ +package main + +import ( + "fmt" + "os" + + "charm.land/bubbles/v2/tree" + tea "charm.land/bubbletea/v2" +) + +type model struct { + tree tree.Model +} + +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.KeyPressMsg: + switch msg.String() { + case "q", "ctrl+c": + return m, tea.Quit + } + } + m.tree, cmd = m.tree.Update(msg) + return m, cmd +} + +func (m model) View() string { + return m.tree.View() +} + +func main() { + t := tree.New(tree.Root("~/charm"). + Child( + "ayman", + tree.Root("bash"). + Child( + tree.Root("tools"). + Child("zsh", + "doom-emacs", + ), + ), + tree.Root("carlos"). + Child( + tree.Root("emotes"). + Child( + "chefkiss.png", + "kekw.png", + ), + ), + "maas", + ), 70, 13) + + if _, err := tea.NewProgram(model{tree: t}).Run(); err != nil { + fmt.Println("Oh no:", err) + os.Exit(1) + } +} diff --git a/examples/tree-file-system/main.go b/examples/tree-file-system/main.go new file mode 100644 index 0000000000..53675e696a --- /dev/null +++ b/examples/tree-file-system/main.go @@ -0,0 +1,142 @@ +package main + +import ( + "fmt" + "os" + + "charm.land/bubbles/v2/key" + "charm.land/bubbles/v2/tree" + tea "charm.land/bubbletea/v2" + "charm.land/lipgloss/v2" + ltree "charm.land/lipgloss/v2/tree" + "github.com/charmbracelet/x/ansi" +) + +type model struct { + tree tree.Model + choice *tree.Node +} + +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.KeyPressMsg: + switch msg.String() { + case "e": + m.choice = m.tree.NodeAtCurrentOffset() + return m, tea.Quit + case "q", "ctrl+c": + return m, tea.Quit + } + } + m.tree, cmd = m.tree.Update(msg) + m.updateStyles() + + return m, cmd +} + +func (m *model) updateStyles() { + dimmed := lipgloss.Color("239") + base := lipgloss.NewStyle() + m.tree.SetStyles(tree.Styles{ + TreeStyle: base. + Padding(1). + Border(lipgloss.RoundedBorder()). + BorderForeground(lipgloss.Color("236")). + BorderBackground(base.GetBackground()), + RootNodeStyle: base, + NodeStyle: base, + ParentNodeStyle: base, + OpenIndicatorStyle: base, + SelectedNodeStyle: base.Bold(true).Background(lipgloss.Color("8")), + HelpStyle: base.MarginTop(1), + EnumeratorStyle: base.Foreground(dimmed), + IndenterStyle: base.Foreground(dimmed), + }) +} + +func (m model) View() string { + return m.tree.View() +} + +type file struct { + name string + color string +} + +func (f file) String() string { + return "⌯ " + lipgloss.NewStyle().Foreground(lipgloss.Color(f.color)).Render(f.name) +} + +type dir struct { + name string +} + +func (d dir) String() string { + return lipgloss.NewStyle().Foreground(lipgloss.Color("4")).Render(d.name) +} + +const ( + width = 50 + height = 21 + enumeratorWidth = 3 +) + +func main() { + t := tree.New( + tree.Root(dir{"charmbracelet/lipgloss"}). + Indenter(func(_ ltree.Children, _ int) string { + return "│ " + }). + Enumerator(func(_ ltree.Children, _ int) string { + return "│ " + }). + Child( + tree.Root(dir{"tree"}). + Child(file{"tree.go", "6"}). + Child(file{"renderer.go", "6"}), + ). + Child( + tree.Root(dir{"table"}). + Child( + tree.Root(dir{"utils"}). + Child(file{"utils.go", "6"}), + ), + ). + Child(tree.Root(dir{"list"}).Child(lipgloss.NewStyle().Faint(true).Render("(empty)"))). + Child(file{"README.md", "3"}). + Child(file{"go.mod", "255"}). + Child(file{"go.sum", "255"}). + Child(file{".gitignore", "255"}), + width, + height, + ) + t.SetCursorCharacter("") + t.SetOpenCharacter("📂") + t.SetClosedCharacter("📁") + kb := []key.Binding{ + key.NewBinding(key.WithKeys("e"), key.WithHelp("e", "select")), + } + t.AdditionalShortHelpKeys = func() []key.Binding { + return kb + } + t.AdditionalFullHelpKeys = func() []key.Binding { + return kb + } + + p := tea.NewProgram(model{tree: t}) + m, err := p.Run() + if err != nil { + fmt.Println("Oh no:", err) + os.Exit(1) + } + + // Assert the final tea.Model to our local model and print the choice. + if m, ok := m.(model); ok && m.choice != nil { + fmt.Printf("---\nYou chose %s!\n", ansi.Strip(m.choice.Value())) + } +} diff --git a/examples/tree-long/main.go b/examples/tree-long/main.go new file mode 100644 index 0000000000..6f77ac6ab3 --- /dev/null +++ b/examples/tree-long/main.go @@ -0,0 +1,63 @@ +package main + +import ( + "fmt" + "os" + "time" + + "charm.land/bubbles/v2/tree" + tea "charm.land/bubbletea/v2" + "charm.land/lipgloss/v2" +) + +type model struct { + tree tree.Model +} + +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.KeyPressMsg: + switch msg.String() { + case "q", "ctrl+c": + return m, tea.Quit + } + } + m.tree, cmd = m.tree.Update(msg) + return m, cmd +} + +func (m model) View() string { + return m.tree.View() +} + +func main() { + root := tree.Root("🛂 Passport expiration date") + thisYear := time.Now().Year() + for year := thisYear; year < thisYear+10; year++ { + yRoot := tree.Root(fmt.Sprintf("%d", year)).Close() + for month := 1; month <= 12; month++ { + mRoot := tree.Root(time.Month(month).String()).Close().RootStyle(lipgloss.NewStyle().Foreground(lipgloss.Color("1"))) + for day := 1; day < daysIn(time.Month(month), year); day++ { + mRoot.Child(fmt.Sprintf("%d", day)) + } + yRoot.Child(mRoot) + } + root.Child(yRoot) + } + + t := tree.New(root, 80, 30) + + if _, err := tea.NewProgram(model{tree: t}).Run(); err != nil { + fmt.Println("Oh no:", err) + os.Exit(1) + } +} + +func daysIn(m time.Month, year int) int { + return time.Date(year, m+1, 0, 0, 0, 0, 0, time.UTC).Day() +} diff --git a/examples/tree-toc/main.go b/examples/tree-toc/main.go new file mode 100644 index 0000000000..7c858dc014 --- /dev/null +++ b/examples/tree-toc/main.go @@ -0,0 +1,120 @@ +package main + +import ( + "fmt" + "os" + + "charm.land/bubbles/v2/tree" + tea "charm.land/bubbletea/v2" + "charm.land/lipgloss/v2" + ltree "charm.land/lipgloss/v2/tree" +) + +type model struct { + tree tree.Model +} + +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.KeyPressMsg: + switch msg.String() { + case "q", "ctrl+c": + return m, tea.Quit + } + } + m.tree, cmd = m.tree.Update(msg) + m.updateStyles() + + return m, cmd +} + +func (m *model) updateStyles() { + m.tree.SetStyles(tree.Styles{ + RootNodeStyle: lipgloss.NewStyle().Foreground(lipgloss.Color("205")), + SelectedNodeStyle: lipgloss.NewStyle().Foreground(lipgloss.Color("#EE6FF8")).Bold(true), + CursorStyle: lipgloss.NewStyle().Foreground(lipgloss.Color("#EE6FF8")).Bold(true), + HelpStyle: lipgloss.NewStyle().MarginTop(1), + }) +} + +func (m model) View() string { + pageNumbers := make([]string, len(m.tree.AllNodes())) + for i, node := range m.tree.AllNodes() { + v := node.GivenValue() + if page, ok := v.(page); ok { + num := fmt.Sprintf("%d", page.page) + if i == m.tree.YOffset() { + num = lipgloss.NewStyle().Foreground(lipgloss.Color("#EE6FF8")).Bold(true).Render(num) + } else { + num = lipgloss.NewStyle().Foreground(lipgloss.Color("245")).Render(num) + } + pageNumbers[i] = num + } + } + return lipgloss.NewStyle().Padding(1).Render( + lipgloss.JoinHorizontal( + lipgloss.Top, + m.tree.View(), + lipgloss.JoinVertical(lipgloss.Left, pageNumbers...)), + ) +} + +const ( + width = 60 + height = 12 + enumeratorWidth = 3 +) + +func enumerator(_ ltree.Children, _ int) string { + return " " +} + +func indenter(_ ltree.Children, _ int) string { + return " " +} + +type page struct { + title string + page int +} + +func (p page) String() string { + return p.title +} + +func main() { + t := tree.New( + tree.Root(page{"Go Mistakes", 1}). + Enumerator(enumerator). + Indenter(indenter). + Child( + tree.Root(page{"Code and Project Organization", 2}). + Child(page{"Unintended variable shadowing", 12}). + Child(page{"Unnecessary nested code", 22}), + ). + Child( + tree.Root(page{"Data Types", 23}). + Child(page{"Creating confusion with octal literals", 28}). + Child(page{"Neglecting integer overflows", 52}), + ). + Child( + tree.Root(page{"Strings", 53}). + Child(page{"Not understaing the concept of rune", 59}). + Child(page{"Misusing trim functions", 61}), + ), + width, + height, + ) + t.SetClosedCharacter("📘") + t.SetOpenCharacter("📖") + + if _, err := tea.NewProgram(model{tree: t}).Run(); err != nil { + fmt.Println("Oh no:", err) + os.Exit(1) + } +} From 833ff7c9b51f83449c8f8083c232bb947cd017b4 Mon Sep 17 00:00:00 2001 From: Dolev Hadar Date: Fri, 18 Apr 2025 13:32:03 +0300 Subject: [PATCH 2/3] refactor --- examples/tree-file-system/main.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/tree-file-system/main.go b/examples/tree-file-system/main.go index 53675e696a..11028c7e8d 100644 --- a/examples/tree-file-system/main.go +++ b/examples/tree-file-system/main.go @@ -121,12 +121,12 @@ func main() { kb := []key.Binding{ key.NewBinding(key.WithKeys("e"), key.WithHelp("e", "select")), } - t.AdditionalShortHelpKeys = func() []key.Binding { + t.SetAdditionalShortHelpKeys(func() []key.Binding { return kb - } - t.AdditionalFullHelpKeys = func() []key.Binding { + }) + t.SetAdditionalFullHelpKeys(func() []key.Binding { return kb - } + }) p := tea.NewProgram(model{tree: t}) m, err := p.Run() From baadff9e7a5656933a6e71f326a1a147241b13f4 Mon Sep 17 00:00:00 2001 From: Dolev Hadar Date: Wed, 19 Nov 2025 20:59:08 +0200 Subject: [PATCH 3/3] chore: rebase --- examples/go.mod | 2 +- examples/go.sum | 6 ++++-- examples/tree-default/main.go | 4 ++-- examples/tree-file-system/main.go | 4 ++-- examples/tree-long/main.go | 7 ++++--- examples/tree-toc/main.go | 11 ++++++----- 6 files changed, 19 insertions(+), 15 deletions(-) diff --git a/examples/go.mod b/examples/go.mod index 2621b3aecd..dc5fe33604 100644 --- a/examples/go.mod +++ b/examples/go.mod @@ -47,6 +47,6 @@ require ( golang.org/x/text v0.24.0 // indirect ) -replace charm.land/lipgloss/v2 v2.0.2 => ../../lipgloss +replace charm.land/lipgloss/v2 v2.0.0 => ../../lipgloss replace charm.land/bubbles/v2 v2.1.0 => ../../bubbles diff --git a/examples/go.sum b/examples/go.sum index abdbc7e19e..250317ffb1 100644 --- a/examples/go.sum +++ b/examples/go.sum @@ -1,5 +1,7 @@ charm.land/glamour/v2 v2.0.0 h1:IDBoqLEy7Hdpb9VOXN+khLP/XSxtJy1VsHuW/yF87+U= charm.land/glamour/v2 v2.0.0/go.mod h1:kjq9WB0s8vuUYZNYey2jp4Lgd9f4cKdzAw88FZtpj/w= +charm.land/lipgloss/v2 v2.0.2 h1:xFolbF8JdpNkM2cEPTfXEcW1p6NRzOWTSamRfYEw8cs= +charm.land/lipgloss/v2 v2.0.2/go.mod h1:KjPle2Qd3YmvP1KL5OMHiHysGcNwq6u83MUjYkFvEkM= github.com/MakeNowJust/heredoc v1.0.0 h1:cXCdzVdstXyiTqTvfqk9SDHpKNjxuom+DOlyEeQ4pzQ= github.com/MakeNowJust/heredoc v1.0.0/go.mod h1:mG5amYoWBHf8vpLOuehzbGGw0EHxpZZ6lCpQ4fNJ8LE= github.com/alecthomas/assert/v2 v2.7.0 h1:QtqSACNS3tF7oasA8CU6A6sXZSBDqnm7RfpLl9bZqbE= @@ -10,8 +12,8 @@ github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4= github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= -github.com/aymanbagabas/go-udiff v0.4.0 h1:TKnLPh7IbnizJIBKFWa9mKayRUBQ9Kh1BPCk6w2PnYM= -github.com/aymanbagabas/go-udiff v0.4.0/go.mod h1:0L9PGwj20lrtmEMeyw4WKJ/TMyDtvAoK9bf2u/mNo3w= +github.com/aymanbagabas/go-udiff v0.4.1 h1:OEIrQ8maEeDBXQDoGCbbTTXYJMYRCRO1fnodZ12Gv5o= +github.com/aymanbagabas/go-udiff v0.4.1/go.mod h1:0L9PGwj20lrtmEMeyw4WKJ/TMyDtvAoK9bf2u/mNo3w= 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/colorprofile v0.4.3 h1:QPa1IWkYI+AOB+fE+mg/5/4HRMZcaXex9t5KX76i20Q= diff --git a/examples/tree-default/main.go b/examples/tree-default/main.go index 2309e0161c..ca5d824c82 100644 --- a/examples/tree-default/main.go +++ b/examples/tree-default/main.go @@ -29,8 +29,8 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, cmd } -func (m model) View() string { - return m.tree.View() +func (m model) View() tea.View { + return tea.NewView(m.tree.View()) } func main() { diff --git a/examples/tree-file-system/main.go b/examples/tree-file-system/main.go index 11028c7e8d..6d36e07d3f 100644 --- a/examples/tree-file-system/main.go +++ b/examples/tree-file-system/main.go @@ -59,8 +59,8 @@ func (m *model) updateStyles() { }) } -func (m model) View() string { - return m.tree.View() +func (m model) View() tea.View { + return tea.NewView(m.tree.View()) } type file struct { diff --git a/examples/tree-long/main.go b/examples/tree-long/main.go index 6f77ac6ab3..4b8aaa36a4 100644 --- a/examples/tree-long/main.go +++ b/examples/tree-long/main.go @@ -31,8 +31,8 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, cmd } -func (m model) View() string { - return m.tree.View() +func (m model) View() tea.View { + return tea.NewView(m.tree.View()) } func main() { @@ -41,7 +41,8 @@ func main() { for year := thisYear; year < thisYear+10; year++ { yRoot := tree.Root(fmt.Sprintf("%d", year)).Close() for month := 1; month <= 12; month++ { - mRoot := tree.Root(time.Month(month).String()).Close().RootStyle(lipgloss.NewStyle().Foreground(lipgloss.Color("1"))) + mRoot := tree.Root(time.Month(month).String()).Close().RootStyle( + lipgloss.NewStyle().Foreground(lipgloss.Color("1"))) for day := 1; day < daysIn(time.Month(month), year); day++ { mRoot.Child(fmt.Sprintf("%d", day)) } diff --git a/examples/tree-toc/main.go b/examples/tree-toc/main.go index 7c858dc014..1a3556dd12 100644 --- a/examples/tree-toc/main.go +++ b/examples/tree-toc/main.go @@ -42,7 +42,7 @@ func (m *model) updateStyles() { }) } -func (m model) View() string { +func (m model) View() tea.View { pageNumbers := make([]string, len(m.tree.AllNodes())) for i, node := range m.tree.AllNodes() { v := node.GivenValue() @@ -56,18 +56,19 @@ func (m model) View() string { pageNumbers[i] = num } } - return lipgloss.NewStyle().Padding(1).Render( + v := lipgloss.NewStyle().Padding(1).Render( lipgloss.JoinHorizontal( lipgloss.Top, m.tree.View(), lipgloss.JoinVertical(lipgloss.Left, pageNumbers...)), ) + + return tea.NewView(v) } const ( - width = 60 - height = 12 - enumeratorWidth = 3 + width = 60 + height = 12 ) func enumerator(_ ltree.Children, _ int) string {