Skip to content

Commit

Permalink
moving loader and adding previous view function (unfinished)
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseduffield committed Jul 22, 2018
1 parent f0447be commit 5dbe262
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
9 changes: 0 additions & 9 deletions gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 32 additions & 0 deletions view_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"sort"
"strings"
"time"

"github.com/jesseduffield/gocui"
)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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]
}

0 comments on commit 5dbe262

Please sign in to comment.