From c1c679a27112f773142056d3a66bb0e6f4e05c89 Mon Sep 17 00:00:00 2001 From: bashbunni Date: Wed, 7 Aug 2024 16:10:25 -0700 Subject: [PATCH] refactor(examples): use Root shorthand instead of tree.New where applicable --- README.md | 12 ++++-------- examples/tree/background/main.go | 10 ++++------ examples/tree/files/main.go | 4 ++-- examples/tree/rounded/main.go | 12 ++++-------- examples/tree/simple/main.go | 3 +-- examples/tree/styles/main.go | 3 +-- examples/tree/toggle/main.go | 3 +-- 7 files changed, 17 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index ad13e110..e8b39325 100644 --- a/README.md +++ b/README.md @@ -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") ``` @@ -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"), ) diff --git a/examples/tree/background/main.go b/examples/tree/background/main.go index 0955383d..a38ca626 100644 --- a/examples/tree/background/main.go +++ b/examples/tree/background/main.go @@ -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"), ) diff --git a/examples/tree/files/main.go b/examples/tree/files/main.go index 2f274ad9..9e6250b8 100644 --- a/examples/tree/files/main.go +++ b/examples/tree/files/main.go @@ -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 }) diff --git a/examples/tree/rounded/main.go b/examples/tree/rounded/main.go index 2ab3e6c5..c32dae3a 100644 --- a/examples/tree/rounded/main.go +++ b/examples/tree/rounded/main.go @@ -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", diff --git a/examples/tree/simple/main.go b/examples/tree/simple/main.go index f636224e..718022ed 100644 --- a/examples/tree/simple/main.go +++ b/examples/tree/simple/main.go @@ -7,8 +7,7 @@ import ( ) func main() { - t := tree.New(). - Root("."). + t := tree.Root("."). Child("Item 1"). Child( tree.New(). diff --git a/examples/tree/styles/main.go b/examples/tree/styles/main.go index 2a24b363..9950b1f4 100644 --- a/examples/tree/styles/main.go +++ b/examples/tree/styles/main.go @@ -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", diff --git a/examples/tree/toggle/main.go b/examples/tree/toggle/main.go index a16a8fe7..b914c2f5 100644 --- a/examples/tree/toggle/main.go +++ b/examples/tree/toggle/main.go @@ -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}).