implement peer removal without prompt
Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
parent
08ec326ea4
commit
51d299888d
|
@ -24,3 +24,12 @@ func (c *client) getPeers() ([]Peer, error) {
|
|||
}
|
||||
return peers, nil
|
||||
}
|
||||
|
||||
func (c *client) removePeer(enode string) (bool, error) {
|
||||
var rval bool
|
||||
err := c.rpcClient.Call(&rval, "admin_removePeer", enode)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return rval, nil
|
||||
}
|
||||
|
|
6
keys.go
6
keys.go
|
@ -44,3 +44,9 @@ func MoveCursor(mod int, vc *ViewController, g *gocui.Gui, v *gocui.View) error
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (vc *ViewController) HandleDelete(g *gocui.Gui, v *gocui.View) error {
|
||||
ps := vc.State.(*PeersState)
|
||||
selectedPeer := ps.selected
|
||||
rval := ps.Remove(*selectedPeer)
|
||||
}
|
||||
|
|
4
main.go
4
main.go
|
@ -52,6 +52,8 @@ func main() {
|
|||
Binding{gocui.KeyArrowDown, gocui.ModNone, mainView.CursorDown},
|
||||
Binding{'k', gocui.ModNone, mainView.CursorUp},
|
||||
Binding{'j', gocui.ModNone, mainView.CursorDown},
|
||||
Binding{gocui.KeyDelete, gocui.ModNone, mainView.HandleDelete},
|
||||
Binding{'d', gocui.ModNone, mainView.HandleDelete},
|
||||
}
|
||||
infoView := &ViewController{
|
||||
Name: "info",
|
||||
|
@ -60,7 +62,7 @@ func main() {
|
|||
Enabled: true,
|
||||
Wrap: true,
|
||||
// corner positions
|
||||
TopLeft: func(mx, my int) (int, int) { return 0, my/2 + 1 },
|
||||
TopLeft: func(mx, my int) (int, int) { return 0, (my / 2) + 1 },
|
||||
BotRight: func(mx, my int) (int, int) { return mx - 1, my - 1 },
|
||||
}
|
||||
|
||||
|
|
8
peers.go
8
peers.go
|
@ -64,6 +64,14 @@ func writePeers(g *gocui.Gui, peers []Peer) {
|
|||
})
|
||||
}
|
||||
|
||||
func (p *PeersState) Remove(peer Peer) error {
|
||||
success, err := p.c.removePeer(peer.Enode)
|
||||
if err != nil || success != true {
|
||||
log.Panicln(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func writePeerDetails(g *gocui.Gui, peer *Peer) {
|
||||
g.Update(func(g *gocui.Gui) error {
|
||||
v, err := g.View("info")
|
||||
|
|
2
view.go
2
view.go
|
@ -42,6 +42,7 @@ func (m *ViewManager) Layout(g *gocui.Gui) error {
|
|||
x1, y1 := cfg.BotRight(mx, my)
|
||||
|
||||
v, err := g.SetView(cfg.Name, x0, y0, x1, y1)
|
||||
|
||||
// Some settings can be set only once
|
||||
if err == gocui.ErrUnknownView {
|
||||
cfg.SetKeybindings(g)
|
||||
|
@ -54,6 +55,7 @@ func (m *ViewManager) Layout(g *gocui.Gui) error {
|
|||
} else if err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
|
||||
v.Title = cfg.Title
|
||||
v.Wrap = cfg.Wrap
|
||||
v.SelFgColor = cfg.SelFgColor
|
||||
|
|
Loading…
Reference in New Issue