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
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