From 6a2f4aaa3e07c356c1e6fc724d91bd5ba29eaccd Mon Sep 17 00:00:00 2001 From: Adrien Waksberg Date: Sun, 20 Oct 2019 22:14:50 +0200 Subject: [PATCH] feat: add clibboard --- gpm/cli.go | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/gpm/cli.go b/gpm/cli.go index cf9d2f4..c5072cf 100644 --- a/gpm/cli.go +++ b/gpm/cli.go @@ -9,6 +9,7 @@ import ( ui "github.com/gizak/termui/v3" "github.com/gizak/termui/v3/widgets" + "github.com/atotto/clipboard" ) // Options @@ -271,6 +272,7 @@ func (c *Cli) AddEntry() bool { func (c *Cli) ListEntries(ch chan<- bool) { var pattern, group string var entries []Entry + var selected bool refresh := true index := -1 @@ -297,15 +299,20 @@ func (c *Cli) ListEntries(ch chan<- bool) { } if len(entries) > 0 && index >= 0 && index < len(entries) { + selected = true + } else { + selected = false + } + + if selected { c.EntryBox(entries[index]) } ui.Render(l) e := <-uiEvents switch e.ID { - case "t": - c.ChoiceBox("test", false) case "q": + clipboard.WriteAll("") ch <- true case "": index = l.SelectedRow @@ -316,11 +323,11 @@ func (c *Cli) ListEntries(ch chan<- bool) { case "n": refresh = c.AddEntry() case "u": - if len(entries) > 0 && index >= 0 && index < len(entries) { + if selected { refresh = c.UpdateEntry(entries[index]) } case "d": - if len(entries) > 0 && index >= 0 && index < len(entries) { + if selected { refresh = c.DeleteEntry(entries[index]) } case "/": @@ -337,6 +344,20 @@ func (c *Cli) ListEntries(ch chan<- bool) { if len(entries) > 0 { l.ScrollUp() } + case "": + if selected { + clipboard.WriteAll(entries[index].User) + } + case "": + if selected { + clipboard.WriteAll(entries[index].Password) + } + case "": + if selected { + code, time, _ := entries[index].OTPCode() + c.NotificationBox(fmt.Sprintf("the OTP code is available for %d seconds", time), false) + clipboard.WriteAll(code) + } } } } @@ -429,7 +450,7 @@ func Run() { select { case <-c1: return - case <-time.After(10 * time.Second): + case <-time.After(300 * time.Second): return } }