Use an external command for clipboard

This commit is contained in:
2025-01-30 08:07:05 -06:00
parent e8bf42dd17
commit cf346ed025
5 changed files with 18 additions and 56 deletions

View File

@@ -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)