1package yankable
 2
 3import (
 4	tea "github.com/charmbracelet/bubbletea"
 5	"github.com/charmbracelet/lipgloss"
 6)
 7
 8type Yankable struct {
 9	yankStyle lipgloss.Style
10	style     lipgloss.Style
11	text      string
12	clicked   bool
13}
14
15func New(style, yankStyle lipgloss.Style, text string) *Yankable {
16	return &Yankable{
17		yankStyle: yankStyle,
18		style:     style,
19		text:      text,
20		clicked:   false,
21	}
22}
23
24func (y *Yankable) SetText(text string) {
25	y.text = text
26}
27
28func (y *Yankable) Init() tea.Cmd {
29	return nil
30}
31
32func (y *Yankable) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
33	cmds := make([]tea.Cmd, 0)
34	switch msg := msg.(type) {
35	case tea.MouseMsg:
36		switch msg.Type {
37		case tea.MouseRight:
38			y.clicked = true
39			return y, nil
40		}
41	default:
42		y.clicked = false
43	}
44	return y, tea.Batch(cmds...)
45}
46
47func (y *Yankable) View() string {
48	if y.clicked {
49		return y.yankStyle.String()
50	}
51	return y.style.Render(y.text)
52}