Copy func in findings

Signed-off-by: Hadi <112569860+anotherhadi@users.noreply.github.com>
This commit is contained in:
Hadi
2026-05-19 21:29:41 +02:00
parent 87fa9448d6
commit 3463e51739
7 changed files with 20 additions and 7 deletions
+6
View File
@@ -209,6 +209,12 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, nil return m, nil
case key.Matches(msg, keys.Keys.Global.Copy): 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 raw, scheme string
var responseFocused bool var responseFocused bool
switch m.page { switch m.page {
+1 -1
View File
@@ -17,7 +17,7 @@ const (
popupH = 20 popupH = 20
) )
func writeClipboard(text string) { func WriteClipboard(text string) {
encoded := base64.StdEncoding.EncodeToString([]byte(text)) encoded := base64.StdEncoding.EncodeToString([]byte(text))
fmt.Fprintf(os.Stderr, "\033]52;c;%s\a", encoded) fmt.Fprintf(os.Stderr, "\033]52;c;%s\a", encoded)
} }
+1 -1
View File
@@ -11,7 +11,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
switch { switch {
case kp.String() == "enter": case kp.String() == "enter":
if item, ok := m.list.SelectedItem().(copyItem); ok { if item, ok := m.list.SelectedItem().(copyItem); ok {
writeClipboard(m.extract(item.id)) WriteClipboard(m.extract(item.id))
} }
m.open = false m.open = false
return m, nil return m, nil
+10 -2
View File
@@ -46,6 +46,14 @@ func New() Model {
func (m Model) Init() tea.Cmd { return nil } 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) { func (m *Model) SetDB(d *db.DB) {
m.database = d m.database = d
} }
@@ -174,12 +182,12 @@ type findingsKeyMap struct{ width int }
func (findingsKeyMap) ShortHelp() []key.Binding { func (findingsKeyMap) ShortHelp() []key.Binding {
g := keys.Keys.Global g := keys.Keys.Global
f := keys.Keys.Findings 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 { func (m findingsKeyMap) FullHelp() [][]key.Binding {
g := keys.Keys.Global 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(keys.Keys.Findings.Bindings(), pageGlobals...)
all = append(all, g.CommonBindings()...) all = append(all, g.CommonBindings()...)
return keys.ChunkByWidth(all, m.width) return keys.ChunkByWidth(all, m.width)
-1
View File
@@ -171,7 +171,6 @@ type Model struct {
teapotFrame int teapotFrame int
} }
func New(projectDir string) Model { func New(projectDir string) Model {
projects := loadProjects(projectDir) projects := loadProjects(projectDir)
+1 -1
View File
@@ -37,7 +37,7 @@ type Entry struct {
type panel int type panel int
const ( const (
panelList panel = iota panelList panel = iota
panelRequest panelRequest
panelResponse panelResponse
) )
+1 -1
View File
@@ -16,12 +16,12 @@ import (
tea "charm.land/bubbletea/v2" tea "charm.land/bubbletea/v2"
"charm.land/lipgloss/v2" "charm.land/lipgloss/v2"
"github.com/andybalholm/brotli" "github.com/andybalholm/brotli"
"github.com/klauspost/compress/zstd"
"github.com/anotherhadi/spilltea/internal/config" "github.com/anotherhadi/spilltea/internal/config"
"github.com/anotherhadi/spilltea/internal/db" "github.com/anotherhadi/spilltea/internal/db"
"github.com/anotherhadi/spilltea/internal/keys" "github.com/anotherhadi/spilltea/internal/keys"
"github.com/anotherhadi/spilltea/internal/style" "github.com/anotherhadi/spilltea/internal/style"
"github.com/anotherhadi/spilltea/internal/util" "github.com/anotherhadi/spilltea/internal/util"
"github.com/klauspost/compress/zstd"
) )
type sentMsg struct { type sentMsg struct {