go-roflcopter/main.go

50 lines
827 B
Go
Raw Permalink Normal View History

2021-12-12 02:12:56 +03:00
package main
import (
2022-02-12 20:14:24 +03:00
"fmt"
2022-02-12 02:12:00 +03:00
"log"
2021-12-12 02:12:56 +03:00
"time"
2022-02-12 02:12:00 +03:00
ui "github.com/gizak/termui/v3"
"github.com/gizak/termui/v3/widgets"
"morozovad.ddns.net/lnd212/go-roflcopter/roflcopter"
)
var (
2022-02-12 20:14:24 +03:00
str string = ""
p *widgets.Paragraph
2022-02-12 02:12:00 +03:00
)
const (
playSound = true
2022-02-12 20:14:24 +03:00
timer = 5 * time.Second
2021-12-12 02:12:56 +03:00
)
2022-02-12 19:30:38 +03:00
func prepareScreen() {
2022-02-12 02:12:00 +03:00
if err := ui.Init(); err != nil {
log.Fatalf("failed to initialize termui: %v", err)
}
2022-02-12 19:30:38 +03:00
p = widgets.NewParagraph()
p.Text = str
p.SetRect(0, 0, 25, 10)
ui.Render(p)
}
2022-02-12 02:12:00 +03:00
2022-02-12 19:30:38 +03:00
func updateScreen() {
p.Text = str
2022-02-12 02:12:00 +03:00
ui.Render(p)
2021-12-12 02:12:56 +03:00
}
func main() {
2022-02-12 20:14:24 +03:00
fmt.Println("Playing only sound for 5s")
rofl := roflcopter.NewRoflcopter(timer, &str, updateScreen)
wg := rofl.OnlySound()
wg.Wait()
time.Sleep(500 * time.Millisecond)
2022-02-12 19:30:38 +03:00
prepareScreen()
2022-02-12 20:14:24 +03:00
wg = rofl.Start(playSound)
wg.Wait()
time.Sleep(500 * time.Millisecond)
2022-02-12 19:30:38 +03:00
ui.Close()
2021-12-12 02:12:56 +03:00
}