2
0
mirror of https://github.com/miguelmota/cointop synced 2024-11-05 00:00:14 +00:00

Move maxChartWidth to ct.State

This commit is contained in:
Simon Roberts 2021-09-29 08:47:42 +10:00
parent 9a270d4b19
commit caccc13ea0
No known key found for this signature in database
GPG Key ID: 0F30F99E6B771FD4
3 changed files with 19 additions and 5 deletions

View File

@ -453,7 +453,7 @@ func (ct *Cointop) ShowChartLoader() error {
func (ct *Cointop) ChartWidth() int {
log.Debug("ChartWidth()")
w := ct.Width()
max := int(ct.config.MaxChartWidth.(int64))
max := ct.State.maxChartWidth
if max > 0 && w > max {
return max
}

View File

@ -46,6 +46,7 @@ type State struct {
convertMenuVisible bool
defaultView string
defaultChartRange string
maxChartWidth int
// DEPRECATED: favorites by 'symbol' is deprecated because of collisions.
favoritesBySymbol map[string]bool
@ -110,7 +111,6 @@ type Cointop struct {
forceRefresh chan bool
limiter <-chan time.Time
maxTableWidth int
maxChartWidth int
refreshMux sync.Mutex
refreshTicker *time.Ticker
saveMux sync.Mutex
@ -238,7 +238,6 @@ func NewCointop(config *Config) (*Cointop, error) {
apiKeys: new(APIKeys),
forceRefresh: make(chan bool),
maxTableWidth: DefaultMaxTableWidth,
maxChartWidth: DefaultMaxChartWidth,
ActionsMap: ActionsMap(),
cache: cache.New(1*time.Minute, 2*time.Minute),
colorsDir: config.ColorsDir,
@ -253,6 +252,7 @@ func NewCointop(config *Config) (*Cointop, error) {
coinsTableColumns: DefaultCoinTableHeaders,
currencyConversion: DefaultCurrency,
defaultChartRange: DefaultChartRange,
maxChartWidth: DefaultMaxChartWidth,
// DEPRECATED: favorites by 'symbol' is deprecated because of collisions. Kept for backward compatibility.
favoritesBySymbol: make(map[string]bool),
favorites: make(map[string]bool),

View File

@ -79,6 +79,10 @@ func (ct *Cointop) SetupConfig() error {
if err := ct.loadDefaultChartRangeFromConfig(); err != nil {
return err
}
if err := ct.loadMaxChartWidthFromConfig(); err != nil {
log.Debug("SetupConfig() ERR", err)
return err
}
if err := ct.loadAPIKeysFromConfig(); err != nil {
return err
}
@ -266,8 +270,8 @@ 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 maxTableWidth interface{} = ct.maxChartWidth
var maxChartWidth interface{} = ct.maxChartWidth
var maxTableWidth interface{} = ct.maxTableWidth
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
@ -431,6 +435,16 @@ 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()")