aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/awesome-gocui/gocui/loader.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-11-03 20:47:29 +0100
committerMichael Muré <batolettre@gmail.com>2019-11-03 20:47:29 +0100
commitcb8236c9c22007eb622b7219c58d3342f1f53d50 (patch)
treee232e5362486065d9b28bb55b9791690efb50c08 /vendor/github.com/awesome-gocui/gocui/loader.go
parent163ea9c93306c387f84ff0b85c2d8fca4c01e449 (diff)
downloadgit-bug-cb8236c9c22007eb622b7219c58d3342f1f53d50.tar.gz
termui: migrate to awesome-gocui instead of the old fork I had
Diffstat (limited to 'vendor/github.com/awesome-gocui/gocui/loader.go')
-rw-r--r--vendor/github.com/awesome-gocui/gocui/loader.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/vendor/github.com/awesome-gocui/gocui/loader.go b/vendor/github.com/awesome-gocui/gocui/loader.go
new file mode 100644
index 00000000..d6715ac6
--- /dev/null
+++ b/vendor/github.com/awesome-gocui/gocui/loader.go
@@ -0,0 +1,46 @@
+package gocui
+
+import "time"
+
+func (g *Gui) loaderTick() {
+ go func() {
+ for range time.Tick(time.Millisecond * 50) {
+ for _, view := range g.Views() {
+ if view.HasLoader {
+ g.userEvents <- userEvent{func(g *Gui) error { return nil }}
+ break
+ }
+ }
+ }
+ }()
+}
+
+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 {
+ characters := "|/-\\"
+ now := time.Now()
+ nanos := now.UnixNano()
+ index := nanos / 50000000 % int64(len(characters))
+ str := characters[index : index+1]
+ chr := []rune(str)[0]
+ return cell{
+ chr: chr,
+ }
+}