Skip to content

Commit f752412

Browse files
committed
more verbose
1 parent 7cd823d commit f752412

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

commands.go

+15-9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"bufio"
55
"fmt"
6+
"log"
67
"net/url"
78
"os/exec"
89
"runtime"
@@ -580,7 +581,20 @@ func (cmd cpCommand) run(state *State, group, args string, reader *bufio.Reader)
580581
if err != nil {
581582
fmt.Printf("Error: unable to copy! Reason: %s\n", err.Error())
582583
} else {
583-
go removeFromClipboardAfterDelay(content)
584+
delay := 1 * time.Minute
585+
fmt.Printf("%d bytes in clipboard, for %s\n", len(content), delay)
586+
go func() {
587+
<-time.After(delay)
588+
c, err := clipboard.ReadAll()
589+
if err == nil && c == content {
590+
err = clipboard.WriteAll("")
591+
if err != nil {
592+
log.Println("Failed to clear clipboard:", err)
593+
} else {
594+
log.Println("Cleared clipboard") // verbose
595+
}
596+
}
597+
}()
584598
}
585599
} else {
586600
fmt.Printf("Error: entry '%s' does not exist.\n", entry)
@@ -1115,11 +1129,3 @@ func ask2OptionsQuestion(question string, reader *bufio.Reader,
11151129
}
11161130
}
11171131
}
1118-
1119-
func removeFromClipboardAfterDelay(content string) {
1120-
time.Sleep(60 * time.Second)
1121-
c, err := clipboard.ReadAll()
1122-
if err == nil && c == content {
1123-
clipboard.WriteAll("")
1124-
}
1125-
}

0 commit comments

Comments
 (0)