feat: implémentation complete v0.1.0 — daemon de sync clipboard bidirectionnel
CI / Lint (push) Failing after 14m46s
CI / Test (push) Failing after 4m23s
CI / Build (darwin/amd64) (push) Skipped
CI / Build (linux/amd64) (push) Skipped
CI / Build (windows/amd64) (push) Skipped
CI / Build (darwin/arm64) (push) Skipped
CI / Build (linux/arm64) (push) Skipped
CI / Build (windows/arm64) (push) Skipped
CI / Release (push) Skipped
CI / Lint (push) Failing after 14m46s
CI / Test (push) Failing after 4m23s
CI / Build (darwin/amd64) (push) Skipped
CI / Build (linux/amd64) (push) Skipped
CI / Build (windows/amd64) (push) Skipped
CI / Build (darwin/arm64) (push) Skipped
CI / Build (linux/arm64) (push) Skipped
CI / Build (windows/arm64) (push) Skipped
CI / Release (push) Skipped
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
//go:build darwin
|
||||
|
||||
package clipboard
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type darwinClipboard struct{}
|
||||
|
||||
// New creates a macOS clipboard (pbpaste/pbcopy).
|
||||
func New() (Clipboard, error) {
|
||||
return newDarwinClipboard()
|
||||
}
|
||||
|
||||
func newDarwinClipboard() (*darwinClipboard, error) {
|
||||
// Verify pbpaste and pbcopy are available
|
||||
if err := checkBinary("pbpaste"); err != nil {
|
||||
return nil, fmt.Errorf("clip-sync: pbpaste not found: %w", err)
|
||||
}
|
||||
if err := checkBinary("pbcopy"); err != nil {
|
||||
return nil, fmt.Errorf("clip-sync: pbcopy not found: %w", err)
|
||||
}
|
||||
return &darwinClipboard{}, nil
|
||||
}
|
||||
|
||||
func (c *darwinClipboard) Read() (string, error) {
|
||||
cmd := exec.Command("pbpaste")
|
||||
out, err := cmd.Output()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("clipboard read (pbpaste): %w", err)
|
||||
}
|
||||
return strings.TrimRight(string(out), "\n\r"), nil
|
||||
}
|
||||
|
||||
func (c *darwinClipboard) Write(text string) error {
|
||||
cmd := exec.Command("pbcopy")
|
||||
cmd.Stdin = strings.NewReader(text)
|
||||
if err := cmd.Run(); err != nil {
|
||||
return fmt.Errorf("clipboard write (pbcopy): %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user