From 21c19363dd093c3cbf46cceece92c6394bab03a4 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Thu, 26 Jan 2023 14:52:43 -0500 Subject: [PATCH] Added x clipboard stub It doesn't do anything yet but boy is it going to --- backend.go | 2 +- backends/x/x.go | 15 +++++++++++++++ tomo.go | 17 +++++++++++++++-- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/backend.go b/backend.go index ad82740..2b018f3 100644 --- a/backend.go +++ b/backend.go @@ -21,7 +21,7 @@ type Backend interface { // interface. NewWindow (width, height int) (window Window, err error) - // Copy puts data in the clipboard. + // Copy puts data into the clipboard. Copy (data Data) // Paste returns the data currently in the clipboard. This method may diff --git a/backends/x/x.go b/backends/x/x.go index bd6cb15..10d9ea5 100644 --- a/backends/x/x.go +++ b/backends/x/x.go @@ -79,6 +79,21 @@ func (backend *Backend) Do (callback func ()) { backend.doChannel <- callback } +// Copy puts data into the clipboard. This method is not yet implemented and +// will do nothing! +func (backend *Backend) Copy (data tomo.Data) { + backend.assert() + // TODO +} + +// Paste returns the data currently in the clipboard. This method may +// return nil. This method is not yet implemented and will do nothing! +func (backend *Backend) Paste () (data tomo.Data) { + backend.assert() + // TODO + return +} + func (backend *Backend) assert () { if backend == nil { panic("nil backend") } } diff --git a/tomo.go b/tomo.go index b6d9ab0..52e93a7 100644 --- a/tomo.go +++ b/tomo.go @@ -24,6 +24,7 @@ func Stop () { // Do executes the specified callback within the main thread as soon as // possible. This function can be safely called from other threads. func Do (callback func ()) { + if backend == nil { panic("no backend is running") } backend.Do(callback) } @@ -36,6 +37,18 @@ func NewWindow (width, height int) (window Window, err error) { err = errors.New("no backend is running.") return } - window, err = backend.NewWindow(width, height) - return + return backend.NewWindow(width, height) +} + +// Copy puts data into the clipboard. +func Copy (data Data) { + if backend == nil { panic("no backend is running") } + backend.Copy(data) +} + +// Paste returns the data currently in the clipboard. This method may +// return nil. +func Paste () (data Data) { + if backend == nil { panic("no backend is running") } + return backend.Paste() }