-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: support any type for list Root func Signed-off-by: Carlos Alexandro Becker <[email protected]> * feat: move tree to root Signed-off-by: Carlos Alexandro Becker <[email protected]> * feat: more cleanup Signed-off-by: Carlos Alexandro Becker <[email protected]> * docs(examples): bring back tree examples * docs(examples): add tree toggle example * docs(examples): fix toggle tree hierarchy; as bashbunni metadata * fix(tree): stylize whitespace when vertically joining tree elements * docs: get started with trees * feat: add RootStyle with example * test: add test for RootStyle func * docs(godoc): replace list mentions in tree package * refactor(examples): use Root shorthand instead of tree.New where applicable --------- Signed-off-by: Carlos Alexandro Becker <[email protected]> Co-authored-by: bashbunni <[email protected]> Co-authored-by: Christian Rocha <[email protected]>
- Loading branch information
1 parent
0618c73
commit feb42a9
Showing
21 changed files
with
438 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/charmbracelet/lipgloss" | ||
"github.com/charmbracelet/lipgloss/tree" | ||
) | ||
|
||
func main() { | ||
enumeratorStyle := lipgloss.NewStyle(). | ||
Background(lipgloss.Color("0")). | ||
Padding(0, 1) | ||
|
||
headerItemStyle := lipgloss.NewStyle(). | ||
Background(lipgloss.Color("#ee6ff8")). | ||
Foreground(lipgloss.Color("#ecfe65")). | ||
Bold(true). | ||
Padding(0, 1) | ||
|
||
itemStyle := headerItemStyle.Background(lipgloss.Color("0")) | ||
|
||
t := tree.Root("# Table of Contents"). | ||
RootStyle(itemStyle). | ||
ItemStyle(itemStyle). | ||
EnumeratorStyle(enumeratorStyle). | ||
Child( | ||
tree.Root("## Chapter 1"). | ||
Child("Chapter 1.1"). | ||
Child("Chapter 1.2"), | ||
). | ||
Child( | ||
tree.Root("## Chapter 2"). | ||
Child("Chapter 2.1"). | ||
Child("Chapter 2.2"), | ||
) | ||
|
||
fmt.Println(t) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/charmbracelet/lipgloss" | ||
"github.com/charmbracelet/lipgloss/tree" | ||
) | ||
|
||
func main() { | ||
enumeratorStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("240")).PaddingRight(1) | ||
itemStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("99")).Bold(true).PaddingRight(1) | ||
|
||
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.Root(path)) | ||
} | ||
return nil | ||
}) | ||
|
||
fmt.Println(t) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/charmbracelet/lipgloss" | ||
"github.com/charmbracelet/lipgloss/tree" | ||
) | ||
|
||
func main() { | ||
enumeratorStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("99")).MarginRight(1) | ||
itemStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("212")).MarginRight(1) | ||
|
||
t := tree. | ||
Root("Makeup"). | ||
Child( | ||
"Glossier", | ||
"Claire’s Boutique", | ||
"Nyx", | ||
"Mac", | ||
"Milk", | ||
). | ||
Enumerator(tree.RoundedEnumerator). | ||
EnumeratorStyle(enumeratorStyle). | ||
ItemStyle(itemStyle). | ||
RootStyle(lipgloss.NewStyle().Foreground(lipgloss.Color("#04B575"))) | ||
|
||
fmt.Println(t) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/charmbracelet/lipgloss" | ||
"github.com/charmbracelet/lipgloss/tree" | ||
) | ||
|
||
func main() { | ||
itemStyle := lipgloss.NewStyle().MarginRight(1) | ||
enumeratorStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("8")).MarginRight(1) | ||
|
||
t := tree.Root("Groceries"). | ||
Child( | ||
tree.Root("Fruits"). | ||
Child( | ||
"Blood Orange", | ||
"Papaya", | ||
"Dragonfruit", | ||
"Yuzu", | ||
), | ||
tree.Root("Items"). | ||
Child( | ||
"Cat Food", | ||
"Nutella", | ||
"Powdered Sugar", | ||
), | ||
tree.Root("Veggies"). | ||
Child( | ||
"Leek", | ||
"Artichoke", | ||
), | ||
).ItemStyle(itemStyle).EnumeratorStyle(enumeratorStyle).Enumerator(tree.RoundedEnumerator) | ||
|
||
fmt.Println(t) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/charmbracelet/lipgloss/tree" | ||
) | ||
|
||
func main() { | ||
t := tree.Root("."). | ||
Child("Item 1"). | ||
Child( | ||
tree.New(). | ||
Root("Item 2"). | ||
Child("Item 2.1"). | ||
Child("Item 2.2"). | ||
Child("Item 2.3"), | ||
). | ||
Child( | ||
tree.New(). | ||
Root("Item 3"). | ||
Child("Item 3.1"). | ||
Child("Item 3.2"), | ||
) | ||
|
||
fmt.Println(t) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/charmbracelet/lipgloss" | ||
"github.com/charmbracelet/lipgloss/tree" | ||
) | ||
|
||
func main() { | ||
purple := lipgloss.NewStyle().Foreground(lipgloss.Color("99")).MarginRight(1) | ||
pink := lipgloss.NewStyle().Foreground(lipgloss.Color("212")).MarginRight(1) | ||
|
||
t := tree.New(). | ||
Child( | ||
"Glossier", | ||
"Claire’s Boutique", | ||
tree.Root("Nyx"). | ||
Child("Lip Gloss", "Foundation"). | ||
EnumeratorStyle(pink), | ||
"Mac", | ||
"Milk", | ||
). | ||
EnumeratorStyle(purple) | ||
fmt.Println(t) | ||
} |
Oops, something went wrong.