clipboard.go raw
1 // SPDX-License-Identifier: Unlicense OR MIT
2
3 package clipboard
4
5 import (
6 "github.com/p9c/p9/pkg/gel/gio/internal/opconst"
7 "github.com/p9c/p9/pkg/gel/gio/io/event"
8 "github.com/p9c/p9/pkg/gel/gio/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() {}
38