add cool ascii spinner
This commit is contained in:
parent
782bd5956a
commit
b5042fdbeb
5
task.go
5
task.go
|
@ -17,7 +17,8 @@ import (
|
|||
func display(writer io.Writer, msg Message) {
|
||||
fmt.Fprintf(
|
||||
writer,
|
||||
"%s remaining [ pomodoro %d/%d ]\n",
|
||||
"%s %s remaining [ pomodoro %d/%d ]\n",
|
||||
msg.Wheel,
|
||||
(msg.Duration - time.Since(msg.Start)).Truncate(time.Second),
|
||||
msg.CurrentPomodoro,
|
||||
msg.Pomodoros,
|
||||
|
@ -31,6 +32,7 @@ func run(task Task, prompter Prompter, db *Store) {
|
|||
writer.Start()
|
||||
ticker := time.NewTicker(RefreshInterval)
|
||||
timer := time.NewTimer(task.duration)
|
||||
wheel := &Wheel{}
|
||||
var p int
|
||||
for p < task.pomodoros {
|
||||
pomodoro := &Pomodoro{}
|
||||
|
@ -44,6 +46,7 @@ func run(task Task, prompter Prompter, db *Store) {
|
|||
Start: pomodoro.Start,
|
||||
Duration: task.duration,
|
||||
Pomodoros: task.pomodoros,
|
||||
Wheel: wheel,
|
||||
CurrentPomodoro: p,
|
||||
})
|
||||
goto loop
|
||||
|
|
24
types.go
24
types.go
|
@ -20,6 +20,30 @@ type Message struct {
|
|||
Duration time.Duration
|
||||
Pomodoros int
|
||||
CurrentPomodoro int
|
||||
Wheel *Wheel
|
||||
}
|
||||
|
||||
// Wheel keeps track of an ASCII spinner
|
||||
type Wheel struct {
|
||||
state int
|
||||
}
|
||||
|
||||
func (w *Wheel) String() string {
|
||||
switch w.state {
|
||||
case 0:
|
||||
w.state++
|
||||
return "|"
|
||||
case 1:
|
||||
w.state++
|
||||
return "/"
|
||||
case 2:
|
||||
w.state++
|
||||
return "-"
|
||||
case 3:
|
||||
w.state = 0
|
||||
return "\\"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// Config represents user preferences
|
||||
|
|
Loading…
Reference in New Issue