-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathblinker_physical.go
53 lines (46 loc) · 1.29 KB
/
blinker_physical.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
package main
import "time"
type realBlinker struct {
blinkIsSet bool
d *Display
}
func (r *realBlinker) refresh() {
if r.blinkIsSet {
r.set()
} else {
r.clear()
}
}
func (r *realBlinker) set() {
r.d.screen.putStr(r.d.getBlinkerX(), r.d.getBlinkerY(), rune('▉'))
r.d.screen.sync()
}
func (r *realBlinker) clear() {
if len(r.d.getCurrentEl().data) > r.d.getCurrentEl().pos {
r.d.screen.putStr(r.d.getBlinkerX(), r.d.getBlinkerY(), r.d.getCurrentEl().getCurrentChar())
} else {
// FIXME: exception: it might be on beginning of another line. Fix the case.
if r.d.getBlinkerX() == 0 && r.d.hasNextEl() && r.d.getBlinkerY() == r.d.getNextEl().startingCoordY {
if len(r.d.getNextEl().data) > 0 {
r.d.screen.putStr(r.d.getBlinkerX(), r.d.getBlinkerY(), r.d.getNextEl().data[0])
} else {
r.d.screen.clearStr(r.d.getBlinkerX(), r.d.getBlinkerY())
}
} else {
r.d.screen.clearStr(r.d.getBlinkerX(), r.d.getBlinkerY())
}
}
r.d.screen.sync()
}
func initRealBlinker(e *Editor) blinker {
b := &realBlinker{d: e.display, blinkIsSet: false}
go func(c chan contentOperation) {
ticker := time.NewTicker(500 * time.Millisecond)
for {
<-ticker.C
b.blinkIsSet = !b.blinkIsSet
c <- blinkOperation{blink: b.blinkIsSet}
}
}(e.display.monitorChannel)
return b
}