move table formatting to peers.go

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2019-06-21 15:10:06 -04:00 committed by Jakub
parent fd834252fb
commit f22a1554f5
2 changed files with 15 additions and 15 deletions

19
json.go
View File

@ -1,9 +1,6 @@
package main package main
import ( import "fmt"
"fmt"
"strings"
)
type Peer struct { type Peer struct {
Enode string `json:"enode"` Enode string `json:"enode"`
@ -20,19 +17,11 @@ func (p Peer) String() string {
type peerId string type peerId string
func (p Peer) AsTable(maxWidth int) string {
var id string
if maxWidth > 50 {
id = string(p.Id)
} else {
id = p.Id.String()
}
return fmt.Sprintf("%15s | %30s | %s", id, p.Name, strings.Join(p.Caps, ", "))
}
// the ID is too long to display in full in most places // the ID is too long to display in full in most places
func (id peerId) String() string { func (id peerId) String() string {
return fmt.Sprintf("%s...%s", string(id[:6]), string(id[len(id)-6:])) return fmt.Sprintf("%s...%s",
string(id[:6]),
string(id[len(id)-6:]))
} }
type NetworkInfo struct { type NetworkInfo struct {

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"github.com/jroimartin/gocui" "github.com/jroimartin/gocui"
"log" "log"
"strings"
"time" "time"
) )
@ -38,3 +39,13 @@ func WritePeers(g *gocui.Gui, peers []Peer) {
return nil return nil
}) })
} }
func (p Peer) AsTable(maxWidth int) string {
var id string
if maxWidth > 50 {
id = string(p.Id)
} else {
id = p.Id.String()
}
return fmt.Sprintf("%15s | %30s | %s", id, p.Name, strings.Join(p.Caps, ", "))
}