Copy value to clipboard

This commit is contained in:
2026-01-23 16:43:44 -06:00
parent 0834792c57
commit 3f347d8342
4 changed files with 182 additions and 17 deletions

View File

@@ -32,6 +32,7 @@ import (
"github.com/bluesky-social/indigo/atproto/syntax"
"github.com/gdamore/tcell"
"github.com/spf13/viper"
"golang.design/x/clipboard"
)
type ScreenHome struct {
@@ -107,12 +108,24 @@ func (s *ScreenHome) Init(a *App) {
s.pdsListing.SetVimMode(viper.GetBool(data.KeyVimMode))
s.jsonContent = wd.NewJsonContent("jsoncontent", s.style)
brd := w.NewBorderedWidget("jsoncontentbrd", s.style, s.jsonContent)
brd.SetBorder(
km := s.jsonContent.GetKeyMap()
km.Add(
w.NewKey(w.BuildEK(tcell.KeyEnter), func(ev *tcell.EventKey) bool {
// Init returns an error if the package is not ready for use.
err := clipboard.Init()
if err != nil {
s.Log("Error initializing clipboard: %s", err.Error())
return true
}
clipboard.Write(clipboard.FmtText, []byte(s.jsonContent.GetSelectedValue()))
return true
}),
)
s.jsonContent.SetKeyMap(km)
s.jsonContent.SetBorder(
[]rune{'─', '┐', '│', '┘', '─', '─', ' ', '─', '├', '─', '┤', '┬', '│', '┴', '┼'},
)
s.columns.AddAll(s.pdsListing, brd)
s.columns.AddAll(s.pdsListing, s.jsonContent)
s.layout.AddAll(s.columns)
s.layout.SetWeight(s.columns, 4)
@@ -131,6 +144,10 @@ func (s *ScreenHome) HandleKey(ev *tcell.EventKey) bool {
return true
}
if s.doOpen {
if ev.Key() == tcell.KeyEscape {
s.doOpen = false
return true
}
if ev.Key() == tcell.KeyCtrlU {
s.openPdsEntry.SetValue("")
return true
@@ -328,8 +345,7 @@ func (s *ScreenHome) selectPdsListingEntry(idx int, nm string) bool {
return true
case models.TypeRecord:
// If signed in and we can edit this, activate jsonContent in 'editable' mode
s.jsonContent.SetEditable(true)
// If signed in and we can edit this, activate jsonContent
s.columns.ActivateWidget(s.jsonContent)
return true
}