mirror of
https://github.com/miguelmota/cointop
synced 2024-11-05 00:00:14 +00:00
Make favorite character configurable (#190)
* Make favorite character configurable
This commit is contained in:
parent
cc325b9d4e
commit
0bacbe5b9d
@ -82,7 +82,7 @@ func (ct *Cointop) GetCoinsTable() *table.Table {
|
|||||||
star := " "
|
star := " "
|
||||||
rankcolor := ct.colorscheme.TableRow
|
rankcolor := ct.colorscheme.TableRow
|
||||||
if coin.Favorite {
|
if coin.Favorite {
|
||||||
star = "*"
|
star = ct.State.favoriteChar
|
||||||
rankcolor = ct.colorscheme.TableRowFavorite
|
rankcolor = ct.colorscheme.TableRowFavorite
|
||||||
}
|
}
|
||||||
rank := fmt.Sprintf("%s%6v ", star, coin.Rank)
|
rank := fmt.Sprintf("%s%6v ", star, coin.Rank)
|
||||||
|
@ -53,6 +53,7 @@ type State struct {
|
|||||||
|
|
||||||
favorites map[string]bool
|
favorites map[string]bool
|
||||||
favoritesTableColumns []string
|
favoritesTableColumns []string
|
||||||
|
favoriteChar string
|
||||||
helpVisible bool
|
helpVisible bool
|
||||||
hideMarketbar bool
|
hideMarketbar bool
|
||||||
hideChart bool
|
hideChart bool
|
||||||
@ -207,6 +208,9 @@ var DefaultCacheDir = filecache.DefaultCacheDir
|
|||||||
// DefaultColorsDir ...
|
// DefaultColorsDir ...
|
||||||
var DefaultColorsDir = fmt.Sprintf("%s/colors", DefaultConfigFilepath)
|
var DefaultColorsDir = fmt.Sprintf("%s/colors", DefaultConfigFilepath)
|
||||||
|
|
||||||
|
// DefaultFavoriteChar ...
|
||||||
|
var DefaultFavoriteChar = "*"
|
||||||
|
|
||||||
// NewCointop initializes cointop
|
// NewCointop initializes cointop
|
||||||
func NewCointop(config *Config) (*Cointop, error) {
|
func NewCointop(config *Config) (*Cointop, error) {
|
||||||
if os.Getenv("DEBUG") != "" {
|
if os.Getenv("DEBUG") != "" {
|
||||||
@ -257,6 +261,7 @@ func NewCointop(config *Config) (*Cointop, error) {
|
|||||||
favoritesBySymbol: make(map[string]bool),
|
favoritesBySymbol: make(map[string]bool),
|
||||||
favorites: make(map[string]bool),
|
favorites: make(map[string]bool),
|
||||||
favoritesTableColumns: DefaultCoinTableHeaders,
|
favoritesTableColumns: DefaultCoinTableHeaders,
|
||||||
|
favoriteChar: DefaultFavoriteChar,
|
||||||
hideMarketbar: config.HideMarketbar,
|
hideMarketbar: config.HideMarketbar,
|
||||||
hideChart: config.HideChart,
|
hideChart: config.HideChart,
|
||||||
hideTable: config.HideTable,
|
hideTable: config.HideTable,
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
"unicode/utf8"
|
||||||
|
|
||||||
"github.com/miguelmota/cointop/pkg/pathutil"
|
"github.com/miguelmota/cointop/pkg/pathutil"
|
||||||
"github.com/miguelmota/cointop/pkg/toml"
|
"github.com/miguelmota/cointop/pkg/toml"
|
||||||
@ -244,6 +245,7 @@ func (ct *Cointop) ConfigToToml() ([]byte, error) {
|
|||||||
|
|
||||||
var favoritesColumnsIfc interface{} = ct.State.favoritesTableColumns
|
var favoritesColumnsIfc interface{} = ct.State.favoritesTableColumns
|
||||||
favoritesMapIfc["columns"] = favoritesColumnsIfc
|
favoritesMapIfc["columns"] = favoritesColumnsIfc
|
||||||
|
favoritesMapIfc["character"] = ct.State.favoriteChar
|
||||||
|
|
||||||
portfolioIfc := map[string]interface{}{}
|
portfolioIfc := map[string]interface{}{}
|
||||||
var holdingsIfc [][]string
|
var holdingsIfc [][]string
|
||||||
@ -507,6 +509,14 @@ func (ct *Cointop) loadAPIChoiceFromConfig() error {
|
|||||||
func (ct *Cointop) loadFavoritesFromConfig() error {
|
func (ct *Cointop) loadFavoritesFromConfig() error {
|
||||||
log.Debug("loadFavoritesFromConfig()")
|
log.Debug("loadFavoritesFromConfig()")
|
||||||
for k, valueIfc := range ct.config.Favorites {
|
for k, valueIfc := range ct.config.Favorites {
|
||||||
|
if k == "character" {
|
||||||
|
if favoriteChar, ok := valueIfc.(string); ok {
|
||||||
|
if utf8.RuneCountInString(favoriteChar) != 1 {
|
||||||
|
return fmt.Errorf("invalid favorite-character. Must be one-character")
|
||||||
|
}
|
||||||
|
ct.State.favoriteChar = favoriteChar
|
||||||
|
}
|
||||||
|
}
|
||||||
ifcs, ok := valueIfc.([]interface{})
|
ifcs, ok := valueIfc.([]interface{})
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
|
@ -89,7 +89,7 @@ func (ct *Cointop) GetPortfolioTable() *table.Table {
|
|||||||
case "rank":
|
case "rank":
|
||||||
star := ct.colorscheme.TableRow(" ")
|
star := ct.colorscheme.TableRow(" ")
|
||||||
if coin.Favorite {
|
if coin.Favorite {
|
||||||
star = ct.colorscheme.TableRowFavorite("*")
|
star = ct.colorscheme.TableRowFavorite(ct.State.favoriteChar)
|
||||||
}
|
}
|
||||||
rank := fmt.Sprintf("%s%v", star, ct.colorscheme.TableRow(fmt.Sprintf("%6v ", coin.Rank)))
|
rank := fmt.Sprintf("%s%v", star, ct.colorscheme.TableRow(fmt.Sprintf("%6v ", coin.Rank)))
|
||||||
ct.SetTableColumnWidth(header, 8)
|
ct.SetTableColumnWidth(header, 8)
|
||||||
|
Loading…
Reference in New Issue
Block a user