1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-07 13:42:01 +02:00

loading animation for confirmation view

This commit is contained in:
Jesse Duffield 2018-07-21 18:37:00 +10:00
parent fab194e923
commit d832eab20c
3 changed files with 32 additions and 5 deletions

26
gui.go
View File

@ -6,6 +6,7 @@ import (
// "io/ioutil"
"log"
"strings"
"time"
// "strings"
@ -278,6 +279,25 @@ func fetch(g *gocui.Gui) {
refreshStatus(g)
}
func loader() string {
characters := "|/-\\"
now := time.Now()
nanos := now.UnixNano()
index := nanos / 50000000 % int64(len(characters))
devLog(characters[index : index+1])
return characters[index : index+1]
}
func updateLoader(g *gocui.Gui) {
if confirmationView, _ := g.View("confirmation"); confirmationView != nil {
content := trimmedContent(confirmationView)
if strings.Contains(content, "...") {
staticContent := strings.Split(content, "...")[0] + "..."
renderString(g, "confirmation", staticContent+" "+loader())
}
}
}
func run() {
g, err := gocui.NewGui(gocui.OutputNormal)
if err != nil {
@ -292,6 +312,12 @@ func run() {
}
}()
go func() {
for range time.Tick(time.Millisecond * 10) {
updateLoader(g)
}
}()
g.SetManagerFunc(layout)
if err := keybindings(g); err != nil {

View File

@ -63,10 +63,9 @@ func handleStashPop(g *gocui.Gui, v *gocui.View) error {
}
func handleStashDrop(g *gocui.Gui, v *gocui.View) error {
return createConfirmationPanel(g, v, "Stash drop", "Are you sure you want to drop this stash entry?", func(g *gocui.Gui, v *gocui.View) error {
return stashDo(g, v, "drop")
}, nil)
return nil
return createConfirmationPanel(g, v, "Stash drop", "Are you sure you want to drop this stash entry?", func(g *gocui.Gui, v *gocui.View) error {
return stashDo(g, v, "drop")
}, nil)
}
func stashDo(g *gocui.Gui, v *gocui.View, method string) error {

View File

@ -162,8 +162,10 @@ func correctCursor(v *gocui.View) error {
func renderString(g *gocui.Gui, viewName, s string) error {
g.Update(func(*gocui.Gui) error {
v, err := g.View(viewName)
// just in case the view disappeared as this function was called, we'll
// silently return if it's not found
if err != nil {
panic(err)
return nil
}
v.Clear()
fmt.Fprint(v, s)