From 3463e5173934179d7b4400dbd4e230b6fd834e74 Mon Sep 17 00:00:00 2001 From: Hadi <112569860+anotherhadi@users.noreply.github.com> Date: Tue, 19 May 2026 21:29:41 +0200 Subject: [PATCH] Copy func in findings Signed-off-by: Hadi <112569860+anotherhadi@users.noreply.github.com> --- internal/ui/app/update.go | 6 ++++++ internal/ui/components/copy/model.go | 2 +- internal/ui/components/copy/update.go | 2 +- internal/ui/findings/model.go | 12 ++++++++++-- internal/ui/home/model.go | 1 - internal/ui/replay/model.go | 2 +- internal/ui/replay/update.go | 2 +- 7 files changed, 20 insertions(+), 7 deletions(-) diff --git a/internal/ui/app/update.go b/internal/ui/app/update.go index f75cee8..f7f3c1f 100644 --- a/internal/ui/app/update.go +++ b/internal/ui/app/update.go @@ -209,6 +209,12 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, nil case key.Matches(msg, keys.Keys.Global.Copy): + if m.page == pageFindings { + if md := m.findingsPage.CurrentMarkdown(); md != "" { + copyUI.WriteClipboard(md) + } + return m, nil + } var raw, scheme string var responseFocused bool switch m.page { diff --git a/internal/ui/components/copy/model.go b/internal/ui/components/copy/model.go index 48e57ba..ab27401 100644 --- a/internal/ui/components/copy/model.go +++ b/internal/ui/components/copy/model.go @@ -17,7 +17,7 @@ const ( popupH = 20 ) -func writeClipboard(text string) { +func WriteClipboard(text string) { encoded := base64.StdEncoding.EncodeToString([]byte(text)) fmt.Fprintf(os.Stderr, "\033]52;c;%s\a", encoded) } diff --git a/internal/ui/components/copy/update.go b/internal/ui/components/copy/update.go index c7fa952..d3a2914 100644 --- a/internal/ui/components/copy/update.go +++ b/internal/ui/components/copy/update.go @@ -11,7 +11,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { switch { case kp.String() == "enter": if item, ok := m.list.SelectedItem().(copyItem); ok { - writeClipboard(m.extract(item.id)) + WriteClipboard(m.extract(item.id)) } m.open = false return m, nil diff --git a/internal/ui/findings/model.go b/internal/ui/findings/model.go index fe96889..ae2a872 100644 --- a/internal/ui/findings/model.go +++ b/internal/ui/findings/model.go @@ -46,6 +46,14 @@ func New() Model { func (m Model) Init() tea.Cmd { return nil } +func (m *Model) CurrentMarkdown() string { + if len(m.findings) == 0 { + return "" + } + f := m.findings[m.cursor] + return "# " + f.Title + "\n\n" + f.Description +} + func (m *Model) SetDB(d *db.DB) { m.database = d } @@ -174,12 +182,12 @@ type findingsKeyMap struct{ width int } func (findingsKeyMap) ShortHelp() []key.Binding { g := keys.Keys.Global f := keys.Keys.Findings - return []key.Binding{g.Up, g.Down, f.Dismiss, g.Help} + return []key.Binding{g.Up, g.Down, f.Dismiss, g.Copy, g.Help} } func (m findingsKeyMap) FullHelp() [][]key.Binding { g := keys.Keys.Global - pageGlobals := []key.Binding{g.Up, g.Down, g.ScrollUp, g.ScrollDown} + pageGlobals := []key.Binding{g.Up, g.Down, g.ScrollUp, g.ScrollDown, g.Copy} all := append(keys.Keys.Findings.Bindings(), pageGlobals...) all = append(all, g.CommonBindings()...) return keys.ChunkByWidth(all, m.width) diff --git a/internal/ui/home/model.go b/internal/ui/home/model.go index eb7d27c..8b237a1 100644 --- a/internal/ui/home/model.go +++ b/internal/ui/home/model.go @@ -171,7 +171,6 @@ type Model struct { teapotFrame int } - func New(projectDir string) Model { projects := loadProjects(projectDir) diff --git a/internal/ui/replay/model.go b/internal/ui/replay/model.go index a413dfd..f924209 100644 --- a/internal/ui/replay/model.go +++ b/internal/ui/replay/model.go @@ -37,7 +37,7 @@ type Entry struct { type panel int const ( - panelList panel = iota + panelList panel = iota panelRequest panelResponse ) diff --git a/internal/ui/replay/update.go b/internal/ui/replay/update.go index b7f91aa..b0a7f44 100644 --- a/internal/ui/replay/update.go +++ b/internal/ui/replay/update.go @@ -16,12 +16,12 @@ import ( tea "charm.land/bubbletea/v2" "charm.land/lipgloss/v2" "github.com/andybalholm/brotli" - "github.com/klauspost/compress/zstd" "github.com/anotherhadi/spilltea/internal/config" "github.com/anotherhadi/spilltea/internal/db" "github.com/anotherhadi/spilltea/internal/keys" "github.com/anotherhadi/spilltea/internal/style" "github.com/anotherhadi/spilltea/internal/util" + "github.com/klauspost/compress/zstd" ) type sentMsg struct {