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 + } + } +}