Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into tree-final
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 committed May 13, 2024
2 parents 2889c21 + e3596ae commit c7bab34
Show file tree
Hide file tree
Showing 17 changed files with 448 additions and 199 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,22 @@ jobs:

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

test-goos:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
cache: true
# https://go.dev/doc/install/source#environment
- run: GOOS=darwin GOARCH=amd64 go test -c -v ./...
- run: GOOS=darwin GOARCH=arm64 go test -c -v ./...
- run: GOOS=linux GOARCH=386 go test -c -v ./...
- run: GOOS=linux GOARCH=amd64 go test -c -v ./...
- run: GOOS=linux GOARCH=arm go test -c -v ./...
- run: GOOS=linux GOARCH=arm64 go test -c -v ./...
- run: GOOS=windows GOARCH=amd64 go test -c -v ./...
- run: GOOS=windows GOARCH=386 go test -c -v ./...
- run: GOOS=windows GOARCH=arm go test -c -v ./...
- run: GOOS=windows GOARCH=arm64 go test -c -v ./...
2 changes: 1 addition & 1 deletion .github/workflows/lint-soft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:

- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
uses: golangci/golangci-lint-action@v5
with:
# Optional: golangci-lint command line arguments.
args: --config .golangci-soft.yml --issues-exit-code=0
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:

- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
uses: golangci/golangci-lint-action@v5
with:
# Optional: golangci-lint command line arguments.
#args:
Expand Down
1 change: 0 additions & 1 deletion .golangci-soft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ linters:
- gomnd
- gomoddirectives
- goprintffuncname
- ifshort
# - lll
- misspell
- nakedret
Expand Down
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<a href="https://pkg.go.dev/github.com/charmbracelet/lipgloss?tab=doc"><img src="https://godoc.org/github.com/golang/gddo?status.svg" alt="GoDoc"></a>
<a href="https://github.com/charmbracelet/lipgloss/actions"><img src="https://github.com/charmbracelet/lipgloss/workflows/build/badge.svg" alt="Build Status"></a>
<a href="https://www.phorm.ai/query?projectId=a0e324b6-b706-4546-b951-6671ea60c13f"><img src="https://stuff.charm.sh/misc/phorm-badge.svg" alt="phorm.ai"></a>

</p>
Style definitions for nice terminal layouts. Built with TUIs in mind.

Expand Down Expand Up @@ -224,17 +223,20 @@ For more on borders see [the docs][docs].

## Copying Styles

Just use `Copy()`:
Just use assignment:

```go
var style = lipgloss.NewStyle().Foreground(lipgloss.Color("219"))
style := lipgloss.NewStyle().Foreground(lipgloss.Color("219"))

copiedStyle := style // this is a true copy

wildStyle := style.Blink(true) // this is also true copy, with blink added

var wildStyle = style.Copy().Blink(true)
```

`Copy()` performs a copy on the underlying data structure ensuring that you get
a true, dereferenced copy of a style. Without copying, it's possible to mutate
styles.
Since `Style` data structures contains only primitive types, assigning a style
to another effectively creates a new copy of the style without mutating the
original.

## Inheritance

Expand Down Expand Up @@ -652,6 +654,7 @@ Print the list:
src="https://github.com/charmbracelet/lipgloss/assets/245435/44e37a5b-5124-4f49-a332-1756a355002e"
/>
</p>

---

## FAQ
Expand Down Expand Up @@ -700,6 +703,7 @@ import (
)

lipgloss.SetColorProfile(termenv.TrueColor)

