Rudimentary configuration for scaling available_supply, 24h_volume, market_cap

pull/200/head
Simon Roberts 3 years ago
parent 3400b7bcc4
commit 37fb0d8ecd
No known key found for this signature in database
GPG Key ID: 0F30F99E6B771FD4

@ -136,7 +136,7 @@ func (ct *Cointop) GetCoinsTable() *table.Table {
})
case "24h_volume":
text := humanize.Monetaryf(coin.Volume24H, 0)
if DefaultScaleNumbers {
if ct.State.scaleNumbers {
volScale, volSuffix := humanize.Scale(coin.Volume24H)
text = humanize.Numericf(volScale, 1) + volSuffix
}
@ -247,7 +247,7 @@ func (ct *Cointop) GetCoinsTable() *table.Table {
})
case "market_cap":
text := humanize.Monetaryf(coin.MarketCap, 0)
if DefaultScaleNumbers {
if ct.State.scaleNumbers {
volScale, volSuffix := humanize.Scale(coin.MarketCap)
text = humanize.Numericf(volScale, 1) + volSuffix
}
@ -275,7 +275,7 @@ func (ct *Cointop) GetCoinsTable() *table.Table {
})
case "available_supply":
text := humanize.Numericf(coin.AvailableSupply, 0)
if DefaultScaleNumbers {
if ct.State.scaleNumbers {
volScale, volSuffix := humanize.Scale(coin.AvailableSupply)
text = humanize.Numericf(volScale, 1) + volSuffix
}

@ -39,6 +39,7 @@ type State struct {
allCoins []*Coin
allCoinsSlugMap sync.Map
cacheDir string
scaleNumbers bool
coins []*Coin
chartPoints [][]rune
currencyConversion string
@ -182,7 +183,7 @@ var DefaultCurrency = "USD"
var DefaultChartRange = "1Y"
// DefaultScaleNumbers ...
var DefaultScaleNumbers = true
var DefaultScaleNumbers = false
// DefaultMaxChartWidth ...
var DefaultMaxChartWidth int = 175
@ -256,6 +257,7 @@ func NewCointop(config *Config) (*Cointop, error) {
State: &State{
allCoins: []*Coin{},
cacheDir: DefaultCacheDir,
scaleNumbers: DefaultScaleNumbers,
coinsTableColumns: DefaultCoinTableHeaders,
currencyConversion: DefaultCurrency,
defaultChartRange: DefaultChartRange,

@ -48,6 +48,7 @@ type ConfigFileConfig struct {
Colorscheme interface{} `toml:"colorscheme"`
RefreshRate interface{} `toml:"refresh_rate"`
CacheDir interface{} `toml:"cache_dir"`
ScaleNumbers interface{} `toml:"scale_numbers"`
Table map[string]interface{} `toml:"table"`
Chart map[string]interface{} `toml:"chart"`
}
@ -70,6 +71,7 @@ func (ct *Cointop) SetupConfig() error {
ct.loadColorschemeFromConfig,
ct.loadRefreshRateFromConfig,
ct.loadCacheDirFromConfig,
ct.loadScaleNumbersFromConfig,
ct.loadPriceAlertsFromConfig,
ct.loadPortfolioFromConfig,
}
@ -284,6 +286,7 @@ func (ct *Cointop) ConfigToToml() ([]byte, error) {
Portfolio: portfolioIfc,
PriceAlerts: priceAlertsMapIfc,
CacheDir: ct.State.cacheDir,
ScaleNumbers: ct.State.scaleNumbers,
Table: tableMapIfc,
Chart: chartMapIfc,
}
@ -458,6 +461,16 @@ func (ct *Cointop) loadCacheDirFromConfig() error {
return nil
}
// LoadScaleNumbersFromConfig loads scale-numbers setting from config file to struct
func (ct *Cointop) loadScaleNumbersFromConfig() error {
log.Debug("loadScaleNumbersFromConfig()")
if scaleNumbers, ok := ct.config.ScaleNumbers.(bool); ok {
ct.State.scaleNumbers = scaleNumbers
}
return nil
}
// LoadAPIChoiceFromConfig loads API choices from config file to struct
func (ct *Cointop) loadAPIChoiceFromConfig() error {
log.Debug("loadAPIKeysFromConfig()")

@ -128,8 +128,9 @@ var HeaderColumns = map[string]*HeaderColumn{
}
// GetLabel fetch the label to use for the heading (depends on configuration)
func (h HeaderColumn) GetLabel() string {
if DefaultScaleNumbers && h.ShortLabel != "" {
func (ct *Cointop) GetLabel(h HeaderColumn) string {
// TODO: technically this should support nosort
if ct.State.scaleNumbers && h.ShortLabel != "" {
return h.ShortLabel
}
return h.Label
@ -188,7 +189,7 @@ func (ct *Cointop) UpdateTableHeader() error {
}
}
}
label := hc.GetLabel()
label := ct.GetLabel(*hc)
if noSort {
label = hc.PlainLabel
}
@ -253,7 +254,7 @@ func (ct *Cointop) SetTableColumnWidth(header string, width int) {
prev = prevIfc.(int)
} else {
hc := HeaderColumns[header]
prev = utf8.RuneCountInString(hc.GetLabel()) + 1
prev = utf8.RuneCountInString(ct.GetLabel(*hc)) + 1
switch header {
case "price", "balance":
prev++

Loading…
Cancel
Save