mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
xclip verbose error output.
This commit is contained in:
parent
11e74459ac
commit
4602f5f6cf
@ -1,17 +1,40 @@
|
||||
package desktop
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"bytes"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (manager *DesktopManagerCtx) ReadClipboard() (string, error) {
|
||||
out, err := exec.Command("xclip", "-selection", "clipboard", "-o").Output()
|
||||
return string(out), err
|
||||
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)
|
||||
return cmd.Run()
|
||||
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user