From 5dbe262d2d15633003712e80d2531c039d63e1c3 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sun, 22 Jul 2018 12:07:36 +1000 Subject: [PATCH] moving loader and adding previous view function (unfinished) --- gui.go | 9 --------- view_helpers.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/gui.go b/gui.go index d5f297e17..12c05827d 100644 --- a/gui.go +++ b/gui.go @@ -279,15 +279,6 @@ 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) diff --git a/view_helpers.go b/view_helpers.go index b822e73e2..abaeb950d 100644 --- a/view_helpers.go +++ b/view_helpers.go @@ -4,6 +4,7 @@ import ( "fmt" "sort" "strings" + "time" "github.com/jesseduffield/gocui" ) @@ -40,6 +41,29 @@ func nextView(g *gocui.Gui, v *gocui.View) error { return switchFocus(g, v, focusedView) } +func previousView(g *gocui.Gui, v *gocui.View) error { + var focusedViewName string + if v == nil || v.Name() == cyclableViews[len(cyclableViews)-1] { + focusedViewName = cyclableViews[0] + } else { + for i := range cyclableViews { + if v.Name() == cyclableViews[i] { + focusedViewName = cyclableViews[i-1] // TODO: make this work properly + break + } + if i == len(cyclableViews)-1 { + devLog(v.Name() + " is not in the list of views") + return nil + } + } + } + focusedView, err := g.View(focusedViewName) + if err != nil { + panic(err) + } + return switchFocus(g, v, focusedView) +} + func newLineFocused(g *gocui.Gui, v *gocui.View) error { mainView, _ := g.View("main") mainView.SetOrigin(0, 0) @@ -198,3 +222,11 @@ func optionsMapToString(optionsMap map[string]string) string { func renderOptionsMap(g *gocui.Gui, optionsMap map[string]string) error { return renderString(g, "options", optionsMapToString(optionsMap)) } + +func loader() string { + characters := "|/-\\" + now := time.Now() + nanos := now.UnixNano() + index := nanos / 50000000 % int64(len(characters)) + return characters[index : index+1] +}