1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-05 00:59:19 +02:00

bump gocui to support loader animations on views

This commit is contained in:
Jesse Duffield
2019-02-15 20:54:03 +11:00
parent c101993405
commit 306ac41fd8
4 changed files with 71 additions and 15 deletions

View File

@ -8,6 +8,7 @@ import (
"bytes"
"io"
"strings"
"time"
"github.com/go-errors/errors"
@ -87,6 +88,9 @@ type View struct {
// Overlaps describes which edges are overlapping with another view's edges
Overlaps byte
// If HasLoader is true, the message will be appended with a spinning loader animation
HasLoader bool
}
type viewLine struct {
@ -322,7 +326,11 @@ func (v *View) draw() error {
}
if v.tainted {
v.viewLines = nil
for i, line := range v.lines {
lines := v.lines
if v.HasLoader {
lines = v.loaderLines()
}
for i, line := range lines {
wrap := 0
if v.Wrap {
wrap = maxX
@ -334,7 +342,9 @@ func (v *View) draw() error {
v.viewLines = append(v.viewLines, vline)
}
}
v.tainted = false
if !v.HasLoader {
v.tainted = false
}
}
if v.Autoscroll && len(v.viewLines) > maxY {
@ -564,3 +574,32 @@ func linesToString(lines [][]cell) string {
return strings.Join(str, "\n")
}
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
}
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,
}
}