From b5042fdbeb115e486211d05267f84fbda1b8e6a7 Mon Sep 17 00:00:00 2001 From: Kevin Schoon Date: Sun, 21 Jan 2018 01:49:07 +0800 Subject: [PATCH] add cool ascii spinner --- task.go | 5 ++++- types.go | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/task.go b/task.go index b773a54..1e93324 100644 --- a/task.go +++ b/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 diff --git a/types.go b/types.go index 64f5a29..5a30678 100644 --- a/types.go +++ b/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