Use an external command for clipboard
This commit is contained in:
29
util/cli.go
29
util/cli.go
@@ -7,40 +7,20 @@ import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
//"golang.design/x/clipboard"
|
||||
"github.com/atotto/clipboard"
|
||||
"github.com/spf13/viper"
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
func WriteToClipboard(val string) error {
|
||||
clipboard.WriteAll(val)
|
||||
return nil
|
||||
cmd := exec.Command(viper.GetString("clipboard-command"), val)
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
/*
|
||||
func WriteToClipboard(val string) error {
|
||||
return WriteToClipboardWithTimeout(val, time.Second*5)
|
||||
}
|
||||
func WriteToClipboardWithTimeout(val string, timeout time.Duration) error {
|
||||
ct := make(chan struct{})
|
||||
go func() {
|
||||
time.Sleep(timeout)
|
||||
ct <- struct{}{}
|
||||
}()
|
||||
select {
|
||||
case <-clipboard.Write(clipboard.FmtText, []byte(val)):
|
||||
fmt.Println("Clipboard Changed")
|
||||
case <-ct:
|
||||
fmt.Println("Clipboard Cleared")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
*/
|
||||
|
||||
func PromptUserForPassword(label string) (string, error) {
|
||||
fmt.Println(label)
|
||||
bytePass, err := term.ReadPassword(int(syscall.Stdin))
|
||||
@@ -49,6 +29,7 @@ func PromptUserForPassword(label string) (string, error) {
|
||||
}
|
||||
return string(bytePass), nil
|
||||
}
|
||||
|
||||
func PromptUser(text string) string {
|
||||
var resp string
|
||||
fmt.Println(text)
|
||||
|
Reference in New Issue
Block a user