-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgo_coroutine.go
46 lines (42 loc) · 1.07 KB
/
go_coroutine.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
package main
import (
"time"
"strings"
)
func checkSyntax() {
old := ""
for range time.Tick(time.Millisecond * 50) {
view := g.CurrentView()
viewName := view.Name()
if "main" == viewName{
mainBuffer := view.Buffer()
if old != mainBuffer {
old = mainBuffer
lines := view.ViewBufferLines()
for idx, line := range lines {
if false == checkHostsItemLine(line) {
lines[idx] = red(line)
}
}
newBuffer := "\n" + strings.Join(lines, "\n")
renderString(g, "main", newBuffer)
if newBuffer[len(newBuffer) - 1] != '\n' {
newBuffer += "\n"
}
// 写入数据库
setCurrentHostsItemContent(newBuffer)
jsonencodeHostsInfoToPath(dataPath, hItems)
// 提现到系统hosts中
hItemsToSystemHosts(hItems)
}
} else if "new-hosts-item-msg" == viewName {
hostsName := view.ViewBuffer()
hostsName = strings.Trim(hostsName, "\n ")
if !checkHostsItemName(hostsName) {
renderString(g, "new-hosts-item-msg", red(hostsName))
} else {
renderString(g, "new-hosts-item-msg", green(hostsName))
}
}
}
}