Merge branch 'cointop-sh:master' into feature/tcell

pull/232/head
Simon Roberts 3 years ago committed by GitHub
commit 18eb944c28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -57,6 +57,18 @@ func ActionsMap() map[string]bool {
"toggle_show_portfolio": true,
"enlarge_chart": true,
"shorten_chart": true,
"toggle_chart_fullscreen": true,
"scroll_right": true,
"show_portfolio_edit_menu": true,
"sort_column_percent_holdings": true,
"toggle_portfolio_balances": true,
"scroll_left": true,
"save": true,
"toggle_table_fullscreen": true,
"toggle_price_alerts": true,
"move_down_or_next_page": true,
"show_price_alert_add_menu": true,
"sort_column_balance": true,
}
}

@ -366,14 +366,44 @@ func (ct *Cointop) loadTableColumnsFromConfig() error {
// LoadShortcutsFromConfig loads keyboard shortcuts from config file to struct
func (ct *Cointop) loadShortcutsFromConfig() error {
log.Debug("loadShortcutsFromConfig()")
// Load the shortcut config into a key:action map (filtering to actions that exist). Keep track of actions.
config := make(map[string]string)
actions := make(map[string]bool)
for k, ifc := range ct.config.Shortcuts {
if v, ok := ifc.(string); ok {
if !ct.ActionExists(v) {
log.Debugf("Shortcut '%s'=>%s is not a valid action", k, v)
continue
}
ct.State.shortcutKeys[k] = v
config[k] = v
actions[v] = true
}
}
// Count how many keys are configured per action.
actionCount := make(map[string]int)
for _, action := range ct.State.shortcutKeys {
actionCount[action] += 1
}
// merge defaults into the loaded config - if the key is not defined, and the action is not found, add it
for key, action := range ct.State.shortcutKeys {
if _, ok := config[key]; ok {
// k is already in the config - ignore it
} else if _, ok := actions[action]; ok {
if actionCount[action] == 1 {
// action is already in the config - ignore it
} else {
// there are multiple bindings, add them anyway
config[key] = action // add action
}
} else {
config[key] = action // add action
}
}
ct.State.shortcutKeys = config
return nil
}

@ -1,13 +1,22 @@
package cointop
import (
"fmt"
"os"
"github.com/cointop-sh/cointop/pkg/pathutil"
log "github.com/sirupsen/logrus"
)
func (ct *Cointop) initlog() {
filename := "/tmp/cointop.log"
debugFile := os.Getenv("DEBUG_FILE")
if debugFile != "" {
filename = pathutil.NormalizePath(debugFile)
if filename != debugFile && os.Getenv("DEBUG") != "" {
fmt.Printf("Writing debug log to %s\n", filename)
}
}
f, err := os.OpenFile(filename, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600)
if err != nil {
panic(err)

@ -64,7 +64,7 @@ func (ct *Cointop) GetFavoritesSlice() []*Coin {
}
}
sort.Slice(sliced, func(i, j int) bool {
sort.SliceStable(sliced, func(i, j int) bool {
return sliced[i].MarketCap > sliced[j].MarketCap
})

@ -574,7 +574,7 @@ func (ct *Cointop) GetPortfolioSlice() []*Coin {
sliced = append(sliced, coin)
}
sort.Slice(sliced, func(i, j int) bool {
sort.SliceStable(sliced, func(i, j int) bool {
return sliced[i].Balance > sliced[j].Balance
})

@ -23,7 +23,7 @@ func (ct *Cointop) Sort(sortBy string, desc bool, list []*Coin, renderHeaders bo
if len(list) < 2 {
return
}
sort.Slice(list[:], func(i, j int) bool {
sort.SliceStable(list[:], func(i, j int) bool {
if ct.State.sortDesc {
i, j = j, i
}

@ -504,3 +504,5 @@ draft: false
```bash
DEBUG=1 DEBUG_HTTP=1 cointop
```
If you set environment variable `DEBUG_FILE` you can explicitly provide a logfile location, rather than `/tmp/cointop.log`

@ -53,6 +53,7 @@ func NormalizePath(path string) string {
userHome := UserPreferredHomeDir()
userConfigHome := UserPreferredConfigDir()
userCacheHome := UserPreferredCacheDir()
userTempDir := os.TempDir()
// expand tilde
if strings.HasPrefix(path, "~/") {
@ -62,6 +63,7 @@ func NormalizePath(path string) string {
path = strings.Replace(path, ":HOME:", userHome, -1)
path = strings.Replace(path, ":PREFERRED_CONFIG_HOME:", userConfigHome, -1)
path = strings.Replace(path, ":PREFERRED_CACHE_HOME:", userCacheHome, -1)
path = strings.Replace(path, ":PREFERRED_TEMP_DIR:", userTempDir, -1)
path = strings.Replace(path, "/", string(filepath.Separator), -1)
return filepath.Clean(path)

Loading…
Cancel
Save