From 6e00f2044bb9670bc2f0e4fb53a9d0d440ca41e1 Mon Sep 17 00:00:00 2001 From: Miguel Mota Date: Thu, 5 Apr 2018 12:50:28 -0700 Subject: [PATCH] display page count Former-commit-id: ba08541779f1c0448d4564d24e0b3e61ca9ca981 [formerly ba08541779f1c0448d4564d24e0b3e61ca9ca981 [formerly 7cf32aba5fac5019735f836c22abfec268894326 [formerly 3f311f0c39ecc523acc877d44a962b0ce57529c1]]] Former-commit-id: ce2a56059ddd4b3cc10e8aece59edac70e75b52b Former-commit-id: b1f8a33e1f4ee6de1d0217ebb7186667e40dcce9 [formerly b091c940648243c553937b36731874ae38e084ce] Former-commit-id: 904051694cddddac7cc6229a77708a98c9d8c395 --- cointop/navigation.go | 16 ++++++++++++++-- cointop/statusbar.go | 4 +++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/cointop/navigation.go b/cointop/navigation.go index 6896173..34b12fc 100644 --- a/cointop/navigation.go +++ b/cointop/navigation.go @@ -174,7 +174,7 @@ func (ct *Cointop) prevPage(g *gocui.Gui, v *gocui.View) error { } func (ct *Cointop) nextPage(g *gocui.Gui, v *gocui.View) error { - if ((ct.page + 1) * ct.perpage) <= len(ct.allcoins) { + if ((ct.page + 1) * ct.perpage) <= ct.getListCount() { ct.page = ct.page + 1 } ct.updateTable() @@ -190,8 +190,20 @@ func (ct *Cointop) firstPage(g *gocui.Gui, v *gocui.View) error { } func (ct *Cointop) lastPage(g *gocui.Gui, v *gocui.View) error { - ct.page = len(ct.allcoins) / ct.perpage + ct.page = ct.getListCount() / ct.perpage ct.updateTable() ct.rowChanged() return nil } + +func (ct *Cointop) getCurrentPage() int { + return ct.page + 1 +} + +func (ct *Cointop) getTotalPages() int { + return (ct.getListCount() / ct.perpage) + 1 +} + +func (ct *Cointop) getListCount() int { + return len(ct.allcoins) +} diff --git a/cointop/statusbar.go b/cointop/statusbar.go index e43c200..bbbc370 100644 --- a/cointop/statusbar.go +++ b/cointop/statusbar.go @@ -10,7 +10,9 @@ func (ct *Cointop) updateStatusbar(s string) { maxX := ct.Width() ct.Update(func() { ct.statusbarview.Clear() - fmt.Fprintln(ct.statusbarview, pad.Right(fmt.Sprintf("[q]uit [← →]page %s", s), maxX, " ")) + currpage := ct.getCurrentPage() + totalpages := ct.getTotalPages() + fmt.Fprintln(ct.statusbarview, pad.Right(fmt.Sprintf("[q]uit [← →]page %v/%v %s", currpage, totalpages, s), maxX, " ")) }) }