feat: add timeout to close

This commit is contained in:
Adrien Waksberg 2019-10-20 17:47:50 +02:00
parent 20b4334759
commit 9f0043786a

View file

@ -3,6 +3,7 @@ package gpm
import ( import (
"fmt" "fmt"
"os" "os"
"time"
ui "github.com/gizak/termui/v3" ui "github.com/gizak/termui/v3"
"github.com/gizak/termui/v3/widgets" "github.com/gizak/termui/v3/widgets"
@ -247,7 +248,7 @@ func (c *Cli) AddEntry() bool {
return true return true
} }
func (c *Cli) ListEntries() { func (c *Cli) ListEntries(ch chan<- bool) {
var pattern, group string var pattern, group string
var entries []Entry var entries []Entry
@ -284,8 +285,8 @@ func (c *Cli) ListEntries() {
switch e.ID { switch e.ID {
case "t": case "t":
c.ChoiceBox("test", false) c.ChoiceBox("test", false)
case "q", "<C-c>": case "q":
return ch <- true
case "<Enter>": case "<Enter>":
index = l.SelectedRow index = l.SelectedRow
case "<Escape>": case "<Escape>":
@ -337,5 +338,12 @@ func Run() {
os.Exit(2) os.Exit(2)
} }
c.ListEntries() c1 := make(chan bool)
go c.ListEntries(c1)
select {
case <-c1:
return
case <-time.After(10 * time.Second):
return
}
} }