diff --git a/main.go b/main.go index 8ef6db6..9cdb18f 100644 --- a/main.go +++ b/main.go @@ -12,28 +12,34 @@ import ( var ( count time.Duration = 15 * time.Second str string = "" - p *widgets.Paragraph + p *widgets.Paragraph ) const ( playSound = true - timer = 15*time.Second + 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() } diff --git a/roflcopter/roflcopter.go b/roflcopter/roflcopter.go index 42d0e17..c88ed87 100644 --- a/roflcopter/roflcopter.go +++ b/roflcopter/roflcopter.go @@ -18,7 +18,7 @@ var swah []byte var ( work bool = true duration time.Duration - wg sync.WaitGroup + wg sync.WaitGroup ) const ( @@ -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)