Make separate configuration for coin table, favorites table, portfolio table and market bar

pull/200/head
Simon Roberts 3 years ago
parent 648a8e772d
commit e57d3c94ff
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 ct.State.compactNotation {
if ct.GetActiveTableCompactNotation() {
text = humanize.ScaleNumericf(coin.Volume24H, 3)
}
ct.SetTableColumnWidthFromString(header, text)
@ -246,7 +246,7 @@ func (ct *Cointop) GetCoinsTable() *table.Table {
})
case "market_cap":
text := humanize.Monetaryf(coin.MarketCap, 0)
if ct.State.compactNotation {
if ct.GetActiveTableCompactNotation() {
text = humanize.ScaleNumericf(coin.MarketCap, 3)
}
ct.SetTableColumnWidthFromString(header, text)
@ -261,7 +261,7 @@ func (ct *Cointop) GetCoinsTable() *table.Table {
})
case "total_supply":
text := humanize.Numericf(coin.TotalSupply, 0)
if ct.State.compactNotation {
if ct.GetActiveTableCompactNotation() {
text = humanize.ScaleNumericf(coin.TotalSupply, 3)
}
ct.SetTableColumnWidthFromString(header, text)
@ -276,7 +276,7 @@ func (ct *Cointop) GetCoinsTable() *table.Table {
})
case "available_supply":
text := humanize.Numericf(coin.AvailableSupply, 0)
if ct.State.compactNotation {
if ct.GetActiveTableCompactNotation() {
text = humanize.ScaleNumericf(coin.AvailableSupply, 3)
}
ct.SetTableColumnWidthFromString(header, text)

@ -39,7 +39,6 @@ type State struct {
allCoins []*Coin
allCoinsSlugMap sync.Map
cacheDir string
compactNotation bool
coins []*Coin
chartPoints [][]rune
currencyConversion string
@ -90,6 +89,11 @@ type State struct {
priceAlerts *PriceAlerts
priceAlertEditID string
priceAlertNewID string
compactNotation bool
tableCompactNotation bool
favoritesCompactNotation bool
portfolioCompactNotation bool
}
// Cointop cointop
@ -257,7 +261,6 @@ func NewCointop(config *Config) (*Cointop, error) {
State: &State{
allCoins: []*Coin{},
cacheDir: DefaultCacheDir,
compactNotation: DefaultCompactNotation,
coinsTableColumns: DefaultCoinTableHeaders,
currencyConversion: DefaultCurrency,
defaultChartRange: DefaultChartRange,
@ -296,6 +299,10 @@ func NewCointop(config *Config) (*Cointop, error) {
Entries: make([]*PriceAlert, 0),
SoundEnabled: true,
},
compactNotation: DefaultCompactNotation,
tableCompactNotation: DefaultCompactNotation,
favoritesCompactNotation: DefaultCompactNotation,
portfolioCompactNotation: DefaultCompactNotation,
},
Views: &Views{
Chart: NewChartView(),

@ -217,10 +217,11 @@ func (ct *Cointop) ConfigToToml() ([]byte, error) {
var favoritesBySymbolIfc []interface{}
favoritesMapIfc := map[string]interface{}{
// DEPRECATED: favorites by 'symbol' is deprecated because of collisions. Kept for backward compatibility.
"symbols": favoritesBySymbolIfc,
"names": favoritesIfc,
"columns": ct.State.favoritesTableColumns,
"character": ct.State.favoriteChar,
"symbols": favoritesBySymbolIfc,
"names": favoritesIfc,
"columns": ct.State.favoritesTableColumns,
"character": ct.State.favoriteChar,
"compact_notation": ct.State.favoritesCompactNotation,
}
var holdingsIfc [][]string
@ -238,8 +239,9 @@ func (ct *Cointop) ConfigToToml() ([]byte, error) {
return holdingsIfc[i][0] < holdingsIfc[j][0]
})
portfolioIfc := map[string]interface{}{
"holdings": holdingsIfc,
"columns": ct.State.portfolioTableColumns,
"holdings": holdingsIfc,
"columns": ct.State.portfolioTableColumns,
"compact_notation": ct.State.portfolioCompactNotation,
}
cmcIfc := map[string]interface{}{
@ -266,6 +268,7 @@ func (ct *Cointop) ConfigToToml() ([]byte, error) {
tableMapIfc := map[string]interface{}{
"columns": ct.State.coinsTableColumns,
"keep_row_focus_on_sort": ct.State.keepRowFocusOnSort,
"compact_notation": ct.State.tableCompactNotation,
}
chartMapIfc := map[string]interface{}{
@ -286,7 +289,6 @@ func (ct *Cointop) ConfigToToml() ([]byte, error) {
Portfolio: portfolioIfc,
PriceAlerts: priceAlertsMapIfc,
CacheDir: ct.State.cacheDir,
CompactNotation: ct.State.compactNotation,
Table: tableMapIfc,
Chart: chartMapIfc,
}
@ -313,6 +315,11 @@ func (ct *Cointop) loadTableConfig() error {
if ok {
ct.State.keepRowFocusOnSort = keepRowFocusOnSortIfc.(bool)
}
if compactNotation, ok := ct.config.Table["compact_notation"]; ok {
ct.State.tableCompactNotation = compactNotation.(bool)
}
return nil
}
@ -493,6 +500,8 @@ func (ct *Cointop) loadFavoritesFromConfig() error {
}
ct.State.favoriteChar = favoriteChar
}
} else if k == "compact_notation" {
ct.State.favoritesCompactNotation = valueIfc.(bool)
}
ifcs, ok := valueIfc.([]interface{})
if !ok {
@ -581,6 +590,8 @@ func (ct *Cointop) loadPortfolioFromConfig() error {
return err
}
}
} else if key == "compact_notation" {
ct.State.portfolioCompactNotation = valueIfc.(bool)
} else {
// Backward compatibility < v1.6.0
holdings, err := ct.InterfaceToFloat64(valueIfc)

@ -154,12 +154,19 @@ func (ct *Cointop) UpdateMarketbar() error {
separator2 = "\n" + offset
}
marketCapStr := humanize.Monetaryf(market.TotalMarketCapUSD, 0)
volumeStr := humanize.Monetaryf(market.Total24HVolumeUSD, 0)
if ct.State.compactNotation {
marketCapStr = humanize.ScaleNumericf(market.TotalMarketCapUSD, 3)
volumeStr = humanize.ScaleNumericf(market.Total24HVolumeUSD, 3)
}
content = fmt.Sprintf(
"%sGlobal ▶ Market Cap: %s %s 24H Volume: %s %s BTC Dominance: %.2f%%",
chartInfo,
fmt.Sprintf("%s%s", ct.CurrencySymbol(), humanize.Monetaryf(market.TotalMarketCapUSD, 0)),
fmt.Sprintf("%s%s", ct.CurrencySymbol(), marketCapStr),
separator1,
fmt.Sprintf("%s%s", ct.CurrencySymbol(), humanize.Monetaryf(market.Total24HVolumeUSD, 0)),
fmt.Sprintf("%s%s", ct.CurrencySymbol(), volumeStr),
separator2,
market.BitcoinPercentageOfMarketCap,
)

@ -131,7 +131,8 @@ var HeaderColumns = map[string]*HeaderColumn{
// GetLabel fetch the label to use for the heading (depends on configuration)
func (ct *Cointop) GetLabel(h *HeaderColumn) string {
// TODO: technically this should support nosort
if ct.State.compactNotation && h.ShortLabel != "" {
compactNotation := ct.GetActiveTableCompactNotation()
if compactNotation && h.ShortLabel != "" {
return h.ShortLabel
}
return h.Label
@ -160,6 +161,22 @@ func (ct *Cointop) GetActiveTableHeaders() []string {
return cols
}
// GetActiveTableHeaders returns the list of active table headers
func (ct *Cointop) GetActiveTableCompactNotation() bool {
var compact bool
switch ct.State.selectedView {
case PortfolioView:
compact = ct.State.portfolioCompactNotation
case CoinsView:
compact = ct.State.tableCompactNotation
case FavoritesView:
compact = ct.State.favoritesCompactNotation
default:
compact = ct.State.tableCompactNotation
}
return compact
}
// UpdateTableHeader renders the table header
func (ct *Cointop) UpdateTableHeader() error {
log.Debug("UpdateTableHeader()")

Loading…
Cancel
Save