Merge branch 'simon-anz-feature/configurable-chart-range'

pull/151/head
Miguel Mota 3 years ago
commit 1c14561662
No known key found for this signature in database
GPG Key ID: 67EC1161588A00F9

@ -44,6 +44,7 @@ type State struct {
coinsTableColumns []string coinsTableColumns []string
convertMenuVisible bool convertMenuVisible bool
defaultView string defaultView string
defaultChartRange string
// DEPRECATED: favorites by 'symbol' is deprecated because of collisions. // DEPRECATED: favorites by 'symbol' is deprecated because of collisions.
favoritesBySymbol map[string]bool favoritesBySymbol map[string]bool
@ -243,6 +244,7 @@ func NewCointop(config *Config) (*Cointop, error) {
cacheDir: DefaultCacheDir, cacheDir: DefaultCacheDir,
coinsTableColumns: DefaultCoinTableHeaders, coinsTableColumns: DefaultCoinTableHeaders,
currencyConversion: DefaultCurrency, currencyConversion: DefaultCurrency,
defaultChartRange: DefaultChartRange,
// DEPRECATED: favorites by 'symbol' is deprecated because of collisions. Kept for backward compatibility. // DEPRECATED: favorites by 'symbol' is deprecated because of collisions. Kept for backward compatibility.
favoritesBySymbol: make(map[string]bool), favoritesBySymbol: make(map[string]bool),
favorites: make(map[string]bool), favorites: make(map[string]bool),

@ -31,18 +31,19 @@ var possibleConfigPaths = []string{
} }
type config struct { type config struct {
Shortcuts map[string]interface{} `toml:"shortcuts"` Shortcuts map[string]interface{} `toml:"shortcuts"`
Favorites map[string]interface{} `toml:"favorites"` Favorites map[string]interface{} `toml:"favorites"`
Portfolio map[string]interface{} `toml:"portfolio"` Portfolio map[string]interface{} `toml:"portfolio"`
PriceAlerts map[string]interface{} `toml:"price_alerts"` PriceAlerts map[string]interface{} `toml:"price_alerts"`
Currency interface{} `toml:"currency"` Currency interface{} `toml:"currency"`
DefaultView interface{} `toml:"default_view"` DefaultView interface{} `toml:"default_view"`
CoinMarketCap map[string]interface{} `toml:"coinmarketcap"` DefaultChartRange interface{} `toml:"default_chart_range"`
API interface{} `toml:"api"` CoinMarketCap map[string]interface{} `toml:"coinmarketcap"`
Colorscheme interface{} `toml:"colorscheme"` API interface{} `toml:"api"`
RefreshRate interface{} `toml:"refresh_rate"` Colorscheme interface{} `toml:"colorscheme"`
CacheDir interface{} `toml:"cache_dir"` RefreshRate interface{} `toml:"refresh_rate"`
Table map[string]interface{} `toml:"table"` CacheDir interface{} `toml:"cache_dir"`
Table map[string]interface{} `toml:"table"`
} }
// SetupConfig loads config file // SetupConfig loads config file
@ -69,6 +70,9 @@ func (ct *Cointop) SetupConfig() error {
if err := ct.loadDefaultViewFromConfig(); err != nil { if err := ct.loadDefaultViewFromConfig(); err != nil {
return err return err
} }
if err := ct.loadDefaultChartRangeFromConfig(); err != nil {
return err
}
if err := ct.loadAPIKeysFromConfig(); err != nil { if err := ct.loadAPIKeysFromConfig(); err != nil {
return err return err
} }
@ -255,6 +259,7 @@ func (ct *Cointop) configToToml() ([]byte, error) {
var currencyIfc interface{} = ct.State.currencyConversion var currencyIfc interface{} = ct.State.currencyConversion
var defaultViewIfc interface{} = ct.State.defaultView var defaultViewIfc interface{} = ct.State.defaultView
var defaultChartRangeIfc interface{} = ct.State.defaultChartRange
var colorschemeIfc interface{} = ct.colorschemeName var colorschemeIfc interface{} = ct.colorschemeName
var refreshRateIfc interface{} = uint(ct.State.refreshRate.Seconds()) var refreshRateIfc interface{} = uint(ct.State.refreshRate.Seconds())
var cacheDirIfc interface{} = ct.State.cacheDir var cacheDirIfc interface{} = ct.State.cacheDir
@ -289,18 +294,19 @@ func (ct *Cointop) configToToml() ([]byte, error) {
tableMapIfc["keep_row_focus_on_sort"] = keepRowFocusOnSortIfc tableMapIfc["keep_row_focus_on_sort"] = keepRowFocusOnSortIfc
var inputs = &config{ var inputs = &config{
API: apiChoiceIfc, API: apiChoiceIfc,
Colorscheme: colorschemeIfc, Colorscheme: colorschemeIfc,
CoinMarketCap: cmcIfc, CoinMarketCap: cmcIfc,
Currency: currencyIfc, Currency: currencyIfc,
DefaultView: defaultViewIfc, DefaultView: defaultViewIfc,
Favorites: favoritesMapIfc, DefaultChartRange: defaultChartRangeIfc,
RefreshRate: refreshRateIfc, Favorites: favoritesMapIfc,
Shortcuts: shortcutsIfcs, RefreshRate: refreshRateIfc,
Portfolio: portfolioIfc, Shortcuts: shortcutsIfcs,
PriceAlerts: priceAlertsMapIfc, Portfolio: portfolioIfc,
CacheDir: cacheDirIfc, PriceAlerts: priceAlertsMapIfc,
Table: tableMapIfc, CacheDir: cacheDirIfc,
Table: tableMapIfc,
} }
var b bytes.Buffer var b bytes.Buffer
@ -399,6 +405,21 @@ func (ct *Cointop) loadDefaultViewFromConfig() error {
return nil return nil
} }
// LoadDefaultChartRangeFromConfig loads default chart range from config file to struct
func (ct *Cointop) loadDefaultChartRangeFromConfig() error {
ct.debuglog("loadDefaultChartRangeFromConfig()")
if defaultChartRange, ok := ct.config.DefaultChartRange.(string); ok {
// validate configured value
_, present := ct.chartRangesMap[defaultChartRange]
if !present {
defaultChartRange = DefaultChartRange
}
ct.State.defaultChartRange = defaultChartRange
ct.State.selectedChartRange = defaultChartRange
}
return nil
}
// LoadAPIKeysFromConfig loads API keys from config file to struct // LoadAPIKeysFromConfig loads API keys from config file to struct
func (ct *Cointop) loadAPIKeysFromConfig() error { func (ct *Cointop) loadAPIKeysFromConfig() error {
ct.debuglog("loadAPIKeysFromConfig()") ct.debuglog("loadAPIKeysFromConfig()")

@ -39,6 +39,7 @@ You can configure the actions you want for each key in `config.toml`:
```toml ```toml
currency = "USD" currency = "USD"
default_view = "" default_view = ""
default_chart_range = "1Y"
api = "coingecko" api = "coingecko"
colorscheme = "cointop" colorscheme = "cointop"
refresh_rate = 60 refresh_rate = 60

@ -328,6 +328,12 @@ draft: false
In the config file, set `default_view = "default"` In the config file, set `default_view = "default"`
## How do I set the default chart range?
In the config file, set `default_chart_range = "3M"`
Supported date ranges are `All Time`, `YTD`, `1Y`, `6M`, `3M`, `1M`, `7D`, `3D`, `24H`.
## How can use a different config file other than the default? ## How can use a different config file other than the default?
Run cointop with the `--config` flag, eg `cointop --config="/path/to/config.toml"`, to use the specified file as the config. Run cointop with the `--config` flag, eg `cointop --config="/path/to/config.toml"`, to use the specified file as the config.

Loading…
Cancel
Save