Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/basic/03-styling/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"

"github.com/charmbracelet/lipgloss"
"charm.land/lipgloss/v2"

"github.com/Digital-Shane/treeview"
"github.com/Digital-Shane/treeview/examples/shared"
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/04-comparison-display/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/Digital-Shane/treeview"
"github.com/Digital-Shane/treeview/examples/shared"
"github.com/charmbracelet/lipgloss"
"charm.land/lipgloss/v2"
)

////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/05-workflow-visualization/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/Digital-Shane/treeview"
"github.com/Digital-Shane/treeview/examples/shared"
"github.com/charmbracelet/lipgloss"
"charm.land/lipgloss/v2"
)

////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/07-builders-nested/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/Digital-Shane/treeview"
"github.com/Digital-Shane/treeview/examples/shared"
"github.com/charmbracelet/lipgloss"
"charm.land/lipgloss/v2"
)

// ==========================================================================
Expand Down
4 changes: 2 additions & 2 deletions examples/intermediate/01-keyboard-controls/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"os"

tea "charm.land/bubbletea/v2"
"github.com/Digital-Shane/treeview"
"github.com/charmbracelet/bubbletea"
)

func main() {
Expand All @@ -26,7 +26,7 @@ func main() {
)

// Create the program with navigation help bar
p := tea.NewProgram(model, tea.WithAltScreen())
p := tea.NewProgram(model)

// Run the program directly
if _, err := p.Run(); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions examples/intermediate/02-search/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"os"
"strings"

tea "charm.land/bubbletea/v2"
"github.com/Digital-Shane/treeview"
"github.com/charmbracelet/bubbletea"
)

// Product represents a product with additional searchable data
Expand Down Expand Up @@ -41,7 +41,7 @@ func main() {
)

// Run the program
p := tea.NewProgram(model, tea.WithAltScreen())
p := tea.NewProgram(model)
if _, err := p.Run(); err != nil {
fmt.Printf("Error running program: %v\n", err)
os.Exit(1)
Expand Down
4 changes: 2 additions & 2 deletions examples/intermediate/03-viewport/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"log"

tea "charm.land/bubbletea/v2"
"github.com/Digital-Shane/treeview"
"github.com/charmbracelet/bubbletea"
)

func main() {
Expand All @@ -32,7 +32,7 @@ func main() {
}

// Create the program
p := tea.NewProgram(model, tea.WithAltScreen())
p := tea.NewProgram(model)

// Run the program
if _, err := p.Run(); err != nil {
Expand Down
25 changes: 16 additions & 9 deletions examples/intermediate/04-file-browser/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"strings"
"time"

tea "charm.land/bubbletea/v2"
"charm.land/lipgloss/v2"
"github.com/Digital-Shane/treeview"
"github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)

func main() {
Expand All @@ -26,7 +26,7 @@ func main() {
model := NewFileBrowserModel(initialPath)

// Create the program
p := tea.NewProgram(model, tea.WithAltScreen())
p := tea.NewProgram(model)

// Run the program
if _, err := p.Run(); err != nil {
Expand Down Expand Up @@ -269,9 +269,14 @@ func (m *FileBrowserModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}

// View renders the complete file browser interface
func (m *FileBrowserModel) View() string {
func (m *FileBrowserModel) View() tea.View {
var view tea.View

view.AltScreen = true

if m.treeModel == nil {
return "Loading..."
view.SetContent("Loading...")
return view
}

var b strings.Builder
Expand All @@ -281,13 +286,15 @@ func (m *FileBrowserModel) View() string {
if m.showMetadata {
b.WriteString(m.renderTwoPanelLayout())
} else {
b.WriteString(m.treeModel.View())
b.WriteString(m.treeModel.View().Content)
}

b.WriteByte('\n')
b.WriteString(m.renderStatusBar())

return b.String()
view.SetContent(b.String())

return view
}

// renderHeader creates the header bar
Expand All @@ -309,7 +316,7 @@ func (m *FileBrowserModel) renderTwoPanelLayout() string {
metadataView := m.renderMetadataPanel(metadataWidth)
treeView := m.treeModel.View()

return lipgloss.JoinHorizontal(lipgloss.Top, metadataView, " │ ", treeView)
return lipgloss.JoinHorizontal(lipgloss.Top, metadataView, " │ ", treeView.Content)
}

// renderMetadataPanel creates the metadata side panel
Expand Down Expand Up @@ -385,7 +392,7 @@ func (m *FileBrowserModel) renderMultiNodeMetadata(nodes []*treeview.Node[treevi
// Count by type
var files, dirs int
var totalSize int64
var extensions = make(map[string]int)
extensions := make(map[string]int)

for _, node := range nodes {
data := node.Data()
Expand Down
35 changes: 16 additions & 19 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
module github.com/Digital-Shane/treeview

go 1.24
go 1.25.0

require (
github.com/charmbracelet/bubbles v0.21.0
github.com/charmbracelet/bubbletea v1.3.6
github.com/charmbracelet/lipgloss v1.1.0
charm.land/bubbles/v2 v2.1.0
charm.land/bubbletea/v2 v2.0.2
charm.land/lipgloss/v2 v2.0.2
github.com/google/go-cmp v0.7.0
github.com/mattn/go-runewidth v0.0.16
github.com/mattn/go-runewidth v0.0.21
)

require (
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/charmbracelet/colorprofile v0.3.1 // indirect
github.com/charmbracelet/x/ansi v0.9.3 // indirect
github.com/charmbracelet/x/cellbuf v0.0.13 // indirect
github.com/charmbracelet/x/term v0.2.1 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/charmbracelet/colorprofile v0.4.2 // indirect
github.com/charmbracelet/ultraviolet v0.0.0-20260205113103-524a6607adb8 // indirect
github.com/charmbracelet/x/ansi v0.11.6 // indirect
github.com/charmbracelet/x/term v0.2.2 // indirect
github.com/charmbracelet/x/termios v0.1.1 // indirect
github.com/charmbracelet/x/windows v0.2.2 // indirect
github.com/clipperhouse/displaywidth v0.11.0 // indirect
github.com/clipperhouse/uax29/v2 v2.7.0 // indirect
github.com/lucasb-eyer/go-colorful v1.3.0 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/termenv v0.16.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/sync v0.16.0 // indirect
golang.org/x/sys v0.34.0 // indirect
golang.org/x/text v0.27.0 // indirect
golang.org/x/sync v0.19.0 // indirect
golang.org/x/sys v0.42.0 // indirect
)
77 changes: 36 additions & 41 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,49 +1,44 @@
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/charmbracelet/bubbles v0.21.0 h1:9TdC97SdRVg/1aaXNVWfFH3nnLAwOXr8Fn6u6mfQdFs=
github.com/charmbracelet/bubbles v0.21.0/go.mod h1:HF+v6QUR4HkEpz62dx7ym2xc71/KBHg+zKwJtMw+qtg=
github.com/charmbracelet/bubbletea v1.3.6 h1:VkHIxPJQeDt0aFJIsVxw8BQdh/F/L2KKZGsK6et5taU=
github.com/charmbracelet/bubbletea v1.3.6/go.mod h1:oQD9VCRQFF8KplacJLo28/jofOI2ToOfGYeFgBBxHOc=
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/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY=
github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30=
github.com/charmbracelet/x/ansi v0.9.3 h1:BXt5DHS/MKF+LjuK4huWrC6NCvHtexww7dMayh6GXd0=
github.com/charmbracelet/x/ansi v0.9.3/go.mod h1:3RQDQ6lDnROptfpWuUVIUG64bD2g2BgntdxH0Ya5TeE=
github.com/charmbracelet/x/cellbuf v0.0.13 h1:/KBBKHuVRbq1lYx5BzEHBAFBP8VcQzJejZ/IA3iR28k=
github.com/charmbracelet/x/cellbuf v0.0.13/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs=
github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
charm.land/bubbles/v2 v2.1.0 h1:YSnNh5cPYlYjPxRrzs5VEn3vwhtEn3jVGRBT3M7/I0g=
charm.land/bubbles/v2 v2.1.0/go.mod h1:l97h4hym2hvWBVfmJDtrEHHCtkIKeTEb3TTJ4ZOB3wY=
charm.land/bubbletea/v2 v2.0.2 h1:4CRtRnuZOdFDTWSff9r8QFt/9+z6Emubz3aDMnf/dx0=
charm.land/bubbletea/v2 v2.0.2/go.mod h1:3LRff2U4WIYXy7MTxfbAQ+AdfM3D8Xuvz2wbsOD9OHQ=
charm.land/lipgloss/v2 v2.0.2 h1:xFolbF8JdpNkM2cEPTfXEcW1p6NRzOWTSamRfYEw8cs=
charm.land/lipgloss/v2 v2.0.2/go.mod h1:KjPle2Qd3YmvP1KL5OMHiHysGcNwq6u83MUjYkFvEkM=
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/charmbracelet/colorprofile v0.4.2 h1:BdSNuMjRbotnxHSfxy+PCSa4xAmz7szw70ktAtWRYrY=
github.com/charmbracelet/colorprofile v0.4.2/go.mod h1:0rTi81QpwDElInthtrQ6Ni7cG0sDtwAd4C4le060fT8=
github.com/charmbracelet/ultraviolet v0.0.0-20260205113103-524a6607adb8 h1:eyFRbAmexyt43hVfeyBofiGSEmJ7krjLOYt/9CF5NKA=
github.com/charmbracelet/ultraviolet v0.0.0-20260205113103-524a6607adb8/go.mod h1:SQpCTRNBtzJkwku5ye4S3HEuthAlGy2n9VXZnWkEW98=
github.com/charmbracelet/x/ansi v0.11.6 h1:GhV21SiDz/45W9AnV2R61xZMRri5NlLnl6CVF7ihZW8=
github.com/charmbracelet/x/ansi v0.11.6/go.mod h1:2JNYLgQUsyqaiLovhU2Rv/pb8r6ydXKS3NIttu3VGZQ=
github.com/charmbracelet/x/exp/golden v0.0.0-20250806222409-83e3a29d542f h1:pk6gmGpCE7F3FcjaOEKYriCvpmIN4+6OS/RD0vm4uIA=
github.com/charmbracelet/x/exp/golden v0.0.0-20250806222409-83e3a29d542f/go.mod h1:IfZAMTHB6XkZSeXUqriemErjAWCCzT0LwjKFYCZyw0I=
github.com/charmbracelet/x/term v0.2.2 h1:xVRT/S2ZcKdhhOuSP4t5cLi5o+JxklsoEObBSgfgZRk=
github.com/charmbracelet/x/term v0.2.2/go.mod h1:kF8CY5RddLWrsgVwpw4kAa6TESp6EB5y3uxGLeCqzAI=
github.com/charmbracelet/x/termios v0.1.1 h1:o3Q2bT8eqzGnGPOYheoYS8eEleT5ZVNYNy8JawjaNZY=
github.com/charmbracelet/x/termios v0.1.1/go.mod h1:rB7fnv1TgOPOyyKRJ9o+AsTU/vK5WHJ2ivHeut/Pcwo=
github.com/charmbracelet/x/windows v0.2.2 h1:IofanmuvaxnKHuV04sC0eBy/smG6kIKrWG2/jYn2GuM=
github.com/charmbracelet/x/windows v0.2.2/go.mod h1:/8XtdKZzedat74NQFn0NGlGL4soHB0YQZrETF96h75k=
github.com/clipperhouse/displaywidth v0.11.0 h1:lBc6kY44VFw+TDx4I8opi/EtL9m20WSEFgwIwO+UVM8=
github.com/clipperhouse/displaywidth v0.11.0/go.mod h1:bkrFNkf81G8HyVqmKGxsPufD3JhNl3dSqnGhOoSD/o0=
github.com/clipperhouse/uax29/v2 v2.7.0 h1:+gs4oBZ2gPfVrKPthwbMzWZDaAFPGYK72F0NJv2v7Vk=
github.com/clipperhouse/uax29/v2 v2.7.0/go.mod h1:EFJ2TJMRUaplDxHKj1qAEhCtQPW2tJSwu5BF98AuoVM=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.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-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
github.com/lucasb-eyer/go-colorful v1.3.0 h1:2/yBRLdWBZKrf7gB40FoiKfAWYQ0lqNcbuQwVHXptag=
github.com/lucasb-eyer/go-colorful v1.3.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
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/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E=
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA=
golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/text v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4=
golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo=
golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
2 changes: 1 addition & 1 deletion providers.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package treeview

import (
"github.com/charmbracelet/lipgloss"
"charm.land/lipgloss/v2"
)

// NodeProvider lets you plug custom rendering logic into treeview. The generic
Expand Down
2 changes: 1 addition & 1 deletion providers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package treeview
import (
"testing"

"github.com/charmbracelet/lipgloss"
"charm.land/lipgloss/v2"
)

// Test helpers for creating test nodes
Expand Down
21 changes: 11 additions & 10 deletions renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"sync"
"unicode/utf8"

"github.com/charmbracelet/bubbles/viewport"
"charm.land/bubbles/v2/viewport"
"github.com/mattn/go-runewidth"
)

Expand Down Expand Up @@ -201,15 +201,16 @@ func renderTreeWithViewport[T any](ctx context.Context, tree *Tree[T], vp *viewp
focusedLineIndex := findFocusedLineIndex(ctx, tree)

// Auto-scroll to keep focused line visible BEFORE rendering
if focusedLineIndex >= 0 && vp.Height > 0 {
if focusedLineIndex >= 0 && vp.Height() > 0 {
// If focused line is above viewport, scroll up
if focusedLineIndex < vp.YOffset {
vp.YOffset = focusedLineIndex
} else if focusedLineIndex >= vp.YOffset+vp.Height {
if focusedLineIndex < vp.YOffset() {
vp.SetYOffset(focusedLineIndex)
} else if focusedLineIndex >= vp.YOffset()+vp.Height() {
// If focused line is below viewport, scroll down
// Keep one line of context if possible
vp.YOffset = focusedLineIndex - vp.Height + 1
vp.YOffset = max(vp.YOffset, 0)
offset := focusedLineIndex - vp.Height() + 1
offset = max(offset, 0)
vp.SetYOffset(offset)
}
}

Expand Down Expand Up @@ -258,12 +259,12 @@ func renderViewportOnly[T any](ctx context.Context, tree *Tree[T], vp *viewport.
}()

// Calculate the range of lines we need to render
startLine := vp.YOffset
endLine := vp.YOffset + vp.Height
startLine := vp.YOffset()
endLine := vp.YOffset() + vp.Height()

// Track state for single-pass rendering
currentLine := 0
renderBuffer := make([]string, 0, vp.Height) // Pre-allocate for viewport height
renderBuffer := make([]string, 0, vp.Height()) // Pre-allocate for viewport height

// ancestorIsLastChild tracks whether each ancestor (at each depth level) was the last
// child among its siblings. This determines whether we draw a vertical continuation
Expand Down
6 changes: 3 additions & 3 deletions renderer_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
"testing"

"github.com/charmbracelet/bubbles/viewport"
"github.com/charmbracelet/lipgloss"
"charm.land/bubbles/v2/viewport"
"charm.land/lipgloss/v2"
)

// benchProvider is a minimal provider to minimize noise in benchmarks.
Expand Down Expand Up @@ -63,7 +63,7 @@ var benchSink string // global sink to avoid compiler elimination

func benchmarkRenderer(b *testing.B, fn func(context.Context, *Tree[string], *viewport.Model) (string, error), tree *Tree[string]) {
ctx := context.Background()
vp := viewport.New(100, 30)
vp := viewport.New(viewport.WithWidth(100), viewport.WithHeight(30))
b.ResetTimer()
for i := 0; i < b.N; i++ {
vpcopy := vp // copy so offsets reset
Expand Down
Loading
Loading