From 226ff0309345cb99b66649a51a11ecfb90558926 Mon Sep 17 00:00:00 2001 From: raul Date: Tue, 9 Apr 2024 20:16:30 +0200 Subject: [PATCH] Create tiny counter within quit view --- gocui-practice/main.go | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/gocui-practice/main.go b/gocui-practice/main.go index 08cd258..b9a4982 100644 --- a/gocui-practice/main.go +++ b/gocui-practice/main.go @@ -1,7 +1,7 @@ package main import ( - "bytes" + //"bytes" "fmt" "io" "log" @@ -10,6 +10,7 @@ import ( "time" "github.com/jroimartin/gocui" + "github.com/nsf/termbox-go" ) var input chan string @@ -42,6 +43,7 @@ func counter() { for { numToIncrease++ time.Sleep(time.Second) + termbox.Interrupt() } } @@ -73,12 +75,35 @@ func layout(g *gocui.Gui) error { return err } v.Title = "Quit button" - fmt.Fprintln(v, "You should quit... NOW!", numToIncrease) + fmt.Fprintln(v, "Quit") go func() { - message := <-input - formattedMsg := bytes.NewBufferString(message) - fmt.Fprintln(formattedMsg) + for { + fmt.Fprintf(v, "\r%v", numToIncrease) + time.Sleep(time.Second) + } }() + go func() { + for { + time.Sleep(time.Second) + fmt.Fprintln(v, "Henlo") + termbox.Interrupt() + + msg := <-input + fmt.Fprintln(v, msg) + termbox.Interrupt() + } + }() + // go func(v *gocui.View) { + // for { + // message := <-input + // v.Clear() + // fmt.Println(message) + // // formattedMsg := bytes.NewBufferString(message) + // // cmd := exec.Command("notify-send", formattedMsg.String()) + // // cmd.Run() + // // fmt.Fprintln(v, formattedMsg) + // } + // }(v) } return nil } @@ -117,6 +142,9 @@ func initKeybindings(g *gocui.Gui) error { strings.TrimRight(buf.String(), "\n") cmd := exec.Command("notify-send", strings.TrimRight(buf.String(), "\n")) cmd.Run() + go func(buf *strings.Builder) { + input <- buf.String() + }(buf) return nil }); err != nil { return err