mirror of
https://github.com/anotherhadi/spilltea.git
synced 2026-05-20 01:32:33 +02:00
edit write clipboard
Signed-off-by: Hadi <112569860+anotherhadi@users.noreply.github.com>
This commit is contained in:
@@ -211,14 +211,16 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
case key.Matches(msg, keys.Keys.Global.Copy):
|
case key.Matches(msg, keys.Keys.Global.Copy):
|
||||||
if m.page == pageFindings {
|
if m.page == pageFindings {
|
||||||
if md := m.findingsPage.CurrentMarkdown(); md != "" {
|
if md := m.findingsPage.CurrentMarkdown(); md != "" {
|
||||||
copyUI.WriteClipboard(md)
|
return m, tea.Batch(
|
||||||
return m, func() tea.Msg {
|
tea.SetClipboard(md),
|
||||||
return notificationsUI.NotificationMsg{
|
func() tea.Msg {
|
||||||
Title: "Copied",
|
return notificationsUI.NotificationMsg{
|
||||||
Body: "Finding copied to clipboard",
|
Title: "Copied",
|
||||||
Kind: notificationsUI.KindSuccess,
|
Body: "Finding copied to clipboard",
|
||||||
}
|
Kind: notificationsUI.KindSuccess,
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
package copy
|
package copy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"charm.land/bubbles/v2/list"
|
"charm.land/bubbles/v2/list"
|
||||||
@@ -17,10 +14,6 @@ const (
|
|||||||
popupH = 20
|
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 {
|
type OpenMsg struct {
|
||||||
RawRequest string
|
RawRequest string
|
||||||
|
|||||||
@@ -4,16 +4,26 @@ import (
|
|||||||
"charm.land/bubbles/v2/key"
|
"charm.land/bubbles/v2/key"
|
||||||
tea "charm.land/bubbletea/v2"
|
tea "charm.land/bubbletea/v2"
|
||||||
"github.com/anotherhadi/spilltea/internal/keys"
|
"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) {
|
func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
|
||||||
if kp, ok := msg.(tea.KeyPressMsg); ok {
|
if kp, ok := msg.(tea.KeyPressMsg); ok {
|
||||||
switch {
|
switch {
|
||||||
case kp.String() == "enter":
|
case kp.String() == "enter":
|
||||||
if item, ok := m.list.SelectedItem().(copyItem); ok {
|
|
||||||
WriteClipboard(m.extract(item.id))
|
|
||||||
}
|
|
||||||
m.open = false
|
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
|
return m, nil
|
||||||
case key.Matches(kp, keys.Keys.Global.Escape):
|
case key.Matches(kp, keys.Keys.Global.Escape):
|
||||||
if m.list.SettingFilter() {
|
if m.list.SettingFilter() {
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
package copyas
|
package copyas
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"charm.land/bubbles/v2/list"
|
"charm.land/bubbles/v2/list"
|
||||||
tea "charm.land/bubbletea/v2"
|
tea "charm.land/bubbletea/v2"
|
||||||
"charm.land/lipgloss/v2"
|
"charm.land/lipgloss/v2"
|
||||||
@@ -16,12 +12,6 @@ const (
|
|||||||
popupH = 20
|
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 {
|
type OpenMsg struct {
|
||||||
RawRequest string
|
RawRequest string
|
||||||
|
|||||||
@@ -4,16 +4,26 @@ import (
|
|||||||
"charm.land/bubbles/v2/key"
|
"charm.land/bubbles/v2/key"
|
||||||
tea "charm.land/bubbletea/v2"
|
tea "charm.land/bubbletea/v2"
|
||||||
"github.com/anotherhadi/spilltea/internal/keys"
|
"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) {
|
func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
|
||||||
if kp, ok := msg.(tea.KeyPressMsg); ok {
|
if kp, ok := msg.(tea.KeyPressMsg); ok {
|
||||||
switch {
|
switch {
|
||||||
case kp.String() == "enter":
|
case kp.String() == "enter":
|
||||||
if item, ok := m.list.SelectedItem().(formatItem); ok {
|
|
||||||
writeClipboard(formatAs(item.id, m.rawRequest, m.scheme))
|
|
||||||
}
|
|
||||||
m.open = false
|
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
|
return m, nil
|
||||||
case key.Matches(kp, keys.Keys.Global.Escape):
|
case key.Matches(kp, keys.Keys.Global.Escape):
|
||||||
if m.list.SettingFilter() {
|
if m.list.SettingFilter() {
|
||||||
|
|||||||
Reference in New Issue
Block a user