feat: add choice box

This commit is contained in:
Adrien Waksberg 2019-10-20 16:03:26 +02:00
parent 00336289c4
commit d055cc34ec

View file

@ -27,6 +27,32 @@ func (c *Cli) NotificationBox(msg string, error bool) {
ui.Render(p) ui.Render(p)
} }
func (c *Cli) ChoiceBox(title string, choice bool) bool {
t := widgets.NewTabPane("Yes", "No")
t.SetRect(10, 10, 70, 5)
t.Title = title
t.Border = true
if !choice {
t.ActiveTabIndex = 1
}
uiEvents := ui.PollEvents()
for {
ui.Render(t)
e := <-uiEvents
switch e.ID {
case "<Enter>":
return choice
case "<Left>", "h":
t.FocusLeft()
choice = true
case "<Right>", "l":
t.FocusRight()
choice = false
}
}
}
func (c *Cli) InputBox(title string, input string, hidden bool) string { func (c *Cli) InputBox(title string, input string, hidden bool) string {
var secret string var secret string
@ -147,6 +173,10 @@ func (c *Cli) UpdateEntry(entry Entry) bool {
entry.Group = c.InputBox("Group", entry.Group, false) entry.Group = c.InputBox("Group", entry.Group, false)
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) {
entry.Password = RandomString(c.Config.PasswordLength,
c.Config.PasswordLetter, c.Config.PasswordDigit, c.Config.PasswordSpecial)
}
entry.Password = c.InputBox("Password", "", true) entry.Password = c.InputBox("Password", "", true)
entry.OTP = c.InputBox("OTP Key", entry.OTP, false) entry.OTP = c.InputBox("OTP Key", entry.OTP, false)
entry.Comment = c.InputBox("Comment", entry.Comment, false) entry.Comment = c.InputBox("Comment", entry.Comment, false)
@ -173,7 +203,12 @@ func (c *Cli) AddEntry() bool {
entry.Group = c.InputBox("Group", "", false) entry.Group = c.InputBox("Group", "", false)
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) {
entry.Password = RandomString(c.Config.PasswordLength,
c.Config.PasswordLetter, c.Config.PasswordDigit, c.Config.PasswordSpecial)
} else {
entry.Password = c.InputBox("Password", "", true) entry.Password = c.InputBox("Password", "", true)
}
entry.OTP = c.InputBox("OTP Key", "", false) entry.OTP = c.InputBox("OTP Key", "", false)
entry.Comment = c.InputBox("Comment", "", false) entry.Comment = c.InputBox("Comment", "", false)
@ -227,6 +262,8 @@ func (c *Cli) ListEntries() {
ui.Render(l) ui.Render(l)
e := <-uiEvents e := <-uiEvents
switch e.ID { switch e.ID {
case "t":
c.ChoiceBox("test", false)
case "q", "<C-c>": case "q", "<C-c>":
return return
case "<Enter>": case "<Enter>":