package clipper

import (
	
	
)

type Clipboard interface {
	// Init initializes the clipboard and returns an error if it is not
	// accessible
	Init() error
	// ReadAll returns the contents of the clipboard register 'reg'
	ReadAll(reg string) ([]byte, error)
	// WriteAll writes 'p' to the clipboard register 'reg'
	WriteAll(reg string, p []byte) error
}

const (
	RegClipboard = "clipboard"
	RegPrimary   = "primary"
)

type ErrInvalidReg struct {
	Reg string
}

func ( *ErrInvalidReg) () string {
	return fmt.Sprintf("invalid register: %s", .Reg)
}

func verify( Clipboard,  ...string) error {
	for ,  := range  {
		if ,  := exec.LookPath();  != nil {
			// command not installed
			return 
		}
	}
	,  := .ReadAll(RegClipboard)
	if  == nil {
		// reading clipboard worked
		return nil
	}
	// reading could fail if the clipboard has no contents, so check if writing
	// works in that case
	return .WriteAll(RegClipboard, []byte{})
}

func write( *exec.Cmd,  []byte) error {
	,  := .StdinPipe()
	if  != nil {
		return 
	}
	if  := .Start();  != nil {
		return 
	}
	if ,  := .Write();  != nil {
		return 
	}
	.Close()
	return .Wait()
}