|
|
|
@ -42,13 +42,13 @@ type ConfigFileConfig struct {
|
|
|
|
|
Currency interface{} `toml:"currency"`
|
|
|
|
|
DefaultView interface{} `toml:"default_view"`
|
|
|
|
|
DefaultChartRange interface{} `toml:"default_chart_range"`
|
|
|
|
|
MaxChartWidth interface{} `toml:"max_chart_width"`
|
|
|
|
|
CoinMarketCap map[string]interface{} `toml:"coinmarketcap"`
|
|
|
|
|
API interface{} `toml:"api"`
|
|
|
|
|
Colorscheme interface{} `toml:"colorscheme"`
|
|
|
|
|
RefreshRate interface{} `toml:"refresh_rate"`
|
|
|
|
|
CacheDir interface{} `toml:"cache_dir"`
|
|
|
|
|
Table map[string]interface{} `toml:"table"`
|
|
|
|
|
Chart map[string]interface{} `toml:"chart"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetupConfig loads config file
|
|
|
|
@ -63,6 +63,9 @@ func (ct *Cointop) SetupConfig() error {
|
|
|
|
|
if err := ct.loadTableConfig(); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if err := ct.loadChartConfig(); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if err := ct.loadShortcutsFromConfig(); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
@ -78,9 +81,6 @@ func (ct *Cointop) SetupConfig() error {
|
|
|
|
|
if err := ct.loadDefaultChartRangeFromConfig(); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if err := ct.loadMaxChartWidthFromConfig(); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if err := ct.loadAPIKeysFromConfig(); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
@ -268,7 +268,6 @@ func (ct *Cointop) ConfigToToml() ([]byte, error) {
|
|
|
|
|
var currencyIfc interface{} = ct.State.currencyConversion
|
|
|
|
|
var defaultViewIfc interface{} = ct.State.defaultView
|
|
|
|
|
var defaultChartRangeIfc interface{} = ct.State.defaultChartRange
|
|
|
|
|
var maxChartWidth interface{} = ct.State.maxChartWidth
|
|
|
|
|
var colorschemeIfc interface{} = ct.colorschemeName
|
|
|
|
|
var refreshRateIfc interface{} = uint(ct.State.refreshRate.Seconds())
|
|
|
|
|
var cacheDirIfc interface{} = ct.State.cacheDir
|
|
|
|
@ -302,6 +301,11 @@ func (ct *Cointop) ConfigToToml() ([]byte, error) {
|
|
|
|
|
var keepRowFocusOnSortIfc interface{} = ct.State.keepRowFocusOnSort
|
|
|
|
|
tableMapIfc["keep_row_focus_on_sort"] = keepRowFocusOnSortIfc
|
|
|
|
|
|
|
|
|
|
chartMapIfc := map[string]interface{}{}
|
|
|
|
|
chartMapIfc["max_width"] = ct.State.maxChartWidth
|
|
|
|
|
chartMapIfc["height"] = ct.State.chartHeight
|
|
|
|
|
log.Debugf("XXX chart = %s", chartMapIfc)
|
|
|
|
|
|
|
|
|
|
var inputs = &ConfigFileConfig{
|
|
|
|
|
API: apiChoiceIfc,
|
|
|
|
|
Colorscheme: colorschemeIfc,
|
|
|
|
@ -309,7 +313,6 @@ func (ct *Cointop) ConfigToToml() ([]byte, error) {
|
|
|
|
|
Currency: currencyIfc,
|
|
|
|
|
DefaultView: defaultViewIfc,
|
|
|
|
|
DefaultChartRange: defaultChartRangeIfc,
|
|
|
|
|
MaxChartWidth: maxChartWidth,
|
|
|
|
|
Favorites: favoritesMapIfc,
|
|
|
|
|
RefreshRate: refreshRateIfc,
|
|
|
|
|
Shortcuts: shortcutsIfcs,
|
|
|
|
@ -317,6 +320,7 @@ func (ct *Cointop) ConfigToToml() ([]byte, error) {
|
|
|
|
|
PriceAlerts: priceAlertsMapIfc,
|
|
|
|
|
CacheDir: cacheDirIfc,
|
|
|
|
|
Table: tableMapIfc,
|
|
|
|
|
Chart: chartMapIfc,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var b bytes.Buffer
|
|
|
|
@ -344,6 +348,21 @@ func (ct *Cointop) loadTableConfig() error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// LoadChartConfig loads chart config from toml config into state struct
|
|
|
|
|
func (ct *Cointop) loadChartConfig() error {
|
|
|
|
|
log.Debugf("loadChartConfig()")
|
|
|
|
|
maxChartWidthIfc, ok := ct.config.Chart["max_width"]
|
|
|
|
|
if ok {
|
|
|
|
|
ct.State.maxChartWidth = int(maxChartWidthIfc.(int64))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
chartHeightIfc, ok := ct.config.Chart["height"]
|
|
|
|
|
if ok {
|
|
|
|
|
ct.State.chartHeight = int(chartHeightIfc.(int64))
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// LoadTableColumnsFromConfig loads preferred coins table columns from config file to struct
|
|
|
|
|
func (ct *Cointop) loadTableColumnsFromConfig() error {
|
|
|
|
|
log.Debug("loadTableColumnsFromConfig()")
|
|
|
|
@ -431,16 +450,6 @@ func (ct *Cointop) loadDefaultChartRangeFromConfig() error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// loadMaxChartWidthFromConfig loads max chart width from config file to struct
|
|
|
|
|
func (ct *Cointop) loadMaxChartWidthFromConfig() error {
|
|
|
|
|
log.Debug("loadMaxChartWidthFromConfig()")
|
|
|
|
|
if maxChartWidth, ok := ct.config.MaxChartWidth.(int64); ok {
|
|
|
|
|
ct.State.maxChartWidth = int(maxChartWidth)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// LoadAPIKeysFromConfig loads API keys from config file to struct
|
|
|
|
|
func (ct *Cointop) loadAPIKeysFromConfig() error {
|
|
|
|
|
log.Debug("loadAPIKeysFromConfig()")
|
|
|
|
|