File: wayland.go

package info (click to toggle)
golang-github-zyedidia-clipper 0.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 152 kB
  • sloc: makefile: 3
file content (47 lines) | stat: -rw-r--r-- 894 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package clipper

import (
	"fmt"
	"os"
	"os/exec"
)

// wl-paste/wl-copy for linux Wayland
type Wayland struct{}

func (wl *Wayland) Init() error {
	if os.Getenv("WAYLAND_DISPLAY") != "" {
		return verify(wl, "wl-paste", "wl-copy")
	}
	return fmt.Errorf("Wayland display not found")
}

func (wl *Wayland) ReadAll(reg string) ([]byte, error) {
	var cmd *exec.Cmd
	switch reg {
	case RegClipboard:
		cmd = exec.Command("wl-paste", "--no-newline")
	case RegPrimary:
		cmd = exec.Command("wl-paste", "--no-newline", "--primary")
	default:
		return nil, &ErrInvalidReg{
			Reg: reg,
		}
	}
	return cmd.Output()
}

func (wl *Wayland) WriteAll(reg string, p []byte) error {
	var cmd *exec.Cmd
	switch reg {
	case RegClipboard:
		cmd = exec.Command("wl-copy")
	case RegPrimary:
		cmd = exec.Command("wl-copy", "--primary")
	default:
		return &ErrInvalidReg{
			Reg: reg,
		}
	}
	return write(cmd, p)
}