feat: add group filter
This commit is contained in:
parent
6c30928065
commit
d4dee06902
3 changed files with 60 additions and 1 deletions
26
gpm/cli.go
26
gpm/cli.go
|
@ -109,7 +109,33 @@ func (c *Cli) UnlockWallet(wallet string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cli) GroupsBox() string {
|
func (c *Cli) GroupsBox() string {
|
||||||
|
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", "<C-c>", "<Escape>":
|
||||||
return ""
|
return ""
|
||||||
|
case "<Enter>":
|
||||||
|
return l.Rows[l.SelectedRow]
|
||||||
|
case "j", "<Down>":
|
||||||
|
if len(l.Rows) > 0 {
|
||||||
|
l.ScrollDown()
|
||||||
|
}
|
||||||
|
case "k", "<Up>":
|
||||||
|
if len(l.Rows) > 0 {
|
||||||
|
l.ScrollUp()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cli) ListEntries() {
|
func (c *Cli) ListEntries() {
|
||||||
|
|
|
@ -103,6 +103,28 @@ func (w *Wallet) Save() error {
|
||||||
return nil
|
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
|
// SearchEntry return an array with the array expected with the pattern
|
||||||
func (w *Wallet) SearchEntry(pattern string, group string) []Entry {
|
func (w *Wallet) SearchEntry(pattern string, group string) []Entry {
|
||||||
var entries []Entry
|
var entries []Entry
|
||||||
|
|
|
@ -233,3 +233,14 @@ func TestLoadWalletWithBadPassword(t *testing.T) {
|
||||||
t.Errorf("must have 0 entries: %d", entries)
|
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])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue