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 := " "
|
||||
rankcolor := ct.colorscheme.TableRow
|
||||
if coin.Favorite {
|
||||
star = "*"
|
||||
star = ct.State.favoriteChar
|
||||
rankcolor = ct.colorscheme.TableRowFavorite
|
||||
}
|
||||
rank := fmt.Sprintf("%s%6v ", star, coin.Rank)
|
||||
|
@ -53,6 +53,7 @@ type State struct {
|
||||
|
||||
favorites map[string]bool
|
||||
favoritesTableColumns []string
|
||||
favoriteChar string
|
||||
helpVisible bool
|
||||
hideMarketbar bool
|
||||
hideChart bool
|
||||
@ -207,6 +208,9 @@ var DefaultCacheDir = filecache.DefaultCacheDir
|
||||
// DefaultColorsDir ...
|
||||
var DefaultColorsDir = fmt.Sprintf("%s/colors", DefaultConfigFilepath)
|
||||
|
||||
// DefaultFavoriteChar ...
|
||||
var DefaultFavoriteChar = "*"
|
||||
|
||||
// NewCointop initializes cointop
|
||||
func NewCointop(config *Config) (*Cointop, error) {
|
||||
if os.Getenv("DEBUG") != "" {
|
||||
@ -257,6 +261,7 @@ func NewCointop(config *Config) (*Cointop, error) {
|
||||
favoritesBySymbol: make(map[string]bool),
|
||||
favorites: make(map[string]bool),
|
||||
favoritesTableColumns: DefaultCoinTableHeaders,
|
||||
favoriteChar: DefaultFavoriteChar,
|
||||
hideMarketbar: config.HideMarketbar,
|
||||
hideChart: config.HideChart,
|
||||
hideTable: config.HideTable,
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/miguelmota/cointop/pkg/pathutil"
|
||||
"github.com/miguelmota/cointop/pkg/toml"
|
||||
@ -244,6 +245,7 @@ func (ct *Cointop) ConfigToToml() ([]byte, error) {
|
||||
|
||||
var favoritesColumnsIfc interface{} = ct.State.favoritesTableColumns
|
||||
favoritesMapIfc["columns"] = favoritesColumnsIfc
|
||||
favoritesMapIfc["character"] = ct.State.favoriteChar
|
||||
|
||||
portfolioIfc := map[string]interface{}{}
|
||||
var holdingsIfc [][]string
|
||||
@ -507,6 +509,14 @@ func (ct *Cointop) loadAPIChoiceFromConfig() error {
|
||||
func (ct *Cointop) loadFavoritesFromConfig() error {
|
||||
log.Debug("loadFavoritesFromConfig()")
|
||||
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{})
|
||||
if !ok {
|
||||
continue
|
||||
|
@ -89,7 +89,7 @@ func (ct *Cointop) GetPortfolioTable() *table.Table {
|
||||
case "rank":
|
||||
star := ct.colorscheme.TableRow(" ")
|
||||
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)))
|
||||
ct.SetTableColumnWidth(header, 8)
|
||||
|
Loading…
Reference in New Issue
Block a user