From 8ec75323e72556ecb8e43c220c9aaf59c634024e Mon Sep 17 00:00:00 2001 From: Miguel Mota Date: Tue, 3 Apr 2018 01:04:41 -0700 Subject: [PATCH] marketbar Former-commit-id: d1a541c46f5da9debd3c9928f9263b6700978755 [formerly d1a541c46f5da9debd3c9928f9263b6700978755 [formerly 97ac554186e96a62b7b71239c7d5d3a88929adb0 [formerly dd9f2d48b630489a71a94308fd8917d5c2dace04]]] Former-commit-id: bc61122f27cc23ea8df80f510c13372d9448d2ec Former-commit-id: aee7b531ed7503994b7bea2004f10d810025d142 [formerly 4ed5978aa3faa95f2e5058111dbd487d5a15b202] Former-commit-id: 897d294659f3a94f556feff81a36057703141928 --- cointop/layout.go | 36 +----------------------------------- cointop/marketbar.go | 2 +- cointop/navigation.go | 2 -- cointop/refresh.go | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 38 deletions(-) create mode 100644 cointop/refresh.go diff --git a/cointop/layout.go b/cointop/layout.go index efc4870..620cb41 100644 --- a/cointop/layout.go +++ b/cointop/layout.go @@ -2,8 +2,6 @@ package cointop import ( "math" - "strings" - "time" "github.com/jroimartin/gocui" apt "github.com/miguelmota/cointop/pkg/api/types" @@ -24,7 +22,7 @@ func (ct *Cointop) layout(g *gocui.Gui) error { ct.marketview.Frame = false ct.marketview.BgColor = gocui.ColorBlack ct.marketview.FgColor = gocui.ColorWhite - ct.updateMarket() + ct.updateMarketbar() } topOffset = topOffset + 1 @@ -176,35 +174,3 @@ func (ct *Cointop) intervalFetchData() { } }() } - -func (ct *Cointop) refreshAll() error { - ct.refreshmux.Lock() - ct.setRefreshStatus() - ct.updateCoins() - ct.updateTable() - ct.updateMarket() - ct.updateChart() - ct.refreshmux.Unlock() - return nil -} - -func (ct *Cointop) setRefreshStatus() { - go func() { - ct.loadingTicks("refreshing", 900) - ct.updateStatusbar("") - ct.rowChanged() - }() -} - -func (ct *Cointop) loadingTicks(s string, t int) { - interval := 150 - k := 0 - for i := 0; i < (t / interval); i++ { - ct.updateStatusbar(s + strings.Repeat(".", k)) - time.Sleep(time.Duration(i*interval) * time.Millisecond) - k = k + 1 - if k > 3 { - k = 0 - } - } -} diff --git a/cointop/marketbar.go b/cointop/marketbar.go index 5a4ddff..ff5cc8b 100644 --- a/cointop/marketbar.go +++ b/cointop/marketbar.go @@ -8,7 +8,7 @@ import ( "github.com/miguelmota/cointop/pkg/pad" ) -func (ct *Cointop) updateMarket() error { +func (ct *Cointop) updateMarketbar() error { maxX := ct.Width() market, err := ct.api.GetGlobalMarketData() if err != nil { diff --git a/cointop/navigation.go b/cointop/navigation.go index c36cf3d..3a5a26d 100644 --- a/cointop/navigation.go +++ b/cointop/navigation.go @@ -11,7 +11,6 @@ func (ct *Cointop) cursorDown(g *gocui.Gui, v *gocui.View) error { _, y := ct.tableview.Origin() cx, cy := ct.tableview.Cursor() numRows := len(ct.coins) - 1 - //fmt.Fprint(v, cy) if (cy + y + 1) > numRows { return nil } @@ -31,7 +30,6 @@ func (ct *Cointop) cursorUp(g *gocui.Gui, v *gocui.View) error { } ox, oy := ct.tableview.Origin() cx, cy := ct.tableview.Cursor() - //fmt.Fprint(v, oy) if err := ct.tableview.SetCursor(cx, cy-1); err != nil && oy > 0 { if err := ct.tableview.SetOrigin(ox, oy-1); err != nil { return err diff --git a/cointop/refresh.go b/cointop/refresh.go new file mode 100644 index 0000000..655e0d8 --- /dev/null +++ b/cointop/refresh.go @@ -0,0 +1,38 @@ +package cointop + +import ( + "strings" + "time" +) + +func (ct *Cointop) refreshAll() error { + ct.refreshmux.Lock() + ct.setRefreshStatus() + ct.updateCoins() + ct.updateTable() + ct.updateMarketbar() + ct.updateChart() + ct.refreshmux.Unlock() + return nil +} + +func (ct *Cointop) setRefreshStatus() { + go func() { + ct.loadingTicks("refreshing", 900) + ct.updateStatusbar("") + ct.rowChanged() + }() +} + +func (ct *Cointop) loadingTicks(s string, t int) { + interval := 150 + k := 0 + for i := 0; i < (t / interval); i++ { + ct.updateStatusbar(s + strings.Repeat(".", k)) + time.Sleep(time.Duration(i*interval) * time.Millisecond) + k = k + 1 + if k > 3 { + k = 0 + } + } +}