Skip to content

Commit

Permalink
refactor(examples): use Root shorthand instead of tree.New where appl…
Browse files Browse the repository at this point in the history
…icable
  • Loading branch information
bashbunni committed Aug 7, 2024
1 parent 81029f5 commit c1c679a
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 30 deletions.
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,7 @@ import "github.com/charmbracelet/lipgloss/tree"
Define a new tree.

```go
t := tree.New().
Root(".").
t := tree.Root(".").
Child("A", "B", "C")
```

Expand All @@ -592,19 +591,16 @@ fmt.Println(t)
Trees have the ability to nest.

```go
t := tree.New().
Root(".").
t := tree.Root(".").
Child("Item 1").
Child(
tree.New().
Root("Item 2").
tree.Root("Item 2").
Child("Item 2.1").
Child("Item 2.2").
Child("Item 2.3"),
).
Child(
tree.New().
Root("Item 3").
tree.Root("Item 3").
Child("Item 3.1").
Child("Item 3.2"),
)
Expand Down
10 changes: 4 additions & 6 deletions examples/tree/background/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,17 @@ func main() {

itemStyle := headerItemStyle.Background(lipgloss.Color("0"))

t := tree.New().
t := tree.Root("# Table of Contents").
RootStyle(itemStyle).
ItemStyle(itemStyle).
EnumeratorStyle(enumeratorStyle).
Root("# Table of Contents").
Child(
tree.New().
Root("## Chapter 1").
tree.Root("## Chapter 1").
Child("Chapter 1.1").
Child("Chapter 1.2"),
).
Child(
tree.New().
Root("## Chapter 2").
tree.Root("## Chapter 2").
Child("Chapter 2.1").
Child("Chapter 2.2"),
)
Expand Down
4 changes: 2 additions & 2 deletions examples/tree/files/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ func main() {
enumeratorStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("240")).PaddingRight(1)
itemStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("99")).Bold(true).PaddingRight(1)

t := tree.New().Root(".").EnumeratorStyle(enumeratorStyle).ItemStyle(itemStyle)
t := tree.Root(".").EnumeratorStyle(enumeratorStyle).ItemStyle(itemStyle)
_ = filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
t.Child(tree.New().Root(path))
t.Child(tree.Root(path))
}
return nil
})
Expand Down
12 changes: 4 additions & 8 deletions examples/tree/rounded/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,22 @@ func main() {
itemStyle := lipgloss.NewStyle().MarginRight(1)
enumeratorStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("8")).MarginRight(1)

t := tree.New().
Root("Groceries").
t := tree.Root("Groceries").
Child(
tree.New().
Root("Fruits").
tree.Root("Fruits").
Child(
"Blood Orange",
"Papaya",
"Dragonfruit",
"Yuzu",
),
tree.New().
Root("Items").
tree.Root("Items").
Child(
"Cat Food",
"Nutella",
"Powdered Sugar",
),
tree.New().
Root("Veggies").
tree.Root("Veggies").
Child(
"Leek",
"Artichoke",
Expand Down
3 changes: 1 addition & 2 deletions examples/tree/simple/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
)

func main() {
t := tree.New().
Root(".").
t := tree.Root(".").
Child("Item 1").
Child(
tree.New().
Expand Down
3 changes: 1 addition & 2 deletions examples/tree/styles/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ func main() {
Child(
"Glossier",
"Claire’s Boutique",
tree.New().
Root("Nyx").
tree.Root("Nyx").
Child("Lip Gloss", "Foundation").
EnumeratorStyle(pink),
"Mac",
Expand Down
3 changes: 1 addition & 2 deletions examples/tree/toggle/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ func (s file) String() string {
func main() {
s := defaultStyles()

t := tree.New().
t := tree.Root(dir{"~", true, s}).
Enumerator(tree.RoundedEnumerator).
EnumeratorStyle(s.enumerator).
Root(dir{"~", true, s}).
Child(
dir{"ayman", false, s},
tree.Root(dir{"bash", false, s}).
Expand Down

0 comments on commit c1c679a

Please sign in to comment.