-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpresenter.go
63 lines (48 loc) · 1.13 KB
/
presenter.go
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package lcd
import (
"fmt"
"strings"
"time"
"github.com/buger/goterm"
)
/**************************************************************************/
type Presenter interface {
Present(lcd *LCD)
Finalize()
}
/**************************************************************************/
type AnimatedPresenter struct{}
func NewAnimatedPresenter() *AnimatedPresenter {
goterm.Clear()
return &AnimatedPresenter{}
}
func (this *AnimatedPresenter) Present(lcd *LCD) {
state := lcd.String()
state = strings.Replace(state, ".", " ", -1)
goterm.MoveCursor(1, 1)
goterm.Println(state)
goterm.Flush()
time.Sleep(time.Millisecond * 75)
}
func (this *AnimatedPresenter) Finalize() {}
/**************************************************************************/
type StaticPresenter struct {
lcd *LCD
}
func NewStaticPresenter() *StaticPresenter {
return &StaticPresenter{}
}
func (this *StaticPresenter) Present(lcd *LCD) {
this.lcd = lcd
}
func (this *StaticPresenter) Finalize() {
fmt.Println(this.lcd)
fmt.Println()
count := 0
for _, value := range this.lcd.grid {
if value {
count++
}
}
fmt.Println("Pixels on:", count)
}