feat: add select box for group in a form
This commit is contained in:
parent
0bf248d70e
commit
ce5563d989
1 changed files with 57 additions and 11 deletions
68
gpm/cli.go
68
gpm/cli.go
|
@ -114,6 +114,40 @@ func (c *Cli) InputBox(title string, input string, hidden bool) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SelectBox to select an item from a list
|
||||||
|
func (c *Cli) SelectBox(title string, items []string) string {
|
||||||
|
l := widgets.NewList()
|
||||||
|
l.Title = title
|
||||||
|
l.TextStyle = ui.NewStyle(ui.ColorYellow)
|
||||||
|
l.SelectedRowStyle = ui.NewStyle(ui.ColorGreen, ui.ColorClear, ui.ModifierBold)
|
||||||
|
l.WrapText = false
|
||||||
|
l.SetRect(10, 10, 70, 5)
|
||||||
|
l.Rows = items
|
||||||
|
|
||||||
|
uiEvents := ui.PollEvents()
|
||||||
|
for {
|
||||||
|
ui.Render(l)
|
||||||
|
e := <-uiEvents
|
||||||
|
switch e.ID {
|
||||||
|
case "q", "<C-c>", "<Escape>":
|
||||||
|
return ""
|
||||||
|
case "<Enter>":
|
||||||
|
if len(l.Rows) == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// EntryBox to add a new entry
|
// EntryBox to add a new entry
|
||||||
func (c *Cli) EntryBox(entry Entry) {
|
func (c *Cli) EntryBox(entry Entry) {
|
||||||
p := widgets.NewParagraph()
|
p := widgets.NewParagraph()
|
||||||
|
@ -139,7 +173,7 @@ func (c *Cli) GroupsBox() string {
|
||||||
l.TextStyle = ui.NewStyle(ui.ColorYellow)
|
l.TextStyle = ui.NewStyle(ui.ColorYellow)
|
||||||
l.SelectedRowStyle = ui.NewStyle(ui.ColorGreen, ui.ColorClear, ui.ModifierBold)
|
l.SelectedRowStyle = ui.NewStyle(ui.ColorGreen, ui.ColorClear, ui.ModifierBold)
|
||||||
l.WrapText = false
|
l.WrapText = false
|
||||||
l.SetRect(0, 0, 25, 23)
|
l.SetRect(25, 0, 80, 20)
|
||||||
l.Rows = append(c.Wallet.Groups(), "No group")
|
l.Rows = append(c.Wallet.Groups(), "No group")
|
||||||
|
|
||||||
uiEvents := ui.PollEvents()
|
uiEvents := ui.PollEvents()
|
||||||
|
@ -244,7 +278,14 @@ func (c *Cli) DeleteEntry(entry Entry) bool {
|
||||||
// UpdateEntry to update an existing entry
|
// UpdateEntry to update an existing entry
|
||||||
func (c *Cli) UpdateEntry(entry Entry) bool {
|
func (c *Cli) UpdateEntry(entry Entry) bool {
|
||||||
entry.Name = c.InputBox("Name", entry.Name, false)
|
entry.Name = c.InputBox("Name", entry.Name, false)
|
||||||
entry.Group = c.InputBox("Group", entry.Group, false)
|
if entry.Group == "" || c.ChoiceBox("Change the group ?", false) {
|
||||||
|
group := c.SelectBox("Group", append(c.Wallet.Groups(), "* Create new group *"))
|
||||||
|
if group == "* Create new group *" || group == "" {
|
||||||
|
entry.Group = c.InputBox("Group", "", false)
|
||||||
|
} else {
|
||||||
|
entry.Group = group
|
||||||
|
}
|
||||||
|
}
|
||||||
entry.URI = c.InputBox("URI", entry.URI, false)
|
entry.URI = c.InputBox("URI", entry.URI, false)
|
||||||
entry.User = c.InputBox("Username", entry.User, false)
|
entry.User = c.InputBox("Username", entry.User, false)
|
||||||
if c.ChoiceBox("Generate a new random password ?", false) {
|
if c.ChoiceBox("Generate a new random password ?", false) {
|
||||||
|
@ -275,7 +316,12 @@ func (c *Cli) AddEntry() bool {
|
||||||
entry := Entry{}
|
entry := Entry{}
|
||||||
entry.GenerateID()
|
entry.GenerateID()
|
||||||
entry.Name = c.InputBox("Name", "", false)
|
entry.Name = c.InputBox("Name", "", false)
|
||||||
entry.Group = c.InputBox("Group", "", false)
|
group := c.SelectBox("Group", append(c.Wallet.Groups(), "* Create new group *"))
|
||||||
|
if group == "* Create new group *" || group == "" {
|
||||||
|
entry.Group = c.InputBox("Group", "", false)
|
||||||
|
} else {
|
||||||
|
entry.Group = group
|
||||||
|
}
|
||||||
entry.URI = c.InputBox("URI", "", false)
|
entry.URI = c.InputBox("URI", "", false)
|
||||||
entry.User = c.InputBox("Username", "", false)
|
entry.User = c.InputBox("Username", "", false)
|
||||||
if c.ChoiceBox("Generate a random password ?", true) {
|
if c.ChoiceBox("Generate a random password ?", true) {
|
||||||
|
@ -309,7 +355,7 @@ func (c *Cli) ListEntries(ch chan<- bool) {
|
||||||
var selected bool
|
var selected bool
|
||||||
|
|
||||||
refresh := true
|
refresh := true
|
||||||
noGroup := false
|
noGroup := false
|
||||||
index := -1
|
index := -1
|
||||||
|
|
||||||
l := widgets.NewList()
|
l := widgets.NewList()
|
||||||
|
@ -327,7 +373,7 @@ func (c *Cli) ListEntries(ch chan<- bool) {
|
||||||
l.Title = "Group: No group"
|
l.Title = "Group: No group"
|
||||||
} else {
|
} else {
|
||||||
l.Title = "Group: All"
|
l.Title = "Group: All"
|
||||||
}
|
}
|
||||||
|
|
||||||
if refresh {
|
if refresh {
|
||||||
refresh = false
|
refresh = false
|
||||||
|
@ -338,7 +384,7 @@ func (c *Cli) ListEntries(ch chan<- bool) {
|
||||||
l.Rows = append(l.Rows, entry.Name)
|
l.Rows = append(l.Rows, entry.Name)
|
||||||
}
|
}
|
||||||
ui.Clear()
|
ui.Clear()
|
||||||
c.NotificationBox("press h to view short cuts", false)
|
c.NotificationBox("press h to view short cuts", false)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(entries) > 0 && index >= 0 && index < len(entries) {
|
if len(entries) > 0 && index >= 0 && index < len(entries) {
|
||||||
|
@ -381,11 +427,11 @@ func (c *Cli) ListEntries(ch chan<- bool) {
|
||||||
refresh = true
|
refresh = true
|
||||||
case "g":
|
case "g":
|
||||||
group = c.GroupsBox()
|
group = c.GroupsBox()
|
||||||
noGroup = false
|
noGroup = false
|
||||||
if group == "No group" {
|
if group == "No group" {
|
||||||
group = ""
|
group = ""
|
||||||
noGroup = true
|
noGroup = true
|
||||||
}
|
}
|
||||||
refresh = true
|
refresh = true
|
||||||
case "j", "<Down>":
|
case "j", "<Down>":
|
||||||
if len(entries) > 0 {
|
if len(entries) > 0 {
|
||||||
|
|
Loading…
Reference in a new issue