Skip to content

Commit 067bbef

Browse files
committed
chore: merge branch 'master' into v2-exp
2 parents 634dfe4 + ca67d0f commit 067bbef

File tree

7 files changed

+265
-23
lines changed

7 files changed

+265
-23
lines changed

β€Ž.github/dependabot.ymlβ€Ž

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,52 @@
11
version: 2
2+
23
updates:
34
- package-ecosystem: "gomod"
45
directory: "/"
56
schedule:
6-
interval: "daily"
7+
interval: "weekly"
8+
day: "monday"
9+
time: "05:00"
10+
timezone: "America/New_York"
711
labels:
812
- "dependencies"
913
commit-message:
10-
prefix: "feat"
14+
prefix: "chore"
1115
include: "scope"
12-
- package-ecosystem: "gomod"
13-
directory: "/example"
16+
17+
- package-ecosystem: "github-actions"
18+
directory: "/"
1419
schedule:
15-
interval: "daily"
20+
interval: "weekly"
21+
day: "monday"
22+
time: "05:00"
23+
timezone: "America/New_York"
1624
labels:
1725
- "dependencies"
1826
commit-message:
1927
prefix: "chore"
2028
include: "scope"
21-
- package-ecosystem: "github-actions"
29+
30+
- package-ecosystem: "docker"
2231
directory: "/"
2332
schedule:
24-
interval: "daily"
33+
interval: "weekly"
34+
day: "monday"
35+
time: "05:00"
36+
timezone: "America/New_York"
37+
labels:
38+
- "dependencies"
39+
commit-message:
40+
prefix: "feat"
41+
include: "scope"
42+
43+
- package-ecosystem: "gomod"
44+
directory: "/example"
45+
schedule:
46+
interval: "weekly"
47+
day: "monday"
48+
time: "05:00"
49+
timezone: "America/New_York"
2550
labels:
2651
- "dependencies"
2752
commit-message:
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: dependabot-sync
2+
on:
3+
schedule:
4+
- cron: "0 0 * * 0" # every Sunday at midnight
5+
workflow_dispatch: # allows manual triggering
6+
7+
permissions:
8+
contents: write
9+
pull-requests: write
10+
11+
jobs:
12+
dependabot-sync:
13+
uses: charmbracelet/meta/.github/workflows/dependabot-sync.yml@main
14+
with:
15+
repo_name: ${{ github.event.repository.name }}
16+
secrets:
17+
gh_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

β€ŽREADME.mdβ€Ž

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -425,17 +425,28 @@ rows := [][]string{
425425
Use the table package to style and render the table.
426426

427427
```go
428+
var (
429+
purple = lipgloss.Color("99")
430+
gray = lipgloss.Color("245")
431+
lightGray = lipgloss.Color("241")
432+
433+
headerStyle = lipgloss.NewStyle().Foreground(purple).Bold(true).Align(lipgloss.Center)
434+
cellStyle = lipgloss.NewStyle().Padding(0, 1).Width(14)
435+
oddRowStyle = cellStyle.Foreground(gray)
436+
evenRowStyle = cellStyle.Foreground(lightGray)
437+
)
438+
428439
t := table.New().
429440
Border(lipgloss.NormalBorder()).
430-
BorderStyle(lipgloss.NewStyle().Foreground(lipgloss.Color("99"))).
441+
BorderStyle(lipgloss.NewStyle().Foreground(purple)).
431442
StyleFunc(func(row, col int) lipgloss.Style {
432443
switch {
433-
case row == 0:
434-
return HeaderStyle
444+
case row == table.HeaderRow:
445+
return headerStyle
435446
case row%2 == 0:
436-
return EvenRowStyle
447+
return evenRowStyle
437448
default:
438-
return OddRowStyle
449+
return oddRowStyle
439450
}
440451
}).
441452
Headers("LANGUAGE", "FORMAL", "INFORMAL").

β€Žstyle.goβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ func (s Style) Render(strs ...string) string {
419419
{
420420
numLines := strings.Count(str, "\n")
421421

422-
if !(numLines == 0 && width == 0) {
422+
if numLines != 0 || width != 0 {
423423
var st *ansi.Style
424424
if colorWhitespace || styleWhitespace {
425425
st = &teWhitespace

β€Žtree/example_test.goβ€Ž

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
package tree_test
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/charmbracelet/lipgloss/tree"
7+
"github.com/charmbracelet/x/ansi"
8+
)
9+
10+
// Leaf Examples
11+
12+
func ExampleLeaf_SetHidden() {
13+
tr := tree.New().
14+
Child(
15+
"Foo",
16+
tree.Root("Bar").
17+
Child(
18+
"Qux",
19+
tree.Root("Quux").
20+
Child("Hello!"),
21+
"Quuux",
22+
),
23+
"Baz",
24+
)
25+
26+
tr.Children().At(1).Children().At(2).SetHidden(true)
27+
fmt.Println(tr.String())
28+
// Output:
29+
//
30+
// β”œβ”€β”€ Foo
31+
// β”œβ”€β”€ Bar
32+
// β”‚ β”œβ”€β”€ Qux
33+
// β”‚ └── Quux
34+
// β”‚ └── Hello!
35+
// └── Baz
36+
//
37+
}
38+
39+
func ExampleNewLeaf() {
40+
tr := tree.New().
41+
Child(
42+
"Foo",
43+
tree.Root("Bar").
44+
Child(
45+
"Qux",
46+
tree.Root("Quux").
47+
Child(
48+
tree.NewLeaf("This should be hidden", true),
49+
tree.NewLeaf(
50+
tree.Root("I am groot").Child("leaves"), false),
51+
),
52+
"Quuux",
53+
),
54+
"Baz",
55+
)
56+
57+
fmt.Println(tr.String())
58+
// Output:
59+
// β”œβ”€β”€ Foo
60+
// β”œβ”€β”€ Bar
61+
// β”‚ β”œβ”€β”€ Qux
62+
// β”‚ β”œβ”€β”€ Quux
63+
// β”‚ β”‚ └── I am groot
64+
// β”‚ β”‚ └── leaves
65+
// β”‚ └── Quuux
66+
// └── Baz
67+
//
68+
}
69+
70+
func ExampleLeaf_SetValue() {
71+
t := tree.
72+
Root("⁜ Makeup").
73+
Child(
74+
"Glossier",
75+
"Fenty Beauty",
76+
tree.New().Child(
77+
"Gloss Bomb Universal Lip Luminizer",
78+
"Hot Cheeks Velour Blushlighter",
79+
),
80+
"Nyx",
81+
"Mac",
82+
"Milk",
83+
).
84+
Enumerator(tree.RoundedEnumerator)
85+
glossier := t.Children().At(0)
86+
glossier.SetValue("Il Makiage")
87+
fmt.Println(ansi.Strip(t.String()))
88+
// Output:
89+
//⁜ Makeup
90+
//β”œβ”€β”€ Il Makiage
91+
//β”œβ”€β”€ Fenty Beauty
92+
//β”‚ β”œβ”€β”€ Gloss Bomb Universal Lip Luminizer
93+
//β”‚ ╰── Hot Cheeks Velour Blushlighter
94+
//β”œβ”€β”€ Nyx
95+
//β”œβ”€β”€ Mac
96+
//╰── Milk
97+
}
98+
99+
// Tree Examples
100+
101+
func ExampleTree_Hide() {
102+
tr := tree.New().
103+
Child(
104+
"Foo",
105+
tree.Root("Bar").
106+
Child(
107+
"Qux",
108+
tree.Root("Quux").
109+
Child("Foo", "Bar").
110+
Hide(true),
111+
"Quuux",
112+
),
113+
"Baz",
114+
)
115+
116+
fmt.Println(tr.String())
117+
// Output:
118+
// β”œβ”€β”€ Foo
119+
// β”œβ”€β”€ Bar
120+
// β”‚ β”œβ”€β”€ Qux
121+
// β”‚ └── Quuux
122+
// └── Baz
123+
}
124+
125+
func ExampleTree_SetHidden() {
126+
tr := tree.New().
127+
Child(
128+
"Foo",
129+
tree.Root("Bar").
130+
Child(
131+
"Qux",
132+
tree.Root("Quux").
133+
Child("Foo", "Bar"),
134+
"Quuux",
135+
),
136+
"Baz",
137+
)
138+
139+
// Hide a tree after its creation. We'll hide Quux.
140+
tr.Children().At(1).Children().At(1).SetHidden(true)
141+
// Output:
142+
// β”œβ”€β”€ Foo
143+
// β”œβ”€β”€ Bar
144+
// β”‚ β”œβ”€β”€ Qux
145+
// β”‚ └── Quuux
146+
// └── Baz
147+
//
148+
fmt.Println(tr.String())
149+
}

β€Žtree/renderer.goβ€Ž

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ func (r *renderer) render(node Node, root bool, prefix string) string {
5555
}
5656

5757
for i := 0; i < children.Length(); i++ {
58+
if i < children.Length()-1 {
59+
if child := children.At(i + 1); child.Hidden() {
60+
// Don't count the last child if its hidden. This renders the
61+
// last visible element with the right prefix
62+
//
63+
// The only type of Children is NodeChildren.
64+
children = children.(NodeChildren).Remove(i + 1)
65+
}
66+
}
5867
prefix := enumerator(children, i)
5968
prefix = r.style.enumeratorFunc(children, i).Render(prefix)
6069
maxLen = max(lipgloss.Width(prefix), maxLen)

0 commit comments

Comments
Β (0)