add mor columns, remote ip, trusted, static

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2019-06-21 16:47:37 -04:00 committed by Jakub
parent f22a1554f5
commit 7e3aa2a85b
3 changed files with 17 additions and 5 deletions

View File

@ -7,7 +7,7 @@ type Peer struct {
Id peerId `json:"id"`
Name string `json:"name"`
Caps []string `json:"caps"`
Network NetworkInfo `json:"netrowkr"`
Network NetworkInfo `json:"network"`
Protocols map[string]string `json:"protocols"`
}

View File

@ -55,7 +55,7 @@ func layout(g *gocui.Gui) error {
v.SelBgColor = gocui.ColorGreen
v.Title = "Peers"
v.Highlight = true
v.SetCursor(0, 1)
v.SetCursor(0, 0)
g.SetCurrentView("main")
fmt.Fprintln(v, "Loading peers...")
}

View File

@ -32,7 +32,6 @@ func WritePeers(g *gocui.Gui, peers []Peer) {
}
v.Clear()
maxWidth, _ := g.Size()
fmt.Fprintf(v, "%-15s | %-40s | %s\n", "Peer ID", "Name", "Protocols")
for _, peer := range peers {
fmt.Fprintf(v, "%s\n", peer.AsTable(maxWidth))
}
@ -40,12 +39,25 @@ func WritePeers(g *gocui.Gui, peers []Peer) {
})
}
func boolToString(v bool, yes string, no string) string {
if v {
return yes
} else {
return no
}
}
func (p Peer) AsTable(maxWidth int) string {
var id string
if maxWidth > 50 {
if maxWidth > 160 {
id = string(p.Id)
} else {
id = p.Id.String()
}
return fmt.Sprintf("%15s | %30s | %s", id, p.Name, strings.Join(p.Caps, ", "))
return fmt.Sprintf("%s %-15s %-21s %-7s %-8s %s",
id, p.Name,
p.Network.RemoteAddress,
boolToString(p.Network.Trusted, "trusted", "normal"),
boolToString(p.Network.Static, "static", "dynamic"),
strings.Join(p.Caps, ", "))
}