From 746f1afd1b468b1fa45238cecacd099fc72d9825 Mon Sep 17 00:00:00 2001 From: Hadi <112569860+anotherhadi@users.noreply.github.com> Date: Tue, 19 May 2026 23:00:41 +0200 Subject: [PATCH] edit write clipboard Signed-off-by: Hadi <112569860+anotherhadi@users.noreply.github.com> --- internal/ui/app/update.go | 18 ++++++++++-------- internal/ui/components/copy/model.go | 7 ------- internal/ui/components/copy/update.go | 16 +++++++++++++--- internal/ui/components/copyas/model.go | 10 ---------- internal/ui/components/copyas/update.go | 16 +++++++++++++--- 5 files changed, 36 insertions(+), 31 deletions(-) diff --git a/internal/ui/app/update.go b/internal/ui/app/update.go index 937fee9..69e2cdc 100644 --- a/internal/ui/app/update.go +++ b/internal/ui/app/update.go @@ -211,14 +211,16 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case key.Matches(msg, keys.Keys.Global.Copy): if m.page == pageFindings { if md := m.findingsPage.CurrentMarkdown(); md != "" { - copyUI.WriteClipboard(md) - return m, func() tea.Msg { - return notificationsUI.NotificationMsg{ - Title: "Copied", - Body: "Finding copied to clipboard", - Kind: notificationsUI.KindSuccess, - } - } + return m, tea.Batch( + tea.SetClipboard(md), + func() tea.Msg { + return notificationsUI.NotificationMsg{ + Title: "Copied", + Body: "Finding copied to clipboard", + Kind: notificationsUI.KindSuccess, + } + }, + ) } return m, nil } diff --git a/internal/ui/components/copy/model.go b/internal/ui/components/copy/model.go index ab27401..969f63c 100644 --- a/internal/ui/components/copy/model.go +++ b/internal/ui/components/copy/model.go @@ -1,9 +1,6 @@ package copy import ( - "encoding/base64" - "fmt" - "os" "strings" "charm.land/bubbles/v2/list" @@ -17,10 +14,6 @@ const ( popupH = 20 ) -func WriteClipboard(text string) { - encoded := base64.StdEncoding.EncodeToString([]byte(text)) - fmt.Fprintf(os.Stderr, "\033]52;c;%s\a", encoded) -} type OpenMsg struct { RawRequest string diff --git a/internal/ui/components/copy/update.go b/internal/ui/components/copy/update.go index d3a2914..d6f468b 100644 --- a/internal/ui/components/copy/update.go +++ b/internal/ui/components/copy/update.go @@ -4,16 +4,26 @@ import ( "charm.land/bubbles/v2/key" tea "charm.land/bubbletea/v2" "github.com/anotherhadi/spilltea/internal/keys" + notificationsUI "github.com/anotherhadi/spilltea/internal/ui/components/notifications" ) func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { if kp, ok := msg.(tea.KeyPressMsg); ok { switch { case kp.String() == "enter": - if item, ok := m.list.SelectedItem().(copyItem); ok { - WriteClipboard(m.extract(item.id)) - } m.open = false + if item, ok := m.list.SelectedItem().(copyItem); ok { + return m, tea.Batch( + tea.SetClipboard(m.extract(item.id)), + func() tea.Msg { + return notificationsUI.NotificationMsg{ + Title: "Copied", + Body: "Request copied to clipboard", + Kind: notificationsUI.KindSuccess, + } + }, + ) + } return m, nil case key.Matches(kp, keys.Keys.Global.Escape): if m.list.SettingFilter() { diff --git a/internal/ui/components/copyas/model.go b/internal/ui/components/copyas/model.go index 5cd449b..49e548a 100644 --- a/internal/ui/components/copyas/model.go +++ b/internal/ui/components/copyas/model.go @@ -1,10 +1,6 @@ package copyas import ( - "encoding/base64" - "fmt" - "os" - "charm.land/bubbles/v2/list" tea "charm.land/bubbletea/v2" "charm.land/lipgloss/v2" @@ -16,12 +12,6 @@ const ( popupH = 20 ) -// writeClipboard uses the OSC 52 terminal escape sequence to set the clipboard. -// Supported by most modern terminals (foot, kitty, wezterm, alacritty, xterm…). -func writeClipboard(text string) { - encoded := base64.StdEncoding.EncodeToString([]byte(text)) - fmt.Fprintf(os.Stderr, "\033]52;c;%s\a", encoded) -} type OpenMsg struct { RawRequest string diff --git a/internal/ui/components/copyas/update.go b/internal/ui/components/copyas/update.go index 05b6d14..3d08370 100644 --- a/internal/ui/components/copyas/update.go +++ b/internal/ui/components/copyas/update.go @@ -4,16 +4,26 @@ import ( "charm.land/bubbles/v2/key" tea "charm.land/bubbletea/v2" "github.com/anotherhadi/spilltea/internal/keys" + notificationsUI "github.com/anotherhadi/spilltea/internal/ui/components/notifications" ) func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { if kp, ok := msg.(tea.KeyPressMsg); ok { switch { case kp.String() == "enter": - if item, ok := m.list.SelectedItem().(formatItem); ok { - writeClipboard(formatAs(item.id, m.rawRequest, m.scheme)) - } m.open = false + if item, ok := m.list.SelectedItem().(formatItem); ok { + return m, tea.Batch( + tea.SetClipboard(formatAs(item.id, m.rawRequest, m.scheme)), + func() tea.Msg { + return notificationsUI.NotificationMsg{ + Title: "Copied", + Body: "Request copied to clipboard", + Kind: notificationsUI.KindSuccess, + } + }, + ) + } return m, nil case key.Matches(kp, keys.Keys.Global.Escape): if m.list.SettingFilter() {