From 9f0043786a51bdbdfd9f94efb079f1d8275d3735 Mon Sep 17 00:00:00 2001 From: Adrien Waksberg Date: Sun, 20 Oct 2019 17:47:50 +0200 Subject: [PATCH] feat: add timeout to close --- gpm/cli.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/gpm/cli.go b/gpm/cli.go index df404ba..a9ea530 100644 --- a/gpm/cli.go +++ b/gpm/cli.go @@ -3,6 +3,7 @@ package gpm import ( "fmt" "os" + "time" ui "github.com/gizak/termui/v3" "github.com/gizak/termui/v3/widgets" @@ -247,7 +248,7 @@ func (c *Cli) AddEntry() bool { return true } -func (c *Cli) ListEntries() { +func (c *Cli) ListEntries(ch chan<- bool) { var pattern, group string var entries []Entry @@ -284,8 +285,8 @@ func (c *Cli) ListEntries() { switch e.ID { case "t": c.ChoiceBox("test", false) - case "q", "": - return + case "q": + ch <- true case "": index = l.SelectedRow case "": @@ -337,5 +338,12 @@ func Run() { os.Exit(2) } - c.ListEntries() + c1 := make(chan bool) + go c.ListEntries(c1) + select { + case <-c1: + return + case <-time.After(10 * time.Second): + return + } }