Debian Codegraph @

commands/msgview/copy-link.go

raw
1 package msgview
2
3 import (
4 "net/url"
5
6 "git.sr.ht/~rjarry/aerc/app"
7 "git.sr.ht/~rjarry/aerc/commands"
8 "git.sr.ht/~rjarry/aerc/lib/ui"
9 )
10
11 type CopyLink struct {
12 Url *url.URL `opt:"url" action:"ParseUrl" complete:"CompleteUrl"`
13 }
14
15 func init() {
16 commands.Register(CopyLink{})
17 }
18
19 func (CopyLink) Description() string {
20 return "Copy the specified URL to the system clipboard."
21 }
22
23 func (CopyLink) Context() commands.CommandContext {
24 return commands.MESSAGE_VIEWER
25 }
26
27 func (CopyLink) Aliases() []string {
28 return []string{"copy-link"}
29 }
30
31 func (*CopyLink) CompleteUrl(arg string) []string {
32 mv := app.SelectedTabContent().(*app.MessageViewer)
33 if mv != nil {
34 if p := mv.SelectedMessagePart(); p != nil {
35 return commands.FilterList(p.Links, arg, nil)
36 }
37 }
38 return nil
39 }
40
41 func (o *CopyLink) ParseUrl(arg string) error {
42 u, err := url.Parse(arg)
43 if err != nil {
44 return err
45 }
46 o.Url = u
47 return nil
48 }
49
50 func (o CopyLink) Execute(args []string) error {
51 ui.PushClipboard(o.Url.String())
52 return nil
53 }