go-roflcopter/main.go

50 lines
827 B
Go

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