update readme

pull/5/head
Miguel Mota 6 years ago
parent 255da8248c
commit 47b507d904

@ -10,7 +10,7 @@
## Install ## Install
Make sure to have [golang](https://golang.org/) installed, then do: Make sure to have [go](https://golang.org/) (1.9+) installed, then do:
```bash ```bash
go get -u github.com/miguelmota/cointop go get -u github.com/miguelmota/cointop

Binary file not shown.

Before

Width:  |  Height:  |  Size: 634 KiB

After

Width:  |  Height:  |  Size: 5.2 MiB

@ -1,6 +1,8 @@
package cointop package cointop
import ( import (
"time"
"github.com/jroimartin/gocui" "github.com/jroimartin/gocui"
apitypes "github.com/miguelmota/cointop/pkg/api/types" apitypes "github.com/miguelmota/cointop/pkg/api/types"
"github.com/miguelmota/cointop/pkg/pad" "github.com/miguelmota/cointop/pkg/pad"
@ -75,16 +77,7 @@ func (ct *Cointop) layout(g *gocui.Gui) error {
ct.tableview.Highlight = true ct.tableview.Highlight = true
ct.tableview.SelBgColor = gocui.ColorCyan ct.tableview.SelBgColor = gocui.ColorCyan
ct.tableview.SelFgColor = gocui.ColorBlack ct.tableview.SelFgColor = gocui.ColorBlack
var err error
if len(ct.coins) == 0 {
ct.coins, err = ct.fetchData()
if err != nil {
return err
}
}
ct.sort(ct.sortby, ct.sortdesc)
ct.updateTable() ct.updateTable()
ct.rowChanged()
} }
if v, err := g.SetView("status", 0, maxY-2, maxX, maxY); err != nil { if v, err := g.SetView("status", 0, maxY-2, maxX, maxY); err != nil {
@ -98,14 +91,15 @@ func (ct *Cointop) layout(g *gocui.Gui) error {
ct.updateStatus("") ct.updateStatus("")
} }
//ct.intervalFetchData()
return nil return nil
} }
func (ct *Cointop) fetchData() ([]*apitypes.Coin, error) { func (ct *Cointop) updateTable() error {
result := []*apitypes.Coin{} result := []*apitypes.Coin{}
coins, err := ct.api.GetAllCoinData() coins, err := ct.api.GetAllCoinData()
if err != nil { if err != nil {
return result, err return err
} }
for i := range coins { for i := range coins {
@ -113,5 +107,23 @@ func (ct *Cointop) fetchData() ([]*apitypes.Coin, error) {
result = append(result, &coin) result = append(result, &coin)
} }
return result, nil ct.coins = result
ct.sort(ct.sortby, ct.sortdesc)
ct.refreshTable()
ct.rowChanged()
return nil
}
func (ct *Cointop) intervalFetchData() {
ticker := time.NewTicker(5 * time.Second)
go func() {
for {
select {
case <-ticker.C:
ct.updateTable()
//ct.updateMarket()
//ct.updateChart()
}
}
}()
} }

@ -15,6 +15,7 @@ func (ct *Cointop) updateMarket() error {
return err return err
} }
timeframe := "7 Day" timeframe := "7 Day"
ct.marketview.Clear()
fmt.Fprintln(ct.marketview, pad.Right(fmt.Sprintf("%s Chart: %s • Total Market Cap: %s • 24H Volume: %s • BTC Dominance: %.2f%% • Active Currencies: %s • Active Markets: %s", color.Cyan("cointop"), timeframe, color.WhiteBold(humanize.Commaf(market.TotalMarketCapUSD)), humanize.Commaf(market.Total24HVolumeUSD), market.BitcoinPercentageOfMarketCap, humanize.Comma(int64(market.ActiveCurrencies)), humanize.Comma(int64(market.ActiveMarkets))), maxX, " ")) fmt.Fprintln(ct.marketview, pad.Right(fmt.Sprintf("%s Chart: %s • Total Market Cap: %s • 24H Volume: %s • BTC Dominance: %.2f%% • Active Currencies: %s • Active Markets: %s", color.Cyan("cointop"), timeframe, color.WhiteBold(humanize.Commaf(market.TotalMarketCapUSD)), humanize.Commaf(market.Total24HVolumeUSD), market.BitcoinPercentageOfMarketCap, humanize.Comma(int64(market.ActiveCurrencies)), humanize.Comma(int64(market.ActiveMarkets))), maxX, " "))
return nil return nil
} }

@ -12,7 +12,8 @@ import (
"github.com/miguelmota/cointop/pkg/table" "github.com/miguelmota/cointop/pkg/table"
) )
func (ct *Cointop) updateTable() error { func (ct *Cointop) refreshTable() error {
ct.tableview.Clear()
maxX, _ := ct.g.Size() maxX, _ := ct.g.Size()
ct.table = table.New().SetWidth(maxX) ct.table = table.New().SetWidth(maxX)
ct.table.AddCol("") ct.table.AddCol("")

Loading…
Cancel
Save