diff --git a/cointop/coins_table.go b/cointop/coins_table.go index 1cf8070..7c75b27 100644 --- a/cointop/coins_table.go +++ b/cointop/coins_table.go @@ -21,8 +21,8 @@ var SupportedCoinTableHeaders = []string{ "30d_change", "24h_volume", "market_cap", - "total_supply", "available_supply", + "total_supply", "last_updated", } @@ -37,8 +37,8 @@ var DefaultCoinTableHeaders = []string{ "7d_change", "24h_volume", "market_cap", - "total_supply", "available_supply", + "total_supply", "last_updated", } diff --git a/cointop/cointop.go b/cointop/cointop.go index d6efb0f..e9174bc 100644 --- a/cointop/cointop.go +++ b/cointop/cointop.go @@ -83,32 +83,31 @@ type State struct { // Cointop cointop type Cointop struct { - g *gocui.Gui - ui *ui.UI - ActionsMap map[string]bool - apiKeys *APIKeys - cache *cache.Cache - colorsDir string - config config // toml config - configFilepath string - api api.Interface - apiChoice string - chartRanges []string - chartRangesMap map[string]time.Duration - colorschemeName string - colorscheme *Colorscheme - debug bool - filecache *filecache.FileCache - forceRefresh chan bool - limiter <-chan time.Time - maxTableWidth int - refreshMux sync.Mutex - refreshTicker *time.Ticker - saveMux sync.Mutex - State *State - table *table.Table - TableColumnOrder []string - Views *Views + g *gocui.Gui + ui *ui.UI + ActionsMap map[string]bool + apiKeys *APIKeys + cache *cache.Cache + colorsDir string + config config // toml config + configFilepath string + api api.Interface + apiChoice string + chartRanges []string + chartRangesMap map[string]time.Duration + colorschemeName string + colorscheme *Colorscheme + debug bool + filecache *filecache.FileCache + forceRefresh chan bool + limiter <-chan time.Time + maxTableWidth int + refreshMux sync.Mutex + refreshTicker *time.Ticker + saveMux sync.Mutex + State *State + table *table.Table + Views *Views } // PortfolioEntry is portfolio entry @@ -266,7 +265,6 @@ func NewCointop(config *Config) (*Cointop, error) { SoundEnabled: true, }, }, - TableColumnOrder: TableColumnOrder(), Views: &Views{ Chart: NewChartView(), Table: NewTableView(), diff --git a/cointop/sort.go b/cointop/sort.go index 7d11dcb..44a3342 100644 --- a/cointop/sort.go +++ b/cointop/sort.go @@ -94,13 +94,13 @@ func (ct *Cointop) SortDesc() error { // SortPrevCol sorts the previous column func (ct *Cointop) SortPrevCol() error { ct.debuglog("sortPrevCol()") + cols := ct.GetActiveTableHeaders() i := ct.GetSortColIndex() k := i - 1 if k < 0 { k = 0 } - - nextsortBy := ct.TableColumnOrder[k] + nextsortBy := cols[k] ct.Sort(nextsortBy, ct.State.sortDesc, ct.State.coins, true) ct.UpdateTable() return nil @@ -109,14 +109,14 @@ func (ct *Cointop) SortPrevCol() error { // SortNextCol sorts the next column func (ct *Cointop) SortNextCol() error { ct.debuglog("sortNextCol()") - l := len(ct.TableColumnOrder) + cols := ct.GetActiveTableHeaders() + l := len(cols) i := ct.GetSortColIndex() k := i + 1 if k > l-1 { k = l - 1 } - - nextsortBy := ct.TableColumnOrder[k] + nextsortBy := cols[k] ct.Sort(nextsortBy, ct.State.sortDesc, ct.State.coins, true) ct.UpdateTable() return nil @@ -156,7 +156,8 @@ func (ct *Cointop) Sortfn(sortBy string, desc bool) func(g *gocui.Gui, v *gocui. // GetSortColIndex gets the sort column index func (ct *Cointop) GetSortColIndex() int { ct.debuglog("getSortColIndex()") - for i, col := range ct.TableColumnOrder { + cols := ct.GetActiveTableHeaders() + for i, col := range cols { if ct.State.sortBy == col { return i } diff --git a/cointop/table.go b/cointop/table.go index e4b97a8..c3bef13 100644 --- a/cointop/table.go +++ b/cointop/table.go @@ -18,26 +18,6 @@ func NewTableView() *TableView { return view } -// TableColumnOrder returns the default order of the table columns -func TableColumnOrder() []string { - return []string{ - "rank", - "name", - "symbol", - "price", - "holdings", - "balance", - "market_cap", - "24h_volume", - "1h_change", - "7d_change", - "total_supply", - "available_supply", - "percent_holdings", - "last_updated", - } -} - const dots = "..." // RefreshTable refreshes the table diff --git a/cointop/table_header.go b/cointop/table_header.go index 7452aea..df88fe9 100644 --- a/cointop/table_header.go +++ b/cointop/table_header.go @@ -126,12 +126,8 @@ func NewTableHeaderView() *TableHeaderView { return view } -// UpdateTableHeader renders the table header -func (ct *Cointop) UpdateTableHeader() error { - ct.debuglog("UpdateTableHeader()") - - baseColor := ct.colorscheme.TableHeaderSprintf() - noSort := ct.IsPriceAlertsVisible() +// GetActiveTableHeaders returns the list of active table headers +func (ct *Cointop) GetActiveTableHeaders() []string { var cols []string switch ct.State.selectedView { case PortfolioView: @@ -141,7 +137,17 @@ func (ct *Cointop) UpdateTableHeader() error { default: cols = ct.GetCoinsTableHeaders() } + return cols +} + +// UpdateTableHeader renders the table header +func (ct *Cointop) UpdateTableHeader() error { + ct.debuglog("UpdateTableHeader()") + + baseColor := ct.colorscheme.TableHeaderSprintf() + noSort := ct.IsPriceAlertsVisible() + cols := ct.GetActiveTableHeaders() var headers []string for i, col := range cols { hc, ok := HeaderColumns[col]