Former-commit-id: 1c64d4a067c68f64d02737472b2f42d8b4868d30 [formerly 1c64d4a067c68f64d02737472b2f42d8b4868d30 [formerly 0553194e516b6433270cb4fd8c41392fc4ee22e3 [formerly 0c842dac32]]]
Former-commit-id: 512fe94317ae26c0778663381c07381b0f7cad75
Former-commit-id: 4362b8e1360c2aed98d6e9726244e2e246d7dd73 [formerly ccad131add3fe8b9b8841b2758e958a82d97a595]
Former-commit-id: 40a20d88395729060edcba639d22ba3e52c2faa5
pull/15/head
Miguel Mota 6 years ago
parent 6cb7c86c39
commit ad9ab777d8

6
Gopkg.lock generated

@ -13,12 +13,6 @@
packages = ["."]
revision = "d9036e2120b5ddfa53f3ebccd618c4af275f47da"
[[projects]]
branch = "master"
name = "github.com/dustin/go-humanize"
packages = ["."]
revision = "bb3d318650d48840a39aa21a027c6630e198e626"
[[projects]]
name = "github.com/fatih/color"
packages = ["."]

@ -29,10 +29,6 @@
branch = "master"
name = "github.com/bradfitz/slice"
[[constraint]]
branch = "master"
name = "github.com/dustin/go-humanize"
[[constraint]]
name = "github.com/fatih/color"
version = "1.6.0"

@ -8,7 +8,7 @@ import (
"github.com/gizak/termui"
"github.com/jroimartin/gocui"
"github.com/miguelmota/cointop/pkg/api"
apitypes "github.com/miguelmota/cointop/pkg/api/types"
apt "github.com/miguelmota/cointop/pkg/api/types"
"github.com/miguelmota/cointop/pkg/table"
)
@ -34,9 +34,9 @@ type Cointop struct {
sortdesc bool
sortby string
api api.Interface
allcoins []*apitypes.Coin
coins []*apitypes.Coin
allcoinsmap map[string]apitypes.Coin
allcoins []*apt.Coin
coins []*apt.Coin
allcoinsmap map[string]apt.Coin
page int
perpage int
refreshmux sync.Mutex

@ -6,7 +6,7 @@ import (
"time"
"github.com/jroimartin/gocui"
apitypes "github.com/miguelmota/cointop/pkg/api/types"
apt "github.com/miguelmota/cointop/pkg/api/types"
"github.com/miguelmota/cointop/pkg/pad"
"github.com/miguelmota/cointop/pkg/table"
)
@ -100,7 +100,7 @@ func (ct *Cointop) layout(g *gocui.Gui) error {
}
func (ct *Cointop) updateCoins() error {
list := []*apitypes.Coin{}
list := []*apt.Coin{}
allcoinsmap, err := ct.api.GetAllCoinData()
if err != nil {
return err

@ -3,8 +3,8 @@ package cointop
import (
"fmt"
humanize "github.com/dustin/go-humanize"
"github.com/miguelmota/cointop/pkg/color"
"github.com/miguelmota/cointop/pkg/humanize"
"github.com/miguelmota/cointop/pkg/pad"
)
@ -16,6 +16,6 @@ func (ct *Cointop) updateMarket() error {
}
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.Commaf(float64(market.ActiveCurrencies)), humanize.Commaf(float64(market.ActiveMarkets))), maxX, " "))
return nil
}

@ -3,10 +3,10 @@ package cointop
import (
"github.com/bradfitz/slice"
"github.com/jroimartin/gocui"
apitypes "github.com/miguelmota/cointop/pkg/api/types"
apt "github.com/miguelmota/cointop/pkg/api/types"
)
func (ct *Cointop) sort(sortby string, desc bool, list []*apitypes.Coin) {
func (ct *Cointop) sort(sortby string, desc bool, list []*apt.Coin) {
ct.sortby = sortby
ct.sortdesc = desc
slice.Sort(list[:], func(i, j int) bool {

@ -6,10 +6,10 @@ import (
"strings"
"time"
humanize "github.com/dustin/go-humanize"
"github.com/jroimartin/gocui"
apitypes "github.com/miguelmota/cointop/pkg/api/types"
apt "github.com/miguelmota/cointop/pkg/api/types"
"github.com/miguelmota/cointop/pkg/color"
"github.com/miguelmota/cointop/pkg/humanize"
"github.com/miguelmota/cointop/pkg/table"
)
@ -99,7 +99,7 @@ func (ct *Cointop) selectedRowIndex() int {
return idx
}
func (ct *Cointop) selectedCoin() *apitypes.Coin {
func (ct *Cointop) selectedCoin() *apt.Coin {
idx := ct.selectedRowIndex()
return ct.coins[idx]
}

@ -0,0 +1,40 @@
package humanize
import (
"bytes"
"strconv"
"strings"
)
// Commaf produces a string form of the given number in base 10 with
// commas after every three orders of magnitude.
//
// e.g. Commaf(834142.32) -> 834,142.32
func Commaf(v float64) string {
buf := &bytes.Buffer{}
if v < 0 {
buf.Write([]byte{'-'})
v = 0 - v
}
comma := []byte{','}
parts := strings.Split(strconv.FormatFloat(v, 'f', -1, 64), ".")
pos := 0
if len(parts[0])%3 != 0 {
pos += len(parts[0]) % 3
buf.WriteString(parts[0][:pos])
buf.Write(comma)
}
for ; pos < len(parts[0]); pos += 3 {
buf.WriteString(parts[0][pos : pos+3])
buf.Write(comma)
}
buf.Truncate(buf.Len() - 1)
if len(parts) > 1 {
buf.Write([]byte{'.'})
buf.WriteString(parts[1])
}
return buf.String()
}
Loading…
Cancel
Save