-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.go
54 lines (43 loc) · 1009 Bytes
/
commands.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// commands.go
package main
import (
"flag"
"log"
"os"
"strconv"
"time"
"github.com/olekukonko/tablewriter"
)
func PrintHistory(storage *Storage, cli *CliOptions) error {
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"ID", "CONTENT"})
table.SetBorder(true)
table.SetRowLine(true)
for _, clip := range storage.List(cli.Last) {
table.Append([]string{strconv.Itoa(clip.Shortcut), clip.Content})
}
table.Render()
return nil
}
func CopyClip(storage *Storage, cli *CliOptions) error {
clipShortcut, err := strconv.Atoi(flag.Arg(1))
if err != nil {
return err
}
clip, err := storage.Get(clipShortcut)
if err != nil {
return err
}
log.Printf("copying '%s' to clipboard\n", clip.Content)
return clip.Copy()
}
func WatchClipboard(storage *Storage, cli *CliOptions) error {
log.Printf("watching for clipboard [refresh=%v]\n", cli.Refresh)
for {
c := NewClip()
if err := storage.SaveIfNew(c); err != nil {
return err
}
time.Sleep(cli.Refresh)
}
}