diff --git a/cmd/wishlist/main.go b/cmd/wishlist/main.go index fe47afc..2375d17 100644 --- a/cmd/wishlist/main.go +++ b/cmd/wishlist/main.go @@ -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" @@ -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 } diff --git a/go.mod b/go.mod index 3783ce9..c99bd2f 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 @@ -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 diff --git a/go.sum b/go.sum index e085470..c9b17b4 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= @@ -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= diff --git a/listitem.go b/listitem.go index 712972d..d7cfd72 100644 --- a/listitem.go +++ b/listitem.go @@ -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. @@ -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") } diff --git a/listitem_test.go b/listitem_test.go index be51958..effe797 100644 --- a/listitem_test.go +++ b/listitem_test.go @@ -38,7 +38,7 @@ func TestWithSSHURL(t *testing.T) { "ssh://localhost:22", withSSHURL(&Endpoint{ Address: "localhost:22", - }), + }, styles{}), ) } @@ -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) { @@ -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) { @@ -65,7 +65,7 @@ func TestWithDescription(t *testing.T) { "foobar desc", withDescription(&Endpoint{ Desc: "foobar desc", - }), + }, makeStyles(testRenderer)), ) }) } @@ -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) { @@ -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) { @@ -98,7 +98,7 @@ func TestWithLink(t *testing.T) { Name: "example", URL: "https://example.com", }, - }), + }, makeStyles(testRenderer)), ) }) } diff --git a/middleware.go b/middleware.go index 168e9e0..37f308a 100644 --- a/middleware.go +++ b/middleware.go @@ -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" @@ -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)), diff --git a/styles.go b/styles.go new file mode 100644 index 0000000..af3f612 --- /dev/null +++ b/styles.go @@ -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 +} diff --git a/styles_test.go b/styles_test.go new file mode 100644 index 0000000..793a7d9 --- /dev/null +++ b/styles_test.go @@ -0,0 +1,9 @@ +package wishlist + +import ( + "os" + + "github.com/charmbracelet/lipgloss" +) + +var testRenderer = lipgloss.NewRenderer(os.Stderr) diff --git a/wishlist.go b/wishlist.go index 06bf172..5b6ef43 100644 --- a/wishlist.go +++ b/wishlist.go @@ -10,8 +10,6 @@ import ( "github.com/charmbracelet/log" ) -var docStyle = lipgloss.NewStyle().Margin(1, 2) //nolint:gomnd - var ( enter = key.NewBinding( key.WithKeys("enter", "o"), @@ -24,7 +22,7 @@ var ( // NewListing creates a new listing model for the given endpoints and SSH session. // If session is nil, it is assume to be a local listing. -func NewListing(endpoints []*Endpoint, client SSHClient) *ListModel { +func NewListing(endpoints []*Endpoint, client SSHClient, r *lipgloss.Renderer) *ListModel { l := list.New(nil, list.NewDefaultDelegate(), 0, 0) l.Title = "Directory Listing" l.AdditionalShortHelpKeys = func() []key.Binding { @@ -35,6 +33,7 @@ func NewListing(endpoints []*Endpoint, client SSHClient) *ListModel { list: l, endpoints: endpoints, client: client, + styles: makeStyles(r), } m.SetItems(endpoints) return m @@ -48,6 +47,7 @@ type ListModel struct { quitting bool width int err error + styles styles } // SetItems allows to update the listing items. @@ -58,7 +58,7 @@ func (m *ListModel) SetItems(endpoints []*Endpoint) tea.Cmd { d.SetHeight(h) m.list.SetDelegate(d) log.Debug("setting delegate height", "height", h) - return m.list.SetItems(endpointsToListItems(endpoints, descriptors)) + return m.list.SetItems(endpointsToListItems(endpoints, descriptors, m.styles)) } func features(endpoints []*Endpoint) []descriptor { @@ -89,7 +89,7 @@ func features(endpoints []*Endpoint) []descriptor { return append(descriptors, withSSHURL) } -func endpointsToListItems(endpoints []*Endpoint, descriptors []descriptor) []list.Item { +func endpointsToListItems(endpoints []*Endpoint, descriptors []descriptor, styles styles) []list.Item { var items []list.Item //nolint: prealloc for _, endpoint := range endpoints { if !endpoint.Valid() { @@ -98,6 +98,7 @@ func endpointsToListItems(endpoints []*Endpoint, descriptors []descriptor) []lis items = append(items, ItemWrapper{ endpoint: endpoint, descriptors: descriptors, + styles: styles, }) } return items @@ -148,7 +149,7 @@ func (m *ListModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } case tea.WindowSizeMsg: - top, right, bottom, left := docStyle.GetMargin() + top, right, bottom, left := m.styles.Doc.GetMargin() m.width = msg.Width m.list.SetSize(msg.Width-left-right, msg.Height-top-bottom) @@ -170,19 +171,6 @@ func (m *ListModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, cmd } -var ( - logoStyle = lipgloss.NewStyle(). - Foreground(lipgloss.AdaptiveColor{Light: "#FFFDF5", Dark: "#FFFDF5"}). - Background(lipgloss.Color("#5A56E0")). - Padding(0, 1). - SetString("Wishlist") - errStyle = lipgloss.NewStyle(). - Italic(true). - Foreground(lipgloss.AdaptiveColor{Light: "#FF4672", Dark: "#ED567A"}) - footerStyle = lipgloss.NewStyle(). - Foreground(lipgloss.AdaptiveColor{Light: "#9B9B9B", Dark: "#5C5C5C"}) -) - // View comply with tea.Model interface. func (m *ListModel) View() string { if m.quitting { @@ -193,18 +181,18 @@ func (m *ListModel) View() string { header := lipgloss.NewStyle(). Width(m.width). Render("Something went wrong:") - errstr := errStyle.Copy(). + errstr := m.styles.Err.Copy(). Width(m.width). Render(rootCause(m.err).Error()) - footer := footerStyle.Copy(). + footer := m.styles.Footer.Copy(). Width(m.width). Render("Press any key to go back to the list.") - return logoStyle.String() + "\n\n" + + return m.styles.Logo.String() + "\n\n" + header + "\n\n" + errstr + "\n\n" + footer + "\n" } - return docStyle.Render(m.list.View()) + return m.styles.Doc.Render(m.list.View()) } func rootCause(err error) error { diff --git a/wishlist_test.go b/wishlist_test.go index 8553fb8..aee64af 100644 --- a/wishlist_test.go +++ b/wishlist_test.go @@ -16,7 +16,7 @@ func TestEndointToListItems(t *testing.T) { { // invalid }, - }, nil) + }, nil, makeStyles(testRenderer)) require.Len(t, result, 1) item := result[0] @@ -31,7 +31,7 @@ func TestNewWishlist(t *testing.T) { Name: "name", Address: "anything", }, - }, cl) + }, cl, testRenderer) require.Len(t, lm.endpoints, 1) require.Equal(t, lm.client, cl) })