Implementing output to clipboard for resources

subcommand
This commit is contained in:
PiMaDaum 2023-02-19 00:23:16 +01:00
parent 61c45be091
commit bf985e9da9
2 changed files with 185 additions and 0 deletions

27
util/clipboard.go Normal file
View file

@ -0,0 +1,27 @@
package util
import (
"fmt"
"time"
"golang.design/x/clipboard"
)
var delaySeconds int = 5
// SetDelay Set the delay between entries
func SetDelay(delay int) {
delaySeconds = delay
}
/*
CopyValueToClipboard Copy the given value to clipboard and sleeps for seconds defined with SetDelay (default: 5 seconds).
After the delay the clipboard will be emptied
*/
func CopyValueToClipboard(entryName string, value string) {
clipboard.Write(clipboard.FmtText, []byte(value))
fmt.Printf("Copying %s to clipboard...\n", entryName)
time.Sleep(time.Duration(delaySeconds) * time.Second)
clipboard.Write(clipboard.FmtText, []byte{})
}