Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: charmbracelet/lipgloss
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.11.0
Choose a base ref
...
head repository: charmbracelet/lipgloss
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.11.1
Choose a head ref
  • 11 commits
  • 33 files changed
  • 6 contributors

Commits on May 24, 2024

  1. feat: trees and lists (#264)

    * feat: implement list renderer
    
    * feat: data model for list
    
    * feat: add Offset, Height, Indent
    
    * feat: tree renderer
    
    * fix: list example
    
    * test: last tree node is a subtree
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    * fix: tree
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    * fix: lint
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    * docs: example
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    * test: inc cov
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    * fix: multiline items
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    * feat: one approach to sublists
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    * fix: tree improvements
    
    * wip
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    * wip
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    * wip
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    * wip
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    * fix: prevent having to pass renderer to all trees
    
    * test: force linux line endings
    
    * fix: windows
    
    * fix: lint issues
    
    * fix: ignore lint issue failing forever
    
    * fix: renames
    
    * fix: renderer
    
    * ci: fix coveralls hopefully
    
    * wip
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    * fix: style
    
    * docs: update
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    * fix: renderer
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    * test: cover with tests
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    * feat: more list enumerators
    
    * fix: drop renderer api
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    * feat: improve api
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    * fix: prealloc
    
    * fix: clean up
    
    * fix: list setup
    
    * fix: improve sublist tests
    
    * fix: improve sublists
    
    * refactor: simplify
    
    * docs: more examples, readme updates
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    * docs: readme
    
    * fix: set item style
    
    * fix(tree): do not use golden files
    
    * test: do not use golden files
    
    * refactor: remove unused code
    
    * feat: hide nodes
    
    * feat: filter
    
    * fix: allow fmt.Stringer
    
    * test: table within a tree
    
    * docs: update
    
    * fix: rename atter to data
    
    * test: test public api only
    
    * docs: sublist with table example
    
    * docs: update example
    
    * fix: lint issues
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    * docs: update examples
    
    * docs: update
    
    * feat: offset
    
    * feat: offsetstart && offsetend
    
    * fix: remove last from enumerator
    
    * refactor: make tree more explicit
    
    * `New()` now take no args
    * added a new `Root(string)` method
    * added a new `Items(...any)` method
    
    * refactor: improve list
    
    * docs: fix examples
    
    * test: ensure embed lists in trees
    
    * docs: sublist example with list as tree node
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    * refactor: first pass at examples cleanup
    
    * refactor: first pass at examples cleanup
    
    * fix: support multi-line prefixes
    
    * test: more glow-style lists within trees
    
    * docs: simplify examples
    
    * fix: improve handling of different types
    
    * chore: go mod tidy
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    * fix: code review suggestions
    
    Co-authored-by: Ayman Bagabas <ayman.bagabas@gmail.com>
    Co-authored-by: bashbunni <15822994+bashbunni@users.noreply.github.com>
    
    * fix: apply code review suggestion
    
    * feat(tree): rounded enumerator (#280)
    
    * chore(examples): go mod tidy
    
    * feat(tree): add rounded corner enumerator
    
    * test: rounded enumerator test
    
    * docs: readme updates
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    * docs: readme updates
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    * chore: fmt
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    * docs: godoc
    
    * docs: godoc
    
    * fix: bash's issue
    
    * fix: bad example
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    * docs: improve godoc for trees and lists (#296)
    
    * docs(godoc): add overview
    
    * docs(godoc): include examples in godoc
    
    * docs(godoc): fix roman numerals example
    
    * docs(godoc): fix tree examples
    
    * docs(godoc): attempt to fix list Enumerator examples
    
    * docs: added some examples to godoc
    
    * fix(list): New(items...) with sublist
    
    * docs: update examples
    
    * chore(tree): improve var names in rounded example
    
    * fix: use padding instead of margin to better styles
    
    * fix: lint
    
    ---------
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    Co-authored-by: Maas Lalani <maas@lalani.dev>
    Co-authored-by: Ayman Bagabas <ayman.bagabas@gmail.com>
    Co-authored-by: bashbunni <15822994+bashbunni@users.noreply.github.com>
    Co-authored-by: Christian Rocha <christian@rocha.is>
    5 people authored May 24, 2024
    4
    Copy the full SHA
    d21c576 View commit details

Commits on May 30, 2024

  1. Tree API Changes (#307)

    * refactor: clean tree_test.go
    
    * refactor: remove subtests
    
    * refactor: rename `Data` to `Items` for `Lists` and `Children` for `Trees`
    
    * chore: support only NodeData
    
    * fix: enumerations -> enumerators for consistency
    
    * fix: item -> children
    
    * fix: use l for List, rather than n
    
    * fix: move list Enumerator definition to enumerator.go
    
    * fix: list enumerator comments
    
    * docs: add package documentation
    
    * fix: examples
    
    * feat: split enumerator and indenters
    
    * docs: add comments
    
    * refactor: package comment
    
    * docs: use more tree terminology
    
    * docs: refactor indentor comments
    
    * fix: lint
    maaslalani authored May 30, 2024
    Copy the full SHA
    1afeca0 View commit details
  2. chore: remove deprecated Copy() calls (#306)

    Co-authored-by: Maas Lalani <maas@lalani.dev>
    meowgorithm and maaslalani authored May 30, 2024
    Copy the full SHA
    70c908d View commit details
  3. refactor: use lipgloss copy for example (#308)

    maaslalani authored May 30, 2024
    Copy the full SHA
    6e07abb View commit details

Commits on May 31, 2024

  1. fix: sublist example, minor edits

    maaslalani committed May 31, 2024
    Copy the full SHA
    878d31f View commit details
  2. fix(tree): examples

    meowgorithm committed May 31, 2024
    Copy the full SHA
    e54d9dd View commit details
  3. feat: deprecate Style.ColorWhitespace

    You can get the exact same effect with margins and padding.
    meowgorithm committed May 31, 2024
    Copy the full SHA
    7838b4e View commit details

Commits on Jun 4, 2024

  1. chore(ci): also build examples (#310)

    * chore(ci): also build examples
    * fix(examples): fix tree styles example
    * fix: ssh examples dependencies
    * chore: use creack/pty
    * chore(examples): update deps
    * chore(examples): bump examples (and ci) to 1.19 so a slog dep will build
    
    ---------
    
    Co-authored-by: Ayman Bagabas <ayman.bagabas@gmail.com>
    meowgorithm and aymanbagabas authored Jun 4, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    bbd02ab View commit details

Commits on Jun 8, 2024

  1. fix: Deprecate UnsetBorderTopBackgroundColor in favor of UnsetBorderT…

    …opBackground
    nervo authored and meowgorithm committed Jun 8, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    33b3263 View commit details

Commits on Jun 18, 2024

  1. chore: update CODEOWNERS

    meowgorithm committed Jun 18, 2024
    Copy the full SHA
    5a82e41 View commit details

Commits on Jul 10, 2024

  1. chore: bump x/ansi to v0.1.3

    Fixes: #324
    aymanbagabas committed Jul 10, 2024
    Copy the full SHA
    e6edbac View commit details
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @meowgorithm @muesli
* @meowgorithm @aymanbagabas
8 changes: 7 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -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:
@@ -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 ./...

200 changes: 200 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion color.go
Original file line number Diff line number Diff line change
@@ -20,7 +20,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(*Renderer) termenv.Color {
39 changes: 27 additions & 12 deletions examples/go.mod
Original file line number Diff line number Diff line change
@@ -1,29 +1,44 @@
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/wish v0.5.0
github.com/gliderlabs/ssh v0.3.4
github.com/kr/pty v1.1.1
github.com/charmbracelet/lipgloss v0.11.0
github.com/charmbracelet/ssh v0.0.0-20240401141849-854cddfa2917
github.com/charmbracelet/wish v1.4.0
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/x/ansi v0.1.1 // indirect
github.com/charmbracelet/bubbletea v0.25.0 // indirect
github.com/charmbracelet/keygen v0.5.0 // indirect
github.com/charmbracelet/log v0.4.0 // indirect
github.com/charmbracelet/x/ansi v0.1.3 // indirect
github.com/charmbracelet/x/errors v0.0.0-20240117030013-d31dba354651 // indirect
github.com/charmbracelet/x/exp/term v0.0.0-20240328150354-ab9afc214dfd // indirect
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.14.0 // indirect
)
Loading