Create tiny counter within quit view

This commit is contained in:
raul 2024-04-09 20:16:30 +02:00
parent 01e9e7e2db
commit 226ff03093
1 changed files with 33 additions and 5 deletions

View File

@ -1,7 +1,7 @@
package main package main
import ( import (
"bytes" //"bytes"
"fmt" "fmt"
"io" "io"
"log" "log"
@ -10,6 +10,7 @@ import (
"time" "time"
"github.com/jroimartin/gocui" "github.com/jroimartin/gocui"
"github.com/nsf/termbox-go"
) )
var input chan string var input chan string
@ -42,6 +43,7 @@ func counter() {
for { for {
numToIncrease++ numToIncrease++
time.Sleep(time.Second) time.Sleep(time.Second)
termbox.Interrupt()
} }
} }
@ -73,12 +75,35 @@ func layout(g *gocui.Gui) error {
return err return err
} }
v.Title = "Quit button" v.Title = "Quit button"
fmt.Fprintln(v, "You should quit... NOW!", numToIncrease) fmt.Fprintln(v, "Quit")
go func() { go func() {
message := <-input for {
formattedMsg := bytes.NewBufferString(message) fmt.Fprintf(v, "\r%v", numToIncrease)
fmt.Fprintln(formattedMsg) 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 return nil
} }
@ -117,6 +142,9 @@ func initKeybindings(g *gocui.Gui) error {
strings.TrimRight(buf.String(), "\n") strings.TrimRight(buf.String(), "\n")
cmd := exec.Command("notify-send", strings.TrimRight(buf.String(), "\n")) cmd := exec.Command("notify-send", strings.TrimRight(buf.String(), "\n"))
cmd.Run() cmd.Run()
go func(buf *strings.Builder) {
input <- buf.String()
}(buf)
return nil return nil
}); err != nil { }); err != nil {
return err return err