Skip to content

Commit

Permalink
Add yank feature on link list
Browse files Browse the repository at this point in the history
closes #14
  • Loading branch information
azimut committed May 1, 2023
1 parent 57bfde5 commit f0d122a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/MichaelMure/go-term-markdown v0.1.4
github.com/MichaelMure/go-term-text v0.3.1
github.com/PuerkitoBio/goquery v1.8.1
github.com/atotto/clipboard v0.1.4
github.com/caser/gophernews v0.0.0-20150107061403-f17255d5b792
github.com/charmbracelet/bubbles v0.15.0
github.com/charmbracelet/bubbletea v0.23.2
Expand All @@ -23,7 +24,6 @@ require (
require (
github.com/alecthomas/chroma v0.10.0 // indirect
github.com/andybalholm/cascadia v1.3.1 // indirect
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52 v1.2.1 // indirect
github.com/charmbracelet/harmonica v0.2.0 // indirect
github.com/containerd/console v1.0.3 // indirect
Expand Down
14 changes: 14 additions & 0 deletions internal/tui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os/exec"
"strings"

"github.com/atotto/clipboard"
"github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/bubbles/list"
"github.com/charmbracelet/bubbles/progress"
Expand All @@ -32,6 +33,7 @@ type KeyMap struct {
LinksView key.Binding
LinksOpen key.Binding // TODO: move this elsewhere
LinksOpenXDG key.Binding
LinksYank key.Binding
}

var DefaultKeyMap = KeyMap{
Expand Down Expand Up @@ -67,6 +69,10 @@ var DefaultKeyMap = KeyMap{
key.WithKeys("O"),
key.WithHelp("O", "open link with xdg-open"),
),
LinksYank: key.NewBinding(
key.WithKeys("y"),
key.WithHelp("y", "yank current selected link"),
),
}

func (m Model) Init() tea.Cmd {
Expand Down Expand Up @@ -119,6 +125,14 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
if msg.String() == "enter" && m.list.FilterValue() == "" {
m.list.ResetFilter()
}
case key.Matches(msg, DefaultKeyMap.LinksYank):
i, ok := m.list.SelectedItem().(item)
if ok {
err := clipboard.WriteAll(string(i))
if err != nil {
panic(err)
}
}
case key.Matches(msg, DefaultKeyMap.LinksView, DefaultKeyMap.Quit):
m.Viewport.Width, m.Viewport.Height = m.list.Width(), m.list.Height()-1
m.onLinkScreen = false
Expand Down

0 comments on commit f0d122a

Please sign in to comment.