diff options
| author | İbrahim Serdar Açıkgöz <serdaracikgoz86@gmail.com> | 2018-12-05 18:28:26 +0300 |
|---|---|---|
| committer | İbrahim Serdar Açıkgöz <serdaracikgoz86@gmail.com> | 2018-12-05 18:28:26 +0300 |
| commit | d092efab54be46c90cfcc4ba0524b4ec0e1e1900 (patch) | |
| tree | a65b91211d831be0931ba9818ceb97eaabcfb0cf | |
| parent | prune option while fetching initiated (diff) | |
| download | gitbatch-d092efab54be46c90cfcc4ba0524b4ec0e1e1900.tar.gz | |
initiated view switching
| -rw-r--r-- | pkg/gui/gui-navigate.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/pkg/gui/gui-navigate.go b/pkg/gui/gui-navigate.go new file mode 100644 index 0000000..5565d13 --- /dev/null +++ b/pkg/gui/gui-navigate.go @@ -0,0 +1,56 @@ +package gui + +import ( + log "github.com/sirupsen/logrus" + "github.com/jroimartin/gocui" +) + +var cyclableViews = []string{mainViewFeature.Name, + remoteViewFeature.Name, + remoteBranchViewFeature.Name, + branchViewFeature.Name, + commitViewFeature.Name} + +func (gui *Gui) nextView(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] + break + } + if i == len(cyclableViews)-1 { + return nil + } + } + } + if _, err := g.SetCurrentView(focusedViewName); err != nil { + log.Warn("Loading view cannot be focused.") + return nil + } + return nil +} + +func (gui *Gui) previousView(g *gocui.Gui, v *gocui.View) error { + var focusedViewName string + if v == nil || v.Name() == cyclableViews[0] { + focusedViewName = cyclableViews[len(cyclableViews)-1] + } 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 { + return nil + } + } + } + if _, err := g.SetCurrentView(focusedViewName); err != nil { + log.Warn("Loading view cannot be focused.") + return nil + } + return nil +} |
