Merge branch 'master' into develop

develop
Miguel Mota 3 years ago
commit ea782f72f4
No known key found for this signature in database
GPG Key ID: 67EC1161588A00F9

@ -206,7 +206,7 @@ var DefaultSortBy = "rank"
var DefaultPerPage = uint(100)
// DefaultMaxPages ...
var DefaultMaxPages = uint(35)
var DefaultMaxPages = uint(10)
// DefaultColorscheme ...
var DefaultColorscheme = "cointop"

@ -241,7 +241,7 @@ func (ct *Cointop) SetCurrencyConverstionFn(convert string) func() error {
if err := ct.Save(); err != nil {
return err
}
go ct.UpdateCurrentPageCoins()
go ct.RefreshAll()
return nil
}

@ -46,6 +46,22 @@ func (ct *Cointop) UpdateCoins() error {
return nil
}
// UpdateCurrentPageCoins updates all the coins in the current page
func (ct *Cointop) UpdateCurrentPageCoins() error {
log.Debugf("UpdateCurrentPageCoins(%d)", len(ct.State.coins))
currentPageCoins := make([]string, len(ct.State.coins))
for i, entry := range ct.State.coins {
currentPageCoins[i] = entry.Name
}
coins, err := ct.api.GetCoinDataBatch(currentPageCoins, ct.State.currencyConversion)
if err != nil {
return err
}
go ct.processCoins(coins)
return nil
}
// ProcessCoinsMap processes coins map
func (ct *Cointop) processCoinsMap(coinsMap map[string]types.Coin) {
log.Debug("ProcessCoinsMap()")

@ -93,6 +93,22 @@ func (ct *Cointop) Search(q string) error {
ct.State.lastSearchQuery = q
}
canSearchSymbol := true
canSearchName := true
if strings.HasPrefix(q, "s:") {
canSearchSymbol = true
canSearchName = false
q = q[2:]
log.Debug("Search, by keyword")
}
if strings.HasPrefix(q, "n:") {
canSearchSymbol = false
canSearchName = true
q = q[2:]
log.Debug("Search, by name")
}
idx := -1
min := -1
var hasprefixidx []int
@ -107,16 +123,23 @@ func (ct *Cointop) Search(q string) error {
coin := ct.State.allCoins[i]
name := strings.ToLower(coin.Name)
symbol := strings.ToLower(coin.Symbol)
// if query matches symbol, return immediately
if symbol == q {
if canSearchSymbol && symbol == q {
ct.GoToGlobalIndex(i)
return nil
}
if !canSearchName {
continue
}
// if query matches name, return immediately
if name == q {
ct.GoToGlobalIndex(i)
return nil
}
// store index with the smallest levenshtein
dist := levenshtein.DamerauLevenshteinDistance(name, q)
if min == -1 || dist <= min {
@ -131,15 +154,22 @@ func (ct *Cointop) Search(q string) error {
}
}
}
if !canSearchName {
return nil
}
// go to row if prefix match
if len(hasprefixidx) > 0 && hasprefixidx[0] != -1 && min > 0 {
ct.GoToGlobalIndex(hasprefixidx[0])
return nil
}
// go to row if levenshtein distance is small enough
if idx > -1 && min <= 6 {
ct.GoToGlobalIndex(idx)
return nil
}
return nil
}

@ -15,7 +15,8 @@ draft: false
## What coins does this support?
This supports any coin supported by the API being used to fetch coin information.
This supports any coin supported by the API being used to fetch coin information. There is, however, a limit on the number of coins that
cointop fetches by default. You can increase this by passing `--max-pages` and `--per-page` arguments on the command line.
## How do I set the API to use?
@ -134,6 +135,8 @@ draft: false
The default key to open search is <kbd>/</kbd>. Type the search query after the `/` in the field and hit <kbd>Enter</kbd>.
Each search starts from the current cursor position. To search for the same term again, hit <kbd>/</kbd> then <kbd>Enter</kbd>.
The default behaviour will start to search by symbol first, then it will continues searching by name if there is no result. To search by only symbol, type the search query after `/s:`. To search by only name, type the search query after `/n:`.
## How do I exit search?
Press <kbd>Esc</kbd> to exit search.

@ -205,7 +205,7 @@ func shortenFloatVal(x float64) string {
return fmt.Sprintf("%.4fB", x/1e9)
}
if x > 1e6 {
return fmt.Sprintf("%.4fB", x/1e6)
return fmt.Sprintf("%.4fM", x/1e6)
}
return fmt.Sprintf("%.4f", x)
}

Loading…
Cancel
Save