2019-06-16 15:23:24 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-06-20 21:01:34 +00:00
|
|
|
"github.com/jroimartin/gocui"
|
2019-06-21 18:53:50 +00:00
|
|
|
"log"
|
2019-06-26 15:39:47 +00:00
|
|
|
"os"
|
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-26 18:54:43 +00:00
|
|
|
clientLogFile, err := os.OpenFile("./app.log", os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
|
2019-06-26 15:39:47 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Panicln(err)
|
|
|
|
}
|
|
|
|
log.SetOutput(clientLogFile)
|
|
|
|
|
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-26 23:54:04 +00:00
|
|
|
peers := NewPeersState(host, port)
|
|
|
|
|
|
|
|
mainView := &ViewController{
|
2019-06-26 22:18:34 +00:00
|
|
|
Name: "main",
|
|
|
|
Title: "Peers",
|
|
|
|
Placeholder: "Loading peers...",
|
|
|
|
Cursor: true,
|
|
|
|
Highlight: true,
|
|
|
|
Current: true,
|
|
|
|
SelFgColor: gocui.ColorBlack,
|
|
|
|
SelBgColor: gocui.ColorGreen,
|
2019-06-27 00:12:04 +00:00
|
|
|
State: peers,
|
2019-06-26 23:57:02 +00:00
|
|
|
// corner positions
|
2019-06-26 22:18:34 +00:00
|
|
|
TopLeft: func(mx, my int) (int, int) {
|
|
|
|
return 0, 0
|
2019-06-26 21:40:31 +00:00
|
|
|
},
|
2019-06-26 22:18:34 +00:00
|
|
|
BotRight: func(mx, my int) (int, int) {
|
|
|
|
return mx - 1, my / 2
|
2019-06-26 21:40:31 +00:00
|
|
|
},
|
|
|
|
}
|
2019-06-26 22:18:34 +00:00
|
|
|
// bindings defined separately so handlers can reference mainView
|
|
|
|
mainView.Keybindings = []Binding{
|
|
|
|
Binding{gocui.KeyCtrlC, gocui.ModNone, quit},
|
|
|
|
Binding{gocui.KeyArrowUp, gocui.ModNone, mainView.CursorUp},
|
|
|
|
Binding{gocui.KeyArrowDown, gocui.ModNone, mainView.CursorDown},
|
|
|
|
}
|
2019-06-26 23:54:04 +00:00
|
|
|
infoView := &ViewController{
|
2019-06-26 22:18:34 +00:00
|
|
|
Name: "info",
|
|
|
|
Title: "Details",
|
|
|
|
Placeholder: "Loading details...",
|
2019-06-26 23:57:02 +00:00
|
|
|
// corner positions
|
2019-06-26 22:18:34 +00:00
|
|
|
TopLeft: func(mx, my int) (int, int) {
|
|
|
|
return 0, my/2 + 1
|
|
|
|
},
|
|
|
|
BotRight: func(mx, my int) (int, int) {
|
|
|
|
return mx - 1, my - 1
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2019-06-26 23:54:04 +00:00
|
|
|
views := []*ViewController{mainView, infoView}
|
2019-06-26 21:40:31 +00:00
|
|
|
|
2019-06-27 00:12:04 +00:00
|
|
|
vm := ViewManager{g: g, views: views}
|
2019-06-26 21:40:31 +00:00
|
|
|
|
|
|
|
g.SetManagerFunc(vm.Layout)
|
2019-06-20 20:03:27 +00:00
|
|
|
|
|
|
|
// Start RPC calling routine
|
2019-06-27 00:23:36 +00:00
|
|
|
go peers.FetchLoop(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 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
|
|
|
}
|