mirror of https://github.com/jroimartin/gocui.git
_examples/delete.go: Refactoring
This commit is contained in:
parent
2db4573e76
commit
d3c84c7bf4
|
@ -62,7 +62,7 @@ func initKeybindings(g *gocui.Gui) error {
|
||||||
}
|
}
|
||||||
if err := g.SetKeybinding("", gocui.KeyTab, gocui.ModNone,
|
if err := g.SetKeybinding("", gocui.KeyTab, gocui.ModNone,
|
||||||
func(g *gocui.Gui, v *gocui.View) error {
|
func(g *gocui.Gui, v *gocui.View) error {
|
||||||
return nextView(g)
|
return nextView(g, true)
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ func newView(g *gocui.Gui) error {
|
||||||
|
|
||||||
views = append(views, name)
|
views = append(views, name)
|
||||||
curView = len(views) - 1
|
curView = len(views) - 1
|
||||||
idxViews += 1
|
idxView += 1
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,25 +137,10 @@ func delView(g *gocui.Gui) error {
|
||||||
}
|
}
|
||||||
views = append(views[:curView], views[curView+1:]...)
|
views = append(views[:curView], views[curView+1:]...)
|
||||||
|
|
||||||
next := curView + 1
|
return nextView(g, false)
|
||||||
if next > len(views)-1 {
|
|
||||||
next = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
nv, err := g.View(views[next])
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := g.SetCurrentView(views[next]); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
nv.BgColor = gocui.ColorRed
|
|
||||||
|
|
||||||
curView = next
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func nextView(g *gocui.Gui) error {
|
func nextView(g *gocui.Gui, disableCurrent bool) error {
|
||||||
next := curView + 1
|
next := curView + 1
|
||||||
if next > len(views)-1 {
|
if next > len(views)-1 {
|
||||||
next = 0
|
next = 0
|
||||||
|
@ -170,11 +155,13 @@ func nextView(g *gocui.Gui) error {
|
||||||
}
|
}
|
||||||
nv.BgColor = gocui.ColorRed
|
nv.BgColor = gocui.ColorRed
|
||||||
|
|
||||||
cv, err := g.View(views[curView])
|
if disableCurrent {
|
||||||
if err != nil {
|
cv, err := g.View(views[curView])
|
||||||
return err
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
cv.BgColor = g.BgColor
|
||||||
}
|
}
|
||||||
cv.BgColor = g.BgColor
|
|
||||||
|
|
||||||
curView = next
|
curView = next
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue