aboutsummaryrefslogtreecommitdiff
path: root/progress.go
blob: 76374b63889138c3fb1135b1f83c17103809305c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package blinkstick

import (
	"image/color"
	"io"
	"time"
)

var (
	red    = color.YCbCr{0x1f, 0x00, 0xff}
	yellow = color.YCbCr{0x3f, 0x00, 0xbf}
	green  = color.YCbCr{0x1f, 0x00, 0x00}
	blue   = color.YCbCr{0x1f, 0xff, 0x1f}
	black  = color.Black
)

type Progress struct {
	//f     Frame
	start time.Time
	soft  time.Duration
	hard  time.Duration
	end   time.Duration
	n     int
}

func NewProgress(soft, hard, end time.Duration) Progress {
	return Progress{
		start: time.Now(),
		soft:  soft,
		hard:  hard,
		end:   end,
	}
}

func (p *Progress) Update(w io.Writer) {
	done := time.Since(p.start)
	switch {
	case p.hard < done:
		//p.f[p.n] = red
	case p.soft < done:
		//p.f[p.n] = yellow
	default:
		//p.f[p.n] = green
	}
	//Set(w, p.f)
	p.n = (p.n + 1) % 8
}