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) {
|
func display(writer io.Writer, msg Message) {
|
||||||
fmt.Fprintf(
|
fmt.Fprintf(
|
||||||
writer,
|
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.Duration - time.Since(msg.Start)).Truncate(time.Second),
|
||||||
msg.CurrentPomodoro,
|
msg.CurrentPomodoro,
|
||||||
msg.Pomodoros,
|
msg.Pomodoros,
|
||||||
|
@ -31,6 +32,7 @@ func run(task Task, prompter Prompter, db *Store) {
|
||||||
writer.Start()
|
writer.Start()
|
||||||
ticker := time.NewTicker(RefreshInterval)
|
ticker := time.NewTicker(RefreshInterval)
|
||||||
timer := time.NewTimer(task.duration)
|
timer := time.NewTimer(task.duration)
|
||||||
|
wheel := &Wheel{}
|
||||||
var p int
|
var p int
|
||||||
for p < task.pomodoros {
|
for p < task.pomodoros {
|
||||||
pomodoro := &Pomodoro{}
|
pomodoro := &Pomodoro{}
|
||||||
|
@ -44,6 +46,7 @@ func run(task Task, prompter Prompter, db *Store) {
|
||||||
Start: pomodoro.Start,
|
Start: pomodoro.Start,
|
||||||
Duration: task.duration,
|
Duration: task.duration,
|
||||||
Pomodoros: task.pomodoros,
|
Pomodoros: task.pomodoros,
|
||||||
|
Wheel: wheel,
|
||||||
CurrentPomodoro: p,
|
CurrentPomodoro: p,
|
||||||
})
|
})
|
||||||
goto loop
|
goto loop
|
||||||
|
|
24
types.go
24
types.go
|
@ -20,6 +20,30 @@ type Message struct {
|
||||||
Duration time.Duration
|
Duration time.Duration
|
||||||
Pomodoros int
|
Pomodoros int
|
||||||
CurrentPomodoro 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
|
// Config represents user preferences
|
||||||
|
|
Loading…
Reference in New Issue