diff --git a/gpm/cli.go b/gpm/cli.go index 49c25ed..b10ba33 100644 --- a/gpm/cli.go +++ b/gpm/cli.go @@ -109,7 +109,33 @@ func (c *Cli) UnlockWallet(wallet string) error { } func (c *Cli) GroupsBox() string { - return "" + l := widgets.NewList() + l.Title = "Groups" + l.TextStyle = ui.NewStyle(ui.ColorYellow) + l.SelectedRowStyle = ui.NewStyle(ui.ColorGreen, ui.ColorClear, ui.ModifierBold) + l.WrapText = false + l.SetRect(0, 0, 25, 23) + l.Rows = c.Wallet.Groups() + + uiEvents := ui.PollEvents() + for { + ui.Render(l) + e := <-uiEvents + switch e.ID { + case "q", "", "": + return "" + case "": + return l.Rows[l.SelectedRow] + case "j", "": + if len(l.Rows) > 0 { + l.ScrollDown() + } + case "k", "": + if len(l.Rows) > 0 { + l.ScrollUp() + } + } + } } func (c *Cli) ListEntries() { diff --git a/gpm/wallet.go b/gpm/wallet.go index 6becff6..6d4d73b 100644 --- a/gpm/wallet.go +++ b/gpm/wallet.go @@ -103,6 +103,28 @@ func (w *Wallet) Save() error { return nil } +// Groups return array with the groups name +func (w *Wallet) Groups() []string { + var groups []string + var exist bool + + for _, entry := range w.Entries { + exist = false + for _, group := range groups { + if group == entry.Group { + exist = true + break + } + } + + if exist == false { + groups = append(groups, entry.Group) + } + } + + return groups +} + // SearchEntry return an array with the array expected with the pattern func (w *Wallet) SearchEntry(pattern string, group string) []Entry { var entries []Entry diff --git a/gpm/wallet_test.go b/gpm/wallet_test.go index c66fb96..72384fd 100644 --- a/gpm/wallet_test.go +++ b/gpm/wallet_test.go @@ -233,3 +233,14 @@ func TestLoadWalletWithBadPassword(t *testing.T) { t.Errorf("must have 0 entries: %d", entries) } } + +func TestGetGroup(t *testing.T) { + wallet := generateWalletWithEntries() + groups := wallet.Groups() + if len(groups) != 1 { + t.Errorf("there must have 1 group: %d", len(groups)) + } + if groups[0] != "Good Group" { + t.Errorf("the group name isn't 'Good Group': %s", groups[0]) + } +}