Files
Hadi 624a723b16 init
Signed-off-by: Hadi <[email protected]>
2026-08-27 00:05:08 +02:00

62 lines
1.4 KiB
Go

package ui
import (
tea "charm.land/bubbletea/v2"
zone "github.com/lrstanley/bubblezone/v2"
"github.com/anotherhadi/ilovetui/notification"
"github.com/anotherhadi/default-creds-tui/internal/creds"
)
type copyField int
const (
fieldUser copyField = iota
fieldPass
)
func (m Model) updateMouseClick(msg tea.MouseClickMsg) (Model, tea.Cmd) {
if zone.Get(searchBoxZone).InBounds(msg) {
m.searching = true
return m, m.searchInput.Focus()
}
items := m.list.VisibleItems()
for i, item := range items {
e := item.(creds.Entry)
switch {
case zone.Get(entryUserZoneID(i)).InBounds(msg):
return m, copyEntryField(e, fieldUser)
case zone.Get(entryPassZoneID(i)).InBounds(msg):
return m, copyEntryField(e, fieldPass)
case zone.Get(entryZoneID(i)).InBounds(msg):
m.list.Select(i)
return m, nil
}
}
return m, nil
}
func (m Model) copySelected(field copyField) tea.Cmd {
e, ok := m.selectedEntry()
if !ok {
return nil
}
return copyEntryField(e, field)
}
func copyEntryField(e creds.Entry, field copyField) tea.Cmd {
label, value := "username", e.User
if field == fieldPass {
label, value = "password", e.Pass
}
if value == "" {
return notification.Show("Copy", "No "+label+" set for '"+e.Name+"'.", notification.Warning)
}
return tea.Batch(
tea.SetClipboard(value),
notification.Show("Copied", "'"+e.Name+"' "+label+" copied to clipboard.", notification.Success),
)
}