diff --git a/main.go b/main.go index eab2779..12e50e1 100644 --- a/main.go +++ b/main.go @@ -6,7 +6,6 @@ import ( "io" "log" "os" - "strings" "golang.design/x/clipboard" @@ -112,7 +111,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.out.Blur() return m, tea.Quit case key.Matches(msg, m.keymap.copy): - clipboard.Write(clipboard.FmtText, []byte(m.out.Value())) + clipboard.Write(clipboard.FmtText, []byte(lines)) case key.Matches(msg, m.keymap.clear): m.out.SetValue("") lines = lines[:0] @@ -134,7 +133,8 @@ func (m *model) sizeInputs() { m.out.SetWidth(m.width - 5) } -var lines []string +var lines string + func (m model) View() string { help := m.help.ShortHelpView([]key.Binding{ m.keymap.copy, @@ -142,7 +142,7 @@ func (m model) View() string { }) var views []string - m.out.SetValue(strings.Join(lines, "\n")) + m.out.SetValue(lines) views = append(views, m.out.View()) return lipgloss.JoinHorizontal(lipgloss.Top, views...) + "\n" + help @@ -174,13 +174,14 @@ func main() { if err != nil { panic(err) } - + go func() { ch := clipboard.Watch(context.TODO(), clipboard.FmtText) for data := range ch { - // log.Printf("%#v", m.out.Value() + "\n" + string(data)) - // m.out.SetValue(m.out.Value() + "\n" + string(data)) - lines = append(lines, string(data)) + sdata := string(data) + if sdata != lines { + lines += "\n" + string(sdata) + } } }()