```

_Note_: this option limits the flexibility of your application and can cause
Expand Down Expand Up @@ -761,3 +765,4 @@ Charm热爱开源 • Charm loves open source
[docs]: https://pkg.go.dev/github.com/charmbracelet/lipgloss?tab=doc
[wish]: https://github.com/charmbracelet/wish
[ssh-example]: examples/ssh
```
2 changes: 1 addition & 1 deletion examples/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
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/exp/term v0.0.0-20240408110044-525ba71bb562 // indirect
github.com/charmbracelet/x/exp/term v0.0.0-20240425164147-ba2a9512b05f // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions examples/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ github.com/charmbracelet/keygen v0.3.0 h1:mXpsQcH7DDlST5TddmXNXjS0L7ECk4/kLQYyBc
github.com/charmbracelet/keygen v0.3.0/go.mod h1:1ukgO8806O25lUZ5s0IrNur+RlwTBERlezdgW71F5rM=
github.com/charmbracelet/wish v0.5.0 h1:FkkdNBFqrLABR1ciNrAL2KCxoyWfKhXnIGZw6GfAtPg=
github.com/charmbracelet/wish v0.5.0/go.mod h1:5GAn5SrDSZ7cgKjnC+3kDmiIo7I6k4/AYiRzC4+tpCk=
github.com/charmbracelet/x/exp/term v0.0.0-20240408110044-525ba71bb562 h1:jCSNgVpyc16IspmSdrUTio2lY33YojCN4tKOyQxWIg4=
github.com/charmbracelet/x/exp/term v0.0.0-20240408110044-525ba71bb562/go.mod h1:yQqGHmheaQfkqiJWjklPHVAq1dKbk8uGbcoS/lcKCJ0=
github.com/charmbracelet/x/exp/term v0.0.0-20240425164147-ba2a9512b05f h1:1BXkZqDueTOBECyDoFGRi0xMYgjJ6vvoPIkWyKOwzTc=
github.com/charmbracelet/x/exp/term v0.0.0-20240425164147-ba2a9512b05f/go.mod h1:yQqGHmheaQfkqiJWjklPHVAq1dKbk8uGbcoS/lcKCJ0=
github.com/gliderlabs/ssh v0.3.4 h1:+AXBtim7MTKaLVPgvE+3mhewYRawNLTd+jEEz/wExZw=
github.com/gliderlabs/ssh v0.3.4/go.mod h1:ZSS+CUoKHDrqVakTfTWUlKSr9MtMFkC4UvtQKD7O914=
github.com/kr/pty v1.1.1 h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw=
Expand Down
22 changes: 11 additions & 11 deletions examples/layout/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ var (
BorderForeground(highlight).
Padding(0, 1)

activeTab = tab.Copy().Border(activeTabBorder, true)
activeTab = tab.Border(activeTabBorder, true)

tabGap = tab.Copy().
tabGap = tab.
BorderTop(false).
BorderLeft(false).
BorderRight(false)
Expand Down Expand Up @@ -109,7 +109,7 @@ var (
Padding(0, 3).
MarginTop(1)

activeButtonStyle = buttonStyle.Copy().
activeButtonStyle = buttonStyle.
Foreground(lipgloss.Color("#FFF7DB")).
Background(lipgloss.Color("#F25D94")).
MarginRight(2).
Expand Down Expand Up @@ -173,13 +173,13 @@ var (
Padding(0, 1).
MarginRight(1)

encodingStyle = statusNugget.Copy().
encodingStyle = statusNugget.
Background(lipgloss.Color("#A550DF")).
Align(lipgloss.Right)

statusText = lipgloss.NewStyle().Inherit(statusBarStyle)

fishCakeStyle = statusNugget.Copy().Background(lipgloss.Color("#6124DF"))
fishCakeStyle = statusNugget.Background(lipgloss.Color("#6124DF"))

// Page.

Expand Down Expand Up @@ -215,7 +215,7 @@ func main() {
for i, v := range colors {
const offset = 2
c := lipgloss.Color(v[0])
fmt.Fprint(&title, titleStyle.Copy().MarginLeft(i*offset).Background(c))
fmt.Fprint(&title, titleStyle.MarginLeft(i*offset).Background(c))
if i < len(colors)-1 {
title.WriteRune('\n')
}
Expand Down Expand Up @@ -276,7 +276,7 @@ func main() {
listItem("Pomelo"),
),
),
list.Copy().Width(columnWidth).Render(
list.Width(columnWidth).Render(
lipgloss.JoinVertical(lipgloss.Left,
listHeader("Actual Lip Gloss Vendors"),
listItem("Glossier"),
Expand All @@ -300,9 +300,9 @@ func main() {

doc.WriteString(lipgloss.JoinHorizontal(
lipgloss.Top,
historyStyle.Copy().Align(lipgloss.Right).Render(historyA),
historyStyle.Copy().Align(lipgloss.Center).Render(historyB),
historyStyle.Copy().MarginRight(0).Render(historyC),
historyStyle.Align(lipgloss.Right).Render(historyA),
historyStyle.Align(lipgloss.Center).Render(historyB),
historyStyle.MarginRight(0).Render(historyC),
))

doc.WriteString("\n\n")
Expand All @@ -315,7 +315,7 @@ func main() {
statusKey := statusStyle.Render("STATUS")
encoding := encodingStyle.Render("UTF-8")
fishCake := fishCakeStyle.Render("🍥 Fish Cake")
statusVal := statusText.Copy().
statusVal := statusText.
Width(width - w(statusKey) - w(encoding) - w(fishCake)).
Render("Ravishing")

Expand Down
2 changes: 1 addition & 1 deletion examples/ssh/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func handler(next ssh.Handler) ssh.Handler {
styles.gray,
)

fmt.Fprintf(&str, "%s %t %s\n\n", styles.bold.Copy().UnsetString().Render("Has dark background?"),
fmt.Fprintf(&str, "%s %t %s\n\n", styles.bold.UnsetString().Render("Has dark background?"),
renderer.HasDarkBackground(),
renderer.Output().BackgroundColor())

Expand Down
8 changes: 4 additions & 4 deletions examples/table/languages/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ func main() {
// CellStyle is the base lipgloss style used for the table rows.
CellStyle = re.NewStyle().Padding(0, 1).Width(14)
// OddRowStyle is the lipgloss style used for odd-numbered table rows.
OddRowStyle = CellStyle.Copy().Foreground(gray)
OddRowStyle = CellStyle.Foreground(gray)
// EvenRowStyle is the lipgloss style used for even-numbered table rows.
EvenRowStyle = CellStyle.Copy().Foreground(lightGray)
EvenRowStyle = CellStyle.Foreground(lightGray)
// BorderStyle is the lipgloss style used for the table border.
BorderStyle = lipgloss.NewStyle().Foreground(purple)
)
Expand Down Expand Up @@ -55,12 +55,12 @@ func main() {

// Make the second column a little wider.
if col == 1 {
style = style.Copy().Width(22)
style = style.Width(22)
}

// Arabic is a right-to-left language, so right align the text.
if row < len(rows) && rows[row-1][0] == "Arabic" && col != 0 {
style = style.Copy().Align(lipgloss.Right)
style = style.Align(lipgloss.Right)
}

return style
Expand Down
10 changes: 5 additions & 5 deletions examples/table/pokemon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
func main() {
re := lipgloss.NewRenderer(os.Stdout)
baseStyle := re.NewStyle().Padding(0, 1)
headerStyle := baseStyle.Copy().Foreground(lipgloss.Color("252")).Bold(true)
selectedStyle := baseStyle.Copy().Foreground(lipgloss.Color("#01BE85")).Background(lipgloss.Color("#00432F"))
headerStyle := baseStyle.Foreground(lipgloss.Color("252")).Bold(true)
selectedStyle := baseStyle.Foreground(lipgloss.Color("#01BE85")).Background(lipgloss.Color("#00432F"))
typeColors := map[string]lipgloss.Color{
"Bug": lipgloss.Color("#D7FF87"),
"Electric": lipgloss.Color("#FDFF90"),
Expand Down Expand Up @@ -101,13 +101,13 @@ func main() {
}

color := c[fmt.Sprint(data[row-1][col])]
return baseStyle.Copy().Foreground(color)
return baseStyle.Foreground(color)
}

if even {
return baseStyle.Copy().Foreground(lipgloss.Color("245"))
return baseStyle.Foreground(lipgloss.Color("245"))
}
return baseStyle.Copy().Foreground(lipgloss.Color("252"))
return baseStyle.Foreground(lipgloss.Color("252"))
})
fmt.Println(t)
}

0 comments on commit c7bab34

Please sign in to comment.