From 6ef43d5ba05d4aa09c0ee1abf248e47cee1275fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D1=B5=C2=B5=CF=83=C9=B3=C9=A0?= <3168632+vuon9@users.noreply.github.com> Date: Mon, 25 Oct 2021 22:58:56 +0700 Subject: [PATCH 1/6] Support search by /s:keyword - symbol, /n:keyword - name --- cointop/search.go | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/cointop/search.go b/cointop/search.go index dd06844..94dbd99 100644 --- a/cointop/search.go +++ b/cointop/search.go @@ -93,6 +93,28 @@ func (ct *Cointop) Search(q string) error { ct.State.lastSearchQuery = q } + hasPrefix := false + canSearchSymbol := true + canSearchName := true + if strings.HasPrefix(q, "s:") { + canSearchSymbol = true + canSearchName = false + hasPrefix = true + log.Debug("Search, by keyword") + } + + if strings.HasPrefix(q, "n:") { + canSearchSymbol = false + canSearchName = true + hasPrefix = true + log.Debug("Search, by name") + } + + if hasPrefix { + q = q[2:] + log.Debugf("Search, truncated query '%s'", q) + } + idx := -1 min := -1 var hasprefixidx []int @@ -107,16 +129,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 +160,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 } From f26006823baddca387a25b38bffe0d8a9725f8e9 Mon Sep 17 00:00:00 2001 From: Vuong <3168632+vuon9@users.noreply.github.com> Date: Tue, 26 Oct 2021 08:23:32 +0000 Subject: [PATCH 2/6] Remove hasPrefix --- cointop/search.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/cointop/search.go b/cointop/search.go index 94dbd99..cc3f7c4 100644 --- a/cointop/search.go +++ b/cointop/search.go @@ -93,26 +93,20 @@ func (ct *Cointop) Search(q string) error { ct.State.lastSearchQuery = q } - hasPrefix := false canSearchSymbol := true canSearchName := true if strings.HasPrefix(q, "s:") { canSearchSymbol = true canSearchName = false - hasPrefix = true + q = q[2:] log.Debug("Search, by keyword") } if strings.HasPrefix(q, "n:") { canSearchSymbol = false canSearchName = true - hasPrefix = true - log.Debug("Search, by name") - } - - if hasPrefix { q = q[2:] - log.Debugf("Search, truncated query '%s'", q) + log.Debug("Search, by name") } idx := -1 From dd1c83ee67397201e312224023dc7aa1dac26bb7 Mon Sep 17 00:00:00 2001 From: Vuong <3168632+vuon9@users.noreply.github.com> Date: Tue, 26 Oct 2021 08:52:44 +0000 Subject: [PATCH 3/6] Update FAQ for search guide --- docs/content/faq.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/content/faq.md b/docs/content/faq.md index 1ee7e20..df6848b 100644 --- a/docs/content/faq.md +++ b/docs/content/faq.md @@ -134,6 +134,8 @@ draft: false The default key to open search is /. Type the search query after the `/` in the field and hit Enter. Each search starts from the current cursor position. To search for the same term again, hit / then Enter. + 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 Esc to exit search. From ac946a7d737c9ca5e7513958b6e452dd3fc9846c Mon Sep 17 00:00:00 2001 From: Simon Roberts Date: Fri, 29 Oct 2021 10:32:26 +1100 Subject: [PATCH 4/6] Reduce the number of pages to 10 (1000 coins) to reduce the load on backend... (#255) * Reduce the number of pages to 10 (1000 coins) to reduce the load on backend, and increase refresh time. See #104 #228 * Add note about --max-pages and --per-page --- cointop/cointop.go | 2 +- docs/content/faq.md | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cointop/cointop.go b/cointop/cointop.go index 4050175..d4579ed 100644 --- a/cointop/cointop.go +++ b/cointop/cointop.go @@ -206,7 +206,7 @@ var DefaultSortBy = "rank" var DefaultPerPage = uint(100) // DefaultMaxPages ... -var DefaultMaxPages = uint(35) +var DefaultMaxPages = uint(10) // DefaultColorscheme ... var DefaultColorscheme = "cointop" diff --git a/docs/content/faq.md b/docs/content/faq.md index cbe8547..70055f1 100644 --- a/docs/content/faq.md +++ b/docs/content/faq.md @@ -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? From 19561ce3000eeeab40681732674c6a4635044f94 Mon Sep 17 00:00:00 2001 From: Simon Roberts Date: Fri, 29 Oct 2021 13:50:32 +1100 Subject: [PATCH 5/6] Immediately after changing currency refresh the current coins #178 (#256) --- cointop/conversion.go | 2 +- cointop/list.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/cointop/conversion.go b/cointop/conversion.go index 51756c7..bbe2a2e 100644 --- a/cointop/conversion.go +++ b/cointop/conversion.go @@ -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 } diff --git a/cointop/list.go b/cointop/list.go index 94d28cd..ff66e6a 100644 --- a/cointop/list.go +++ b/cointop/list.go @@ -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()") From e26816b26cb10544696adbe75e10f584ccd93a4b Mon Sep 17 00:00:00 2001 From: Simon Roberts Date: Fri, 29 Oct 2021 13:51:19 +1100 Subject: [PATCH 6/6] Fix suffix on y-axis for Millions (#259) --- pkg/termui/linechart.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/termui/linechart.go b/pkg/termui/linechart.go index 68bcfae..b81f31c 100644 --- a/pkg/termui/linechart.go +++ b/pkg/termui/linechart.go @@ -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) }