fix terminal render

This commit is contained in:
Морозов Андрей 2022-02-12 20:30:38 +04:00
parent 1024f75332
commit d238897080
2 changed files with 30 additions and 23 deletions

18
main.go
View File

@ -20,20 +20,26 @@ const (
timer = 15 * time.Second
)
func updateScreen() {
func prepareScreen() {
if err := ui.Init(); err != nil {
log.Fatalf("failed to initialize termui: %v", err)
}
defer ui.Close()
//defer ui.Close()
p = widgets.NewParagraph()
p.Text = str
p.SetRect(0, 0, 25, 10)
ui.Render(p)
}
func updateScreen() {
p.Text = str
p.SetRect(0, 0, 25, 12)
ui.Render(p)
}
func main() {
p = widgets.NewParagraph()
prepareScreen()
rofl := roflcopter.NewRoflcopter(timer, &str, playSound, updateScreen)
rofl.Start()
time.Sleep(timer)
time.Sleep(timer + 500*time.Millisecond)
ui.Close()
}

View File

@ -44,14 +44,6 @@ func NewRoflcopter(amount time.Duration, outStr *string, out bool, funcrunner fu
}
}
func (b *Roflcopter) timecounter(step time.Duration) {
for b.count > 0 {
b.count -= step
time.Sleep(step)
}
work = false
}
func (b *Roflcopter) Start() {
*b.str = frame1 + b.count.String()
work = b.work
@ -59,9 +51,18 @@ func (b *Roflcopter) Start() {
if b.output {
go b.player()
}
go b.timecounter(1 * time.Second)
go b.frameChanger(120 * time.Millisecond)
go b.timecounter(500 * time.Millisecond)
go b.frameChanger(125 * time.Millisecond)
}
func (b *Roflcopter) timecounter(step time.Duration) {
for b.count >= 0 {
b.count -= step
time.Sleep(step)
}
work = false
}
func (b *Roflcopter) player() {
b.sound()
wg.Wait()
@ -69,31 +70,31 @@ func (b *Roflcopter) player() {
}
func (b *Roflcopter) frameChanger(delay time.Duration) {
b.runner()
nextframe := 2
for work {
switch nextframe {
case 1:
{
*b.str = frame1 + b.count.String()
*b.str = frame1 + "Ends in " + b.count.String()
time.Sleep(delay)
nextframe = 2
}
case 2:
{
*b.str = frame2 + b.count.String()
*b.str = frame2 + "Ends in " + b.count.String()
time.Sleep(delay)
nextframe = 1
}
}
b.runner()
}
}
func (b *Roflcopter) sound() {
wg.Add(1)
t := 1*time.Second + 390*time.Millisecond
t := 1*time.Second + 380*time.Millisecond
streamer, format, err := mp3.Decode(io.NopCloser(bytes.NewReader(swah)))
if err != nil {
log.Fatal(err)