Skip to content

Commit

Permalink
feat: description and links support (#69)
Browse files Browse the repository at this point in the history
* feat: description and links support

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

* revert unwnated changes

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

* fix: list height issues

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

* fix: version

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

* fix: use dep from master branch

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

* fix: use dep from master branch

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 committed May 24, 2022
1 parent 43ce3d6 commit 30c2b5b
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 9 deletions.
8 changes: 8 additions & 0 deletions _example/config.yaml
Expand Up @@ -21,6 +21,14 @@ endpoints:
# Endpoint's address in the host:port format.
address: foo.local:2234

# An URL to be printed in the list.
link:
name: Optional link name
url: https://github.com/charmbracelet/wishlist

# A descripton of the item.
description: "A description of this endpoint.\nCan have multiple lines."

# User to use to connect.
# Defaults to the current remote user.
user: notme
Expand Down
16 changes: 16 additions & 0 deletions config.go
Expand Up @@ -7,6 +7,20 @@ import (
"github.com/gliderlabs/ssh"
)

// Link defines an item link.
type Link struct {
Name string `yaml:"name"`
URL string `yaml:"url"`
}

func (l Link) String() string {
if l.URL == "" {
return ""
}
// TODO: move to new termenv when released.
return fmt.Sprintf("\x1b]8;;%s\x1b\\%s\x1b]8;;\x1b\\", l.URL, firstNonEmpty(l.Name, l.URL))
}

// Endpoint represents an endpoint to list.
// If it has a Handler, wishlist will start an SSH server on the given address.
type Endpoint struct {
Expand All @@ -16,6 +30,8 @@ type Endpoint struct {
ForwardAgent bool `yaml:"forward_agent"` // ForwardAgent defines wether to forward the current agent. Anologous to SSH's config ForwardAgent.
RequestTTY bool `yaml:"request_tty"` // RequestTTY defines wether to request a TTY. Anologous to SSH's config RequestTTY.
RemoteCommand string `yaml:"remote_command"` // RemoteCommand defines wether to request a TTY. Anologous to SSH's config RemoteCommand.
Desc string `yaml:"description"` // Description describes an optional description of the item.
Link Link `yaml:"link"` // Links can be used to add a link to the item description using OSC8.
IdentityFiles []string `yaml:"-"` // IdentityFiles is only set when parsing from a SSH Config file, and used only on local mode.
Middlewares []wish.Middleware `yaml:"-"` // wish middlewares you can use in the factory method.
}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Expand Up @@ -3,8 +3,8 @@ module github.com/charmbracelet/wishlist
go 1.18

require (
github.com/charmbracelet/bubbles v0.10.3
github.com/charmbracelet/bubbletea v0.20.1-0.20220412142310-3795c036c451
github.com/charmbracelet/bubbles v0.10.4-0.20220524180035-cd2593cfb77c
github.com/charmbracelet/bubbletea v0.20.1-0.20220516164627-a5f28a3a04bb
github.com/charmbracelet/keygen v0.3.0
github.com/charmbracelet/lipgloss v0.5.0
github.com/charmbracelet/wish v0.4.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Expand Up @@ -4,11 +4,11 @@ github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/caarlos0/sshmarshal v0.1.0 h1:zTCZrDORFfWh526Tsb7vCm3+Yg/SfW/Ub8aQDeosk0I=
github.com/caarlos0/sshmarshal v0.1.0/go.mod h1:7Pd/0mmq9x/JCzKauogNjSQEhivBclCQHfr9dlpDIyA=
github.com/charmbracelet/bubbles v0.10.3 h1:fKarbRaObLn/DCsZO4Y3vKCwRUzynQD9L+gGev1E/ho=
github.com/charmbracelet/bubbles v0.10.3/go.mod h1:jOA+DUF1rjZm7gZHcNyIVW+YrBPALKfpGVdJu8UiJsA=
github.com/charmbracelet/bubbles v0.10.4-0.20220524180035-cd2593cfb77c h1:uY5gWGsKwuUaWNxN0rp8MlgbpXIbhHUu2VVV4AvG+QU=
github.com/charmbracelet/bubbles v0.10.4-0.20220524180035-cd2593cfb77c/go.mod h1:jOA+DUF1rjZm7gZHcNyIVW+YrBPALKfpGVdJu8UiJsA=
github.com/charmbracelet/bubbletea v0.19.3/go.mod h1:VuXF2pToRxDUHcBUcPmCRUHRvFATM4Ckb/ql1rBl3KA=
github.com/charmbracelet/bubbletea v0.20.1-0.20220412142310-3795c036c451 h1:yCONEYndKfmJAirOLnG0MwAVqVUZurcZ6VZpxC/RnzU=
github.com/charmbracelet/bubbletea v0.20.1-0.20220412142310-3795c036c451/go.mod h1:GgmJMec61d08zXsOhqRC/AiOx4K4pmz+VIcRIm1FKr4=
github.com/charmbracelet/bubbletea v0.20.1-0.20220516164627-a5f28a3a04bb h1:bRxIjkw9/Bd7ppM/w04SWLxfytUwKRvwP3TPkMooUnI=
github.com/charmbracelet/bubbletea v0.20.1-0.20220516164627-a5f28a3a04bb/go.mod h1:GgmJMec61d08zXsOhqRC/AiOx4K4pmz+VIcRIm1FKr4=
github.com/charmbracelet/harmonica v0.1.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao=
github.com/charmbracelet/keygen v0.3.0 h1:mXpsQcH7DDlST5TddmXNXjS0L7ECk4/kLQYyBcsan2Y=
github.com/charmbracelet/keygen v0.3.0/go.mod h1:1ukgO8806O25lUZ5s0IrNur+RlwTBERlezdgW71F5rM=
Expand Down
19 changes: 16 additions & 3 deletions wishlist.go
@@ -1,7 +1,6 @@
package wishlist

import (
"fmt"
"log"

"github.com/charmbracelet/bubbles/key"
Expand All @@ -20,7 +19,10 @@ var enter = key.NewBinding(
// NewListing creates a new listing model for the given endpoints and SSH session.
// If sessuion is nil, it is assume to be a local listing.
func NewListing(endpoints []*Endpoint, client SSHClient) *ListModel {
l := list.NewModel(endpointsToListItems(endpoints), list.NewDefaultDelegate(), 0, 0)
d := list.NewDefaultDelegate()
d.SetHeight(5)

l := list.NewModel(endpointsToListItems(endpoints), d, 0, 0)
l.Title = "Directory Listing"
l.AdditionalShortHelpKeys = func() []key.Binding {
return []key.Binding{enter}
Expand All @@ -37,7 +39,18 @@ func NewListing(endpoints []*Endpoint, client SSHClient) *ListModel {
func (i *Endpoint) Title() string { return i.Name }

// Description to abide the list.Item interface.
func (i *Endpoint) Description() string { return fmt.Sprintf("ssh://%s", i.Address) }
func (i *Endpoint) Description() string {
var lines []string
if i.Desc != "" {
lines = append(lines, i.Desc)
}
for _, l := range []Link{i.Link, {URL: "ssh://" + i.Address}} {
if s := l.String(); s != "" {
lines = append(lines, s)
}
}
return lipgloss.JoinVertical(lipgloss.Left, lines...)
}

// FilterValue to abide the list.Item interface.
func (i *Endpoint) FilterValue() string { return i.Name }
Expand Down

0 comments on commit 30c2b5b

Please sign in to comment.