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
|
package desktop
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"bytes"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (manager *DesktopManagerCtx) ReadClipboard() (string, error) {
|
func (manager *DesktopManagerCtx) ReadClipboard() (string, error) {
|
||||||
out, err := exec.Command("xclip", "-selection", "clipboard", "-o").Output()
|
cmd := exec.Command("xclip", "-selection", "clipboard", "-o")
|
||||||
return string(out), err
|
|
||||||
|
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 {
|
func (manager *DesktopManagerCtx) WriteClipboard(data string) error {
|
||||||
cmd := exec.Command("xclip", "-selection", "clipboard", "-i")
|
cmd := exec.Command("xclip", "-selection", "clipboard", "-i")
|
||||||
cmd.Stdin = strings.NewReader(data)
|
cmd.Stdin = strings.NewReader(data)
|
||||||
return cmd.Run()
|
|
||||||
|
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