mirror of
https://github.com/status-im/status-go-monitor.git
synced 2025-01-27 03:24:46 +00:00
add mor columns, remote ip, trusted, static
Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
parent
f22a1554f5
commit
7e3aa2a85b
2
json.go
2
json.go
@ -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"`
|
||||
}
|
||||
|
||||
|
2
main.go
2
main.go
@ -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...")
|
||||
}
|
||||
|
18
peers.go
18
peers.go
@ -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, ", "))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user