2019-06-16 15:23:24 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2019-06-20 21:01:34 +00:00
|
|
|
"github.com/jroimartin/gocui"
|
2019-06-21 18:53:50 +00:00
|
|
|
"log"
|
2019-06-16 15:23:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type rcpResp map[string]interface{}
|
|
|
|
|
2019-06-16 16:02:50 +00:00
|
|
|
const host = "127.0.0.1"
|
|
|
|
const port = 8545
|
2019-06-21 14:29:23 +00:00
|
|
|
const interval = 5
|
2019-06-20 20:03:27 +00:00
|
|
|
|
|
|
|
var threadDone = make(chan struct{})
|
2019-06-16 15:23:24 +00:00
|
|
|
|
|
|
|
func main() {
|
2019-06-19 14:58:48 +00:00
|
|
|
g, err := gocui.NewGui(gocui.OutputNormal)
|
2019-06-16 15:23:24 +00:00
|
|
|
if err != nil {
|
2019-06-19 14:58:48 +00:00
|
|
|
log.Panicln(err)
|
2019-06-16 15:23:24 +00:00
|
|
|
}
|
2019-06-19 14:58:48 +00:00
|
|
|
defer g.Close()
|
2019-06-16 16:02:50 +00:00
|
|
|
|
2019-06-21 18:53:50 +00:00
|
|
|
g.SelFgColor = gocui.ColorGreen
|
2019-06-21 14:29:23 +00:00
|
|
|
g.Highlight = true
|
|
|
|
g.Cursor = true
|
|
|
|
|
2019-06-19 14:58:48 +00:00
|
|
|
g.SetManagerFunc(layout)
|
|
|
|
|
2019-06-20 20:03:27 +00:00
|
|
|
if err := keybindings(g); err != nil {
|
|
|
|
log.Panicln(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
url := fmt.Sprintf("http://%s:%d", host, port)
|
|
|
|
c, err := newClient(url)
|
|
|
|
if err != nil {
|
2019-06-19 14:58:48 +00:00
|
|
|
log.Panicln(err)
|
2019-06-16 15:23:24 +00:00
|
|
|
}
|
2019-06-19 14:58:48 +00:00
|
|
|
|
2019-06-20 20:03:27 +00:00
|
|
|
// Start RPC calling routine
|
2019-06-21 18:53:50 +00:00
|
|
|
go FetchPeers(c, g)
|
2019-06-20 20:03:27 +00:00
|
|
|
|
2019-06-19 14:58:48 +00:00
|
|
|
if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
|
|
|
|
log.Panicln(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func layout(g *gocui.Gui) error {
|
|
|
|
maxX, maxY := g.Size()
|
2019-06-21 19:07:38 +00:00
|
|
|
if v, err := g.SetView("main", 0, 0, maxX-1, maxY/2); err != nil {
|
2019-06-19 14:58:48 +00:00
|
|
|
if err != gocui.ErrUnknownView {
|
|
|
|
return err
|
|
|
|
}
|
2019-06-21 18:53:50 +00:00
|
|
|
v.SelFgColor = gocui.ColorBlack
|
|
|
|
v.SelBgColor = gocui.ColorGreen
|
|
|
|
v.Title = "Peers"
|
2019-06-21 14:29:23 +00:00
|
|
|
v.Highlight = true
|
2019-06-21 20:47:37 +00:00
|
|
|
v.SetCursor(0, 0)
|
2019-06-21 18:53:50 +00:00
|
|
|
g.SetCurrentView("main")
|
2019-06-20 20:03:27 +00:00
|
|
|
fmt.Fprintln(v, "Loading peers...")
|
2019-06-19 14:58:48 +00:00
|
|
|
}
|
2019-06-21 19:07:38 +00:00
|
|
|
if v, err := g.SetView("info", 0, maxY/2+1, maxX-1, maxY-1); err != nil {
|
|
|
|
if err != gocui.ErrUnknownView {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
v.Title = "Details"
|
|
|
|
fmt.Fprintln(v, "Loading details...")
|
|
|
|
}
|
2019-06-19 14:58:48 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func quit(g *gocui.Gui, v *gocui.View) error {
|
2019-06-20 20:03:27 +00:00
|
|
|
close(threadDone)
|
2019-06-19 14:58:48 +00:00
|
|
|
return gocui.ErrQuit
|
2019-06-16 15:23:24 +00:00
|
|
|
}
|