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.1
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.12.0
Choose a head ref
  • 3 commits
  • 18 files changed
  • 2 contributors

Commits on Jul 10, 2024

  1. feat(ci): use goreleaser for releases (#301)

    * feat(ci): use goreleaser for releases
    
    This will publish and announce releases on tag push.
    
    * chore: remove announce
    aymanbagabas authored Jul 10, 2024

    Verified

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

Commits on Jul 11, 2024

  1. Drop Tree (#330)

    * fix: move tree to internal
    
    * feat: tree indenter on lists
    
    * fix: sublist example
    
    * fix: remove tree
    maaslalani authored Jul 11, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    2a67670 View commit details
  2. docs: list documentation (#331)

    maaslalani authored Jul 11, 2024
    Copy the full SHA
    6348d59 View commit details
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: goreleaser

on:
push:
tags:
- v*.*.*

concurrency:
group: goreleaser
cancel-in-progress: true

jobs:
goreleaser:
uses: charmbracelet/meta/.github/workflows/goreleaser.yml@main
secrets:
docker_username: ${{ secrets.DOCKERHUB_USERNAME }}
docker_token: ${{ secrets.DOCKERHUB_TOKEN }}
gh_pat: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
goreleaser_key: ${{ secrets.GORELEASER_KEY }}
twitter_consumer_key: ${{ secrets.TWITTER_CONSUMER_KEY }}
twitter_consumer_secret: ${{ secrets.TWITTER_CONSUMER_SECRET }}
twitter_access_token: ${{ secrets.TWITTER_ACCESS_TOKEN }}
twitter_access_token_secret: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }}
mastodon_client_id: ${{ secrets.MASTODON_CLIENT_ID }}
mastodon_client_secret: ${{ secrets.MASTODON_CLIENT_SECRET }}
mastodon_access_token: ${{ secrets.MASTODON_ACCESS_TOKEN }}
discord_webhook_id: ${{ secrets.DISCORD_WEBHOOK_ID }}
discord_webhook_token: ${{ secrets.DISCORD_WEBHOOK_TOKEN }}
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
5 changes: 5 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
includes:
- from_url:
url: charmbracelet/meta/main/goreleaser-lib.yaml
# yaml-language-server: $schema=https://goreleaser.com/static/schema-pro.json

187 changes: 47 additions & 140 deletions README.md
Original file line number Diff line number Diff line change
@@ -455,114 +455,9 @@ 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"
@@ -584,77 +479,89 @@ fmt.Println(l)
// β€’ C
```

Lists have the ability to nest.

```go
l := list.New(
"A", list.New("Artichoke"),
"B", list.New("Baking Flour", "Bananas", "Barley", "Bean Sprouts"),
"C", list.New("Cashew Apple", "Cashews", "Coconut Milk", "Curry Paste", "Currywurst"),
"D", list.New("Dill", "Dragonfruit", "Dried Shrimp"),
"E", list.New("Eggs"),
"F", list.New("Fish Cake", "Furikake"),
"J", list.New("Jicama"),
"K", list.New("Kohlrabi"),
"L", list.New("Leeks", "Lentils", "Licorice Root"),
)
```

Print the list.

```go
fmt.Println(l)
```

### Customization
<p align="center">
<img width="600" alt="image" src="https://github.com/charmbracelet/lipgloss/assets/42545625/0dc9f440-0748-4151-a3b0-7dcf29dfcdb0">
</p>

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)
itemStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("212")).MarginRight(1)

l := list.New(
"Glossier",
"Claire’s Boutique",
"Nyx",
"Mac",
"Milk",
"Glossier",
"Claire’s Boutique",
"Nyx",
"Mac",
"Milk",
).
Enumerator(list.Roman).
EnumeratorStyle(enumeratorStyle).
ItemStyle(itemStyle)
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"
/>
<img width="600" alt="List example" src="https://github.com/charmbracelet/lipgloss/assets/42545625/360494f1-57fb-4e13-bc19-0006efe01561">
</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 ""
}
```
l := list.New("Duck", "Duck", "Duck", "Duck", "Goose", "Duck", "Duck")

Use it in a list:
func DuckDuckGooseEnumerator(l list.Items, i int) string {
if l.At(i).Value() == "Goose" {
return "Honk β†’"
}
return ""
}

```go
l := list.New("Duck", "Duck", "Duck", "Duck", "Goose", "Duck", "Duck")
l.Enumerator(DuckDuckGooseEnumerator)
l = 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"
/>
<img width="600" alt="image" src="https://github.com/charmbracelet/lipgloss/assets/42545625/157aaf30-140d-4948-9bb4-dfba46e5b87e">
</p>

### Building

If you need, you can also build trees incrementally:
If you need, you can also build lists incrementally:

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

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

---

## FAQ
2 changes: 0 additions & 2 deletions examples/go.mod
Original file line number Diff line number Diff line change
@@ -4,8 +4,6 @@ go 1.19

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

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

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

require (
29 changes: 14 additions & 15 deletions examples/list/sublist/main.go
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@ import (
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/lipgloss/list"
"github.com/charmbracelet/lipgloss/table"
"github.com/charmbracelet/lipgloss/tree"
"github.com/lucasb-eyer/go-colorful"
)

@@ -119,16 +118,16 @@ func main() {
Item("Lip Gloss").
Item("Lip Gloss").
Item(
tree.New().
list.New().
EnumeratorStyle(lipgloss.NewStyle().Foreground(lipgloss.Color(colors[4][0])).MarginRight(1)).
Child("\nStyle Definitions for Nice Terminal Layouts\n─────").
Child("From Charm").
Child("https://github.com/charmbracelet/lipgloss").
Child(
tree.New().
Item("\nStyle Definitions for Nice Terminal Layouts\n─────").
Item("From Charm").
Item("https://github.com/charmbracelet/lipgloss").
Item(
list.New().
EnumeratorStyle(lipgloss.NewStyle().Foreground(lipgloss.Color(colors[3][0])).MarginRight(1)).
Child("Emperors: Julio-Claudian dynasty").
Child(
Item("Emperors: Julio-Claudian dynasty").
Item(
lipgloss.NewStyle().Padding(1).Render(
list.New(
"Augustus",
@@ -139,7 +138,7 @@ func main() {
).Enumerator(list.Roman).String(),
),
).
Child(
Item(
lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.Color("#FAFAFA")).
@@ -151,7 +150,7 @@ func main() {
Width(40).
Render(history),
).
Child(
Item(
table.New().
Width(30).
BorderStyle(purple.MarginRight(0)).
@@ -174,8 +173,8 @@ func main() {
Row("Orange", "2").
Row("Strawberry", "12"),
).
Child("Documents").
Child(
Item("Documents").
Item(
list.New().
Enumerator(func(_ list.Items, i int) string {
if i == 1 {
@@ -200,9 +199,9 @@ func main() {
Item("Baz Document\n" + faint.Render("10 minutes ago")).
Item("Qux Document\n" + faint.Render("1 month ago")),
).
Child("EOF"),
Item("EOF"),
).
Child("go get github.com/charmbracelet/lipgloss/list\n"),
Item("go get github.com/charmbracelet/lipgloss/list\n"),
).
Item("See ya later"),
),
Loading