Skip to content

Commit

Permalink
feat: update wish (#264)
Browse files Browse the repository at this point in the history
* feat: update wish

Update wish, and use the new MakeRenderer feature to properly handle
colors.

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

* test: update

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

* chore: update

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

* chore: lint

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

---------

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 authored Feb 2, 2024
1 parent dda9ca2 commit 2987a2e
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 69 deletions.
13 changes: 11 additions & 2 deletions cmd/wishlist/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/keygen"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/log"
"github.com/charmbracelet/ssh"
"github.com/charmbracelet/wish"
Expand Down Expand Up @@ -395,8 +396,16 @@ func getSSHConfig(path string, seed []*wishlist.Endpoint) (wishlist.Config, erro
func workLocally(config wishlist.Config, args []string) error {
// either no args or arg is a list
if len(args) == 0 || args[0] == "list" {
m := wishlist.NewListing(config.Endpoints, wishlist.NewLocalSSHClient())
_, err := tea.NewProgram(m, tea.WithAltScreen()).Run()
m := wishlist.NewListing(
config.Endpoints,
wishlist.NewLocalSSHClient(),
lipgloss.NewRenderer(os.Stderr),
)
_, err := tea.NewProgram(
m,
tea.WithOutput(os.Stderr),
tea.WithAltScreen(),
).Run()
return err //nolint: wrapcheck
}

Expand Down
9 changes: 6 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ require (
github.com/charmbracelet/lipgloss v0.9.1
github.com/charmbracelet/log v0.3.1
github.com/charmbracelet/promwish v0.7.0
github.com/charmbracelet/ssh v0.0.0-20221117183211-483d43d97103
github.com/charmbracelet/wish v1.2.0
github.com/charmbracelet/ssh v0.0.0-20240202115812-f4ab1009799a
github.com/charmbracelet/wish v1.3.1-0.20240202121148-92123fdfa942
github.com/gobwas/glob v0.2.3
github.com/grandcat/zeroconf v1.0.0
github.com/hashicorp/go-multierror v1.1.1
Expand All @@ -35,7 +35,10 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/charmbracelet/x/errors v0.0.0-20240117030013-d31dba354651 // indirect
github.com/charmbracelet/x/exp/term v0.0.0-20240202113029-6ff29cf0473e // indirect
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
github.com/creack/pty v1.1.21 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
Expand All @@ -62,7 +65,7 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sync v0.4.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
Expand Down
27 changes: 12 additions & 15 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,20 @@ github.com/charmbracelet/log v0.3.1 h1:TjuY4OBNbxmHWSwO3tosgqs5I3biyY8sQPny/eCMT
github.com/charmbracelet/log v0.3.1/go.mod h1:OR4E1hutLsax3ZKpXbgUqPtTjQfrh1pG3zwHGWuuq8g=
github.com/charmbracelet/promwish v0.7.0 h1:oaMH+ey6W4DDIv1xucS8jL1ik/Q46qxjNXlh6XxEm+s=
github.com/charmbracelet/promwish v0.7.0/go.mod h1:WbRJN9irg8LmsBU8G2rFF8md9O3rSg63qrnqquP/+cs=
github.com/charmbracelet/ssh v0.0.0-20221117183211-483d43d97103 h1:wpHMERIN0pQZE635jWwT1dISgfjbpUcEma+fbPKSMCU=
github.com/charmbracelet/ssh v0.0.0-20221117183211-483d43d97103/go.mod h1:0Vm2/8yBljiLDnGJHU8ehswfawrEybGk33j5ssqKQVM=
github.com/charmbracelet/wish v1.2.0 h1:h5Wj9pr97IQz/l4gM5Xep2lXcY/YM+6O2RC2o3x0JIQ=
github.com/charmbracelet/wish v1.2.0/go.mod h1:JX3fC+178xadJYAhPu6qWtVDpJTwpnFvpdjz9RKJlUE=
github.com/charmbracelet/ssh v0.0.0-20240202115812-f4ab1009799a h1:ryXQeBfu7DN77RFiKLa/VA9VRkMsinpkv4qYparR//k=
github.com/charmbracelet/ssh v0.0.0-20240202115812-f4ab1009799a/go.mod h1:GPT/bjXsVDf5TKq2P1n4zl79ZnGwt2lWr19DomWm7zw=
github.com/charmbracelet/wish v1.3.1-0.20240202121148-92123fdfa942 h1:JiZXIlVQbnnJ/bm/Hi/T/OsP9NSR2BF6AJ1hxCBsn8s=
github.com/charmbracelet/wish v1.3.1-0.20240202121148-92123fdfa942/go.mod h1:4GbN5YK/Qmip0k/nT+dOuYVpdKgj3oZBnsOeEJlG9fE=
github.com/charmbracelet/x/errors v0.0.0-20240117030013-d31dba354651 h1:3RXpZWGWTOeVXCTv0Dnzxdv/MhNUkBfEcbaTY0zrTQI=
github.com/charmbracelet/x/errors v0.0.0-20240117030013-d31dba354651/go.mod h1:2P0UgXMEa6TsToMSuFqKFQR+fZTO9CNGUNokkPatT/0=
github.com/charmbracelet/x/exp/term v0.0.0-20240202113029-6ff29cf0473e h1:45T85zTqW/gN3FK5/JFM5Jk+LJkdP2gAfJcg8xE5lBs=
github.com/charmbracelet/x/exp/term v0.0.0-20240202113029-6ff29cf0473e/go.mod h1:8NVO/XlUZbcJU5g0gVE7K1YiNnRFqYA3nZzGS/0lBRk=
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 h1:q2hJAaP1k2wIvVRd/hEHD7lacgqrCPS+k8g1MndzfWY=
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/creack/pty v1.1.21 h1:1/QdRyBaHHJP61QkWMXlOIBfsgdDeeKfK8SYVUWJKf0=
github.com/creack/pty v1.1.21/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4=
Expand Down Expand Up @@ -116,7 +122,6 @@ github.com/teivah/broadcast v0.1.0 h1:UMs1tn8w20Xlnod+VbLbwH3dzEH2zfJy4lxdzZjQLL
github.com/teivah/broadcast v0.1.0/go.mod h1:mXEgvXdYz2xUkQFARxI+jyX1MfCBwMDiGjIKSAsEq1g=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
Expand All @@ -127,33 +132,25 @@ golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/oauth2 v0.16.0 h1:aDkGMBSYxElaoP81NpoUoz2oo2R2wHdZpGToUxfyQrQ=
golang.org/x/oauth2 v0.16.0/go.mod h1:hqZ+0LWXsiVoZpeld6jVt06P3adbS2Uu911W1SsJv2o=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ=
golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.16.0 h1:m+B6fahuftsE9qjo0VWp2FW0mB3MTJvR0BaMQrq0pmE=
golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
18 changes: 8 additions & 10 deletions listitem.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@ import (
"strings"

"github.com/charmbracelet/bubbles/list"
"github.com/charmbracelet/lipgloss"
)

var noContentStyle = lipgloss.NewStyle().Faint(true).Italic(true)

var _ list.Item = ItemWrapper{}

// ItemWrapper wrappes an Endpoint and a set of descriptors and acts as a list.Item.
type ItemWrapper struct {
endpoint *Endpoint
descriptors []descriptor
styles styles
}

// FilterValue to abide the list.Item interface.
Expand All @@ -27,27 +25,27 @@ func (i ItemWrapper) Title() string { return i.endpoint.Name }
func (i ItemWrapper) Description() string {
lines := make([]string, 0, len(i.descriptors))
for _, desc := range i.descriptors {
lines = append(lines, desc(i.endpoint))
lines = append(lines, desc(i.endpoint, i.styles))
}
return strings.Join(lines, "\n")
}

type descriptor func(e *Endpoint) string
type descriptor func(e *Endpoint, styles styles) string

func withSSHURL(i *Endpoint) string {
func withSSHURL(i *Endpoint, _ styles) string {
return Link{URL: "ssh://" + i.Address}.String()
}

func withLink(i *Endpoint) string {
func withLink(i *Endpoint, styles styles) string {
if l := i.Link.String(); l != "" {
return l
}
return noContentStyle.Render("no link")
return styles.NoContent.Render("no link")
}

func withDescription(i *Endpoint) string {
func withDescription(i *Endpoint, styles styles) string {
if desc := strings.Split(i.Desc, "\n")[0]; desc != "" {
return desc
}
return noContentStyle.Render("no description")
return styles.NoContent.Render("no description")
}
14 changes: 7 additions & 7 deletions listitem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestWithSSHURL(t *testing.T) {
"ssh://localhost:22",
withSSHURL(&Endpoint{
Address: "localhost:22",
}),
}, styles{}),
)
}

Expand All @@ -47,7 +47,7 @@ func TestWithDescription(t *testing.T) {
require.Equal(
t,
"no description",
withDescription(&Endpoint{}),
withDescription(&Endpoint{}, makeStyles(testRenderer)),
)
})
t.Run("multiline", func(t *testing.T) {
Expand All @@ -56,7 +56,7 @@ func TestWithDescription(t *testing.T) {
"foo",
withDescription(&Endpoint{
Desc: "foo\n\nbar\n\nsfsdfsd\n",
}),
}, makeStyles(testRenderer)),
)
})
t.Run("simple", func(t *testing.T) {
Expand All @@ -65,7 +65,7 @@ func TestWithDescription(t *testing.T) {
"foobar desc",
withDescription(&Endpoint{
Desc: "foobar desc",
}),
}, makeStyles(testRenderer)),
)
})
}
Expand All @@ -75,7 +75,7 @@ func TestWithLink(t *testing.T) {
require.Equal(
t,
"no link",
withLink(&Endpoint{}),
withLink(&Endpoint{}, makeStyles(testRenderer)),
)
})
t.Run("url only", func(t *testing.T) {
Expand All @@ -86,7 +86,7 @@ func TestWithLink(t *testing.T) {
Link: Link{
URL: "https://example.com",
},
}),
}, makeStyles(testRenderer)),
)
})
t.Run("url and name", func(t *testing.T) {
Expand All @@ -98,7 +98,7 @@ func TestWithLink(t *testing.T) {
Name: "example",
URL: "https://example.com",
},
}),
}, makeStyles(testRenderer)),
)
})
}
19 changes: 12 additions & 7 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/charmbracelet/log"
"github.com/charmbracelet/ssh"
"github.com/charmbracelet/wish"
bm "github.com/charmbracelet/wish/bubbletea"
"github.com/charmbracelet/wishlist/blocking"
"github.com/charmbracelet/wishlist/multiplex"
"github.com/muesli/termenv"
Expand Down Expand Up @@ -60,14 +61,18 @@ func listingMiddleware(config *Config, endpointRelay *broadcast.Relay[[]*Endpoin

errch := make(chan error, 1)
appch := make(chan bool, 1)
model := NewListing(config.Endpoints, &remoteClient{
session: s,
stdin: handoffStdin,
cleanup: func() {
listStdin.Reset()
handoffStdin.Reset()
model := NewListing(
config.Endpoints,
&remoteClient{
session: s,
stdin: handoffStdin,
cleanup: func() {
listStdin.Reset()
handoffStdin.Reset()
},
},
})
bm.MakeRenderer(s),
)
p := tea.NewProgram(
model,
tea.WithInput(blocking.New(listStdin)),
Expand Down
29 changes: 29 additions & 0 deletions styles.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package wishlist

import "github.com/charmbracelet/lipgloss"

//nolint:gomnd
func makeStyles(r *lipgloss.Renderer) styles {
return styles{
Logo: r.NewStyle().
Foreground(lipgloss.AdaptiveColor{Light: "#FFFDF5", Dark: "#FFFDF5"}).
Background(lipgloss.Color("#5A56E0")).
Padding(0, 1).
SetString("Wishlist"),
Err: r.NewStyle().
Italic(true).
Foreground(lipgloss.AdaptiveColor{Light: "#FF4672", Dark: "#ED567A"}),
Footer: r.NewStyle().
Foreground(lipgloss.AdaptiveColor{Light: "#9B9B9B", Dark: "#5C5C5C"}),
NoContent: r.NewStyle().Faint(true).Italic(true),
Doc: r.NewStyle().Margin(1, 2),
}
}

type styles struct {
Logo lipgloss.Style
Err lipgloss.Style
Footer lipgloss.Style
NoContent lipgloss.Style
Doc lipgloss.Style
}
9 changes: 9 additions & 0 deletions styles_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package wishlist

import (
"os"

"github.com/charmbracelet/lipgloss"
)

var testRenderer = lipgloss.NewRenderer(os.Stderr)
Loading

0 comments on commit 2987a2e

Please sign in to comment.