github.com/cybriq/giocore@v0.0.7-0.20210703034601-cfb9cb5f3900/io/clipboard/clipboard.go (about) 1 // SPDX-License-Identifier: Unlicense OR MIT 2 3 package clipboard 4 5 import ( 6 "github.com/cybriq/giocore/internal/opconst" 7 "github.com/cybriq/giocore/io/event" 8 "github.com/cybriq/giocore/op" 9 ) 10 11 // Event is generated when the clipboard content is requested. 12 type Event struct { 13 Text string 14 } 15 16 // ReadOp requests the text of the clipboard, delivered to 17 // the current handler through an Event. 18 type ReadOp struct { 19 Tag event.Tag 20 } 21 22 // WriteOp copies Text to the clipboard. 23 type WriteOp struct { 24 Text string 25 } 26 27 func (h ReadOp) Add(o *op.Ops) { 28 data := o.Write1(opconst.TypeClipboardReadLen, h.Tag) 29 data[0] = byte(opconst.TypeClipboardRead) 30 } 31 32 func (h WriteOp) Add(o *op.Ops) { 33 data := o.Write1(opconst.TypeClipboardWriteLen, &h.Text) 34 data[0] = byte(opconst.TypeClipboardWrite) 35 } 36 37 func (Event) ImplementsEvent() {}