Debian Codegraph @

internal/clipboard/terminal.go

raw
1 package clipboard
2
3 import (
4 "errors"
5 "time"
6
7 "github.com/micro-editor/tcell/v2"
8 "github.com/zyedidia/micro/v2/internal/screen"
9 )
10
11 type terminalClipboard struct{}
12
13 var terminal terminalClipboard
14
15 func (t terminalClipboard) read(reg string) (string, error) {
16 screen.Screen.GetClipboard(reg)
17 // wait at most 200ms for response
18 for {
19 select {
20 case event := <-screen.Events:
21 e, ok := event.(*tcell.EventPaste)
22 if ok {
23 return e.Text(), nil
24 }
25 case <-time.After(200 * time.Millisecond):
26 return "", errors.New("No clipboard received from terminal")
27 }
28 }
29 }
30
31 func (t terminalClipboard) write(text, reg string) error {
32 return screen.Screen.SetClipboard(text, reg)
33 }