1package e2e23import (4 "sync"56 ghostty "go.mitchellh.com/libghostty"7)89func init() {10 namedKeys["f4"] = ghostty.KeyF411}1213// clipboard records what the program writes to the system clipboard14// through the terminal (OSC 52).15type clipboard struct {16 mu sync.Mutex17 text string18}1920func (c *clipboard) get() string {21 c.mu.Lock()22 defer c.mu.Unlock()23 return c.text24}2526// watchClipboard makes the terminal accept clipboard writes and records27// them.28func (s *session) watchClipboard() *clipboard {29 c := &clipboard{}30 s.mu.Lock()31 defer s.mu.Unlock()32 s.vt.SetEffectClipboardWrite(func(_ *ghostty.Terminal, w ghostty.ClipboardWrite) ghostty.ClipboardWriteReply {33 c.mu.Lock()34 defer c.mu.Unlock()35 for _, content := range w.Contents {36 if content.MIME == "text/plain" || c.text == "" {37 c.text = string(content.Data)38 }39 }40 return ghostty.ClipboardWriteReply{Result: ghostty.ClipboardWriteSuccess}41 })42 return c43}4445// paste pastes text as the terminal would, with bracketed paste when the46// program asked for it.47func (s *session) paste(text string) {48 s.t.Helper()49 s.mu.Lock()50 bracketed, _ := s.vt.Mode(ghostty.ModeBracketedPaste)51 s.mu.Unlock()52 data, err := ghostty.PasteEncode([]byte(text), bracketed)53 if err != nil {54 s.t.Fatal(err)55 }56 if _, err := s.pty.Write(data); err != nil {57 s.t.Fatal(err)58 }59}