charmbracelet / lipgloss

Style definitions for nice terminal layouts 👄
MIT License
8.06k stars 229 forks source link

tree - expose node offset to make styling based on it possible #365

Open dlvhdr opened 1 month ago

dlvhdr commented 1 month ago

Is your feature request related to a problem? Please describe.

I would like to limit the width of a node's text so it's always one line.

Also, I'm not sure if it's possible, but I would like to have the ability to add ellipsis to items with overflowing text - could be a separate issue.

Describe the solution you'd like

Expose an offset attribute so I know what level a node is in (its depth). I will then use it like so:

tree.Root().ItemStyleFunc(func(children tree.Children, i int) lipgloss.Style {
  node := children.At(i)
  return lipgloss.NewStyle().MaxWidth(SidebarWidth - node.Offset())
})

Describe alternatives you've considered

Additional context Using MaxWidth of 10 gives me this which only "works" for some of the nodes. image

caarlos0 commented 2 weeks ago

hey Dolev!

I think the Offset() method makes sense.

Do you wanna work on a PR, or should I do it?

dlvhdr commented 2 weeks ago

I was actually thinking of taking a stab at writing a bubbles for the tree, so I'm thinking maybe I can write a draft to figure out if anything else needs to be exposed before implementing Offset, wdyt?

caarlos0 commented 2 weeks ago

Awesome! Sounds like a plan 🙏🏻