mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
41 lines
795 B
Go
41 lines
795 B
Go
package desktop
|
|
|
|
import (
|
|
"fmt"
|
|
"bytes"
|
|
"os/exec"
|
|
"strings"
|
|
)
|
|
|
|
func (manager *DesktopManagerCtx) ReadClipboard() (string, error) {
|
|
cmd := exec.Command("xclip", "-selection", "clipboard", "-o")
|
|
|
|
var stdout, stderr bytes.Buffer
|
|
cmd.Stdout = &stdout
|
|
cmd.Stderr = &stderr
|
|
|
|
err := cmd.Run()
|
|
if err != nil {
|
|
msg := strings.TrimSpace(string(stderr.Bytes()))
|
|
return "", fmt.Errorf("%s", msg)
|
|
}
|
|
|
|
return string(stdout.Bytes()), nil
|
|
}
|
|
|
|
func (manager *DesktopManagerCtx) WriteClipboard(data string) error {
|
|
cmd := exec.Command("xclip", "-selection", "clipboard", "-i")
|
|
cmd.Stdin = strings.NewReader(data)
|
|
|
|
var stderr bytes.Buffer
|
|
cmd.Stderr = &stderr
|
|
|
|
err := cmd.Run()
|
|
if err != nil {
|
|
msg := strings.TrimSpace(string(stderr.Bytes()))
|
|
return fmt.Errorf("%s", msg)
|
|
}
|
|
|
|
return nil
|
|
}
|