forked from jroimartin/gocui
-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathloader.go
More file actions
31 lines (27 loc) · 707 Bytes
/
loader.go
File metadata and controls
31 lines (27 loc) · 707 Bytes
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
package gocui
import "time"
func (v *View) loaderLines() [][]cell {
duplicate := make([][]cell, len(v.lines))
for i := range v.lines {
if i < len(v.lines)-1 {
duplicate[i] = make([]cell, len(v.lines[i]))
copy(duplicate[i], v.lines[i])
} else {
duplicate[i] = make([]cell, len(v.lines[i])+2)
copy(duplicate[i], v.lines[i])
duplicate[i][len(duplicate[i])-2] = cell{chr: " "}
duplicate[i][len(duplicate[i])-1] = Loader()
}
}
return duplicate
}
// Loader can show a loading animation
func Loader() cell {
frames := []string{"|", "/", "-", "\\"}
now := time.Now()
nanos := now.UnixNano()
index := nanos / 50000000 % int64(len(frames))
return cell{
chr: frames[index],
}
}