Skip to content

Commit

Permalink
Merge branch 'master' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Jun 5, 2024
2 parents 972c013 + bbd02ab commit a724723
Show file tree
Hide file tree
Showing 33 changed files with 3,217 additions and 150 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jobs:
test:
strategy:
matrix:
go-version: [~1.18, ^1]
go-version: [~1.19, ^1]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
env:
Expand All @@ -24,6 +24,12 @@ jobs:
- name: Build
run: go build -v ./...

- name: Build examples
run: |
go mod tidy
go build -v ./...
working-directory: ./examples

- name: Test
run: go test ./...

Expand Down
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ linters:
enable:
- bodyclose
- exportloopref
- gofumpt
- goimports
- gosec
- nilerr
Expand Down
200 changes: 200 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,206 @@ fmt.Println(t)

For more on tables see [the docs](https://pkg.go.dev/github.com/charmbracelet/lipgloss?tab=doc) and [examples](https://github.com/charmbracelet/lipgloss/tree/master/examples/table).

## Rendering Trees

Lip Gloss ships with a tree rendering sub-package.

```go
import "github.com/charmbracelet/lipgloss/tree"
```

Define a new tree.

```go
t := tree.New("root", "child 1", "child 2", tree.New("child 3", "child 3.1"))
```

Print the tree.

```go
fmt.Println(t)

// root
// ├── child 1
// ├── child 2
// └── child 3
// └── child 3.1
```

### Customization

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

```go
style1 := lipgloss.NewStyle().Foreground(lipgloss.Color("99")).MarginRight(1)
style2 := lipgloss.NewStyle().Foreground(lipgloss.Color("10")).MarginRight(1)

t := tree.New().
Items(
"Glossier",
"Claire’s Boutique",
tree.New().
Root("Nyx").
Items("Qux", "Quux").
EnumeratorStyle(style2),
"Mac",
"Milk",
).
EnumeratorStyle(style1)
```

Print the tree:

<p align="center">
<img
width="600"
alt="Tree example"
src="https://github.com/charmbracelet/lipgloss/assets/245435/5a875269-f6d6-43fa-9916-5d8360e66964"
/>
</p>
You may also define custom enumerator implementations:

```go
t := tree.New().
Items(
"Glossier",
"Claire’s Boutique",
tree.New().
Root("Nyx").
Items(
"Qux",
"Quux",
),
"Mac",
"Milk",
).
Enumerator(func(tree.Data, int) (string, string) {
return "->", "->"
})
```

Print the tree.

<p align="center">
<img
width="600"
alt="Tree example"
src="https://github.com/charmbracelet/lipgloss/assets/245435/811e8b39-124f-48bb-b3dd-e015a65b1065"
/>
</p>

### Building

If you need, you can also build trees incrementally:

```go
t := tree.New("")

for i := 0; i < repeat; i++ {
t.Item("Lip Gloss")
}
```


## Rendering Lists

Lip Gloss ships with a list rendering sub-package.
Implementation-wise, lists are still trees.
The `list` package provides many common `Enumerator` implementations, as well as
some syntactic sugar.

```go
import "github.com/charmbracelet/lipgloss/list"
```

Define a new list.

```go
l := list.New("A", "B", "C")
```

Print the list.

```go
fmt.Println(l)

// • A
// • B
// • C
```


### Customization

Lists 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("10")).MarginRight(1)

l := list.New(
"Glossier",
"Claire’s Boutique",
"Nyx",
"Mac",
"Milk",
).
Enumerator(list.Roman).
EnumeratorStyle(enumeratorStyle).
ItemStyle(itemStyle)
```

Print the list.

<p align="center">
<img
width="600"
alt="List example"
src="https://github.com/charmbracelet/lipgloss/assets/245435/8f5e5e0b-7bf9-4e3b-a8ba-3af10825320e"
/>
</p>
In addition to the predefined enumerators (`Arabic`, `Alphabet`, `Roman`, `Bullet`, `Tree`),
you may also define your own custom enumerator:

```go
var DuckDuckGooseEnumerator Enumerator = func(l *List, i int) string {
if l.At(i) == "Goose" {
return "Honk →"
}
return ""
}
```

Use it in a list:

```go
l := list.New("Duck", "Duck", "Duck", "Duck", "Goose", "Duck", "Duck")
l.Enumerator(DuckDuckGooseEnumerator)
```

Print the list:

<p align="center">
<img
width="600"
alt="image"
src="https://github.com/charmbracelet/lipgloss/assets/245435/44e37a5b-5124-4f49-a332-1756a355002e"
/>
</p>

### Building

If you need, you can also build trees incrementally:

```go
l := list.New()

for i := 0; i < repeat; i++ {
l.Item("Lip Gloss")
}
```
---

## FAQ
Expand Down
2 changes: 1 addition & 1 deletion color.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var noColor = NoColor{}
//
// Example usage:
//
// var style = someStyle.Copy().Background(lipgloss.NoColor{})
// var style = someStyle.Background(lipgloss.NoColor{})
type NoColor struct{}

func (NoColor) color(Profile, bool) ansi.Color {
Expand Down
29 changes: 18 additions & 11 deletions examples/go.mod
Original file line number Diff line number Diff line change
@@ -1,36 +1,43 @@
module examples

go 1.17
go 1.19

replace github.com/charmbracelet/lipgloss => ../

replace github.com/charmbracelet/lipgloss/tree => ../tree

replace github.com/charmbracelet/lipgloss/list => ../list

require (
github.com/charmbracelet/lipgloss v0.4.0
github.com/charmbracelet/lipgloss v0.10.0
github.com/charmbracelet/ssh v0.0.0-20240604154955-a40c6a0d028f
github.com/charmbracelet/wish v0.5.0
github.com/charmbracelet/x/exp/term v0.0.0-20240515162549-69ee4f765313
github.com/gliderlabs/ssh v0.3.4
github.com/kr/pty v1.1.1
github.com/creack/pty v1.1.21
github.com/lucasb-eyer/go-colorful v1.2.0
github.com/muesli/termenv v0.15.2
golang.org/x/term v0.15.0
golang.org/x/term v0.21.0
)

require (
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/caarlos0/sshmarshal v0.1.0 // indirect
github.com/charmbracelet/keygen v0.3.0 // indirect
github.com/charmbracelet/keygen v0.5.0 // indirect
github.com/charmbracelet/x/ansi v0.1.1 // indirect
github.com/charmbracelet/x/conpty v0.1.0 // indirect
github.com/charmbracelet/x/errors v0.0.0-20240508181413-e8d8b6e2de86 // indirect
github.com/charmbracelet/x/input v0.1.0 // indirect
github.com/charmbracelet/x/term v0.1.1 // indirect
github.com/charmbracelet/x/termios v0.1.0 // indirect
github.com/charmbracelet/x/windows v0.1.0 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/gliderlabs/ssh v0.3.4 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/crypto v0.0.0-20220307211146-efcb8507fb70 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/sys v0.21.0 // indirect
)
Loading

0 comments on commit a724723

Please sign in to comment.