Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(readme): minor tree-related readme edits #351

Merged
merged 4 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
66 changes: 37 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -592,18 +592,20 @@ Trees have the ability to nest.

```go
t := tree.Root(".").
Child("Item 1").
Child(
tree.Root("Item 2").
Child("Item 2.1").
Child("Item 2.2").
Child("Item 2.3"),
).
Child(
tree.Root("Item 3").
Child("Item 3.1").
Child("Item 3.2"),
)
Child("macOS").
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads up the alignment in the lists section is two spaces instead of tabs, so we should update the indentation to match

Copy link
Member Author

@meowgorithm meowgorithm Aug 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. The rest of the readme uses four spaces for tabs so I normalized the list section to four spaces instead.

Child(
tree.New().
Root("Linux").
Child("NixOS").
Child("Arch Linux (btw)").
Child("Void Linux"),
).
Child(
tree.New().
Root("BSD").
Child("FreeBSD").
Child("OpenBSD"),
)
```

Print the tree.
Expand All @@ -613,34 +615,40 @@ fmt.Println(t)
```

<p align="center">
<img width="400" alt="Tree Example (simple)" src="https://stuff.charm.sh/lipgloss/tree/simple.png">
<img width="445" alt="Tree Example (simple)" src="https://github.com/user-attachments/assets/dc97a490-9550-4deb-a075-6987007b3307">
</p>

Trees can be customized via their enumeration function as well as using
`lipgloss.Style`s.

```go
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")))
enumeratorStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("63")).MarginRight(1)
rootStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("35"))
itemStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("212"))

t := tree.
Root("⁜ Makeup").
Child(
"Glossier",
"Fenty Beauty",
tree.New().Child(
"Gloss Bomb Universal Lip Luminizer",
"Hot Cheeks Velour Blushlighter",
),
"Nyx",
"Mac",
"Milk",
).
Enumerator(tree.RoundedEnumerator).
EnumeratorStyle(enumeratorStyle).
RootStyle(rootStyle).
ItemStyle(itemStyle)
```

Print the tree.

<p align="center">
<img width="600" alt="Tree Example (makeup)" src="https://stuff.charm.sh/lipgloss/tree/makeup.png">
<img width="502" alt="Tree Example (makeup)" src="https://github.com/user-attachments/assets/68681258-d771-408f-8101-b50e97329130">
</p>

The predefined enumerators for trees are `DefaultEnumerator` and `RoundedEnumerator`.
Expand Down
17 changes: 11 additions & 6 deletions examples/tree/makeup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,27 @@ import (
)

func main() {
enumeratorStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("99")).MarginRight(1)
itemStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("212")).MarginRight(1)
enumeratorStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("63")).MarginRight(1)
rootStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("35"))
itemStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("212"))

t := tree.
Root("Makeup").
Root("Makeup").
Child(
"Glossier",
"Claire’s Boutique",
"Fenty Beauty",
tree.New().Child(
"Gloss Bomb Universal Lip Luminizer",
"Hot Cheeks Velour Blushlighter",
),
"Nyx",
"Mac",
"Milk",
).
Enumerator(tree.RoundedEnumerator).
EnumeratorStyle(enumeratorStyle).
ItemStyle(itemStyle).
RootStyle(lipgloss.NewStyle().Foreground(lipgloss.Color("#04B575")))
RootStyle(rootStyle).
ItemStyle(itemStyle)

fmt.Println(t)
}
16 changes: 8 additions & 8 deletions examples/tree/simple/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ import (

func main() {
t := tree.Root(".").
Child("Item 1").
Child("macOS").
Child(
tree.New().
Root("Item 2").
Child("Item 2.1").
Child("Item 2.2").
Child("Item 2.3"),
Root("Linux").
Child("NixOS").
Child("Arch Linux (btw)").
Child("Void Linux"),
).
Child(
tree.New().
Root("Item 3").
Child("Item 3.1").
Child("Item 3.2"),
Root("BSD").
Child("FreeBSD").
Child("OpenBSD"),
)

fmt.Println(t)
Expand Down
2 changes: 1 addition & 1 deletion examples/tree/toggle/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (s file) String() string {
func main() {
s := defaultStyles()

t := tree.Root(dir{"~", true, s}).
t := tree.Root(dir{"~/charm", true, s}).
Enumerator(tree.RoundedEnumerator).
EnumeratorStyle(s.enumerator).
Child(
Expand Down
Loading