Skip to content

Commit

Permalink
countDown
Browse files Browse the repository at this point in the history
  • Loading branch information
drgrib committed Mar 18, 2017
1 parent b6bd329 commit 7d05f5d
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions ttimer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func panicErr(err error) {
//////////////////////////////////////////////

type Timer struct {
title string
duration time.Duration
end time.Time
status string
Expand All @@ -43,12 +44,7 @@ func (t *Timer) update() {
}
}

//////////////////////////////////////////////
/// main
//////////////////////////////////////////////

func main() {

func (t *Timer) countDown() {
// init and close
err := ui.Init()
panicErr(err)
Expand All @@ -63,19 +59,14 @@ func main() {
cell.Width = 26
cell.Height = 2

// start timer
timer := Timer{}
d := time.Duration(6 * time.Second)
timer.start(d)

// draw
banner := "== Time =="
draw := func(t int) {
timer.update()
banner := fmt.Sprintf("== %s ==", t.title)
draw := func(tick int) {
t.update()
// render
cell.Text = fmt.Sprintf("%s\n%v",
banner,
timer.status)
t.status)
ui.Render(cell)
}

Expand All @@ -85,8 +76,8 @@ func main() {
ui.Merge("timer", ui.NewTimerCh(
time.Duration(ms)*time.Millisecond))
ui.Handle(timerPath, func(e ui.Event) {
t := e.Data.(ui.EvtTimer)
draw(int(t.Count))
tick := e.Data.(ui.EvtTimer)
draw(int(tick.Count))
})

// handle quit
Expand All @@ -97,3 +88,18 @@ func main() {
// start loop
ui.Loop()
}

//////////////////////////////////////////////
/// main
//////////////////////////////////////////////

func main() {

// start timer
timer := Timer{title: "Timer"}
d := time.Duration(6 * time.Second)
timer.start(d)

// run UI
timer.countDown()
}

0 comments on commit 7d05f5d

Please sign in to comment.