From ed94437bddbb8648dbcd3197917843395d3fbb68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Thu, 20 Jun 2019 17:32:50 -0400 Subject: [PATCH] check maxWidth od window to show full peer ID MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakub SokoĊ‚owski --- json.go | 10 ++++++++-- main.go | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/json.go b/json.go index 6513ad3..427452e 100644 --- a/json.go +++ b/json.go @@ -20,8 +20,14 @@ func (p Peer) String() string { type peerId string -func (p Peer) AsTable() string { - return fmt.Sprintf("%15s | %30s | %s", p.Id, p.Name, strings.Join(p.Caps, ", ")) +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 diff --git a/main.go b/main.go index 495faa8..5f14cfa 100644 --- a/main.go +++ b/main.go @@ -65,8 +65,9 @@ func writePeers(g *gocui.Gui, peers []Peer) { return err } v.Clear() + maxWidth, _ := g.Size() for _, peer := range peers { - fmt.Fprintf(v, "%s\n", peer.AsTable()) + fmt.Fprintf(v, "%s\n", peer.AsTable(maxWidth)) } return nil })