diff --git a/cointop/portfolio.go b/cointop/portfolio.go index aa2c015..032af4c 100644 --- a/cointop/portfolio.go +++ b/cointop/portfolio.go @@ -10,6 +10,7 @@ import ( "strconv" "strings" "time" + "unicode/utf8" "github.com/miguelmota/cointop/pkg/asciitable" "github.com/miguelmota/cointop/pkg/humanize" @@ -126,7 +127,7 @@ func (ct *Cointop) GetPortfolioTable() *table.Table { case "price": text := humanize.Commaf(coin.Price) symbolPadding := 1 - ct.SetTableColumnWidth(header, len(text)+symbolPadding) + ct.SetTableColumnWidth(header, utf8.RuneCountInString(text)+symbolPadding) ct.SetTableColumnAlignLeft(header, false) rowCells = append(rowCells, &table.RowCell{ @@ -353,7 +354,7 @@ func (ct *Cointop) UpdatePortfolioUpdateMenu() error { ct.Views.Menu.SetFrame(true) ct.Views.Menu.Update(content) ct.Views.Input.Write(value) - ct.Views.Input.SetCursor(len(value), 0) + ct.Views.Input.SetCursor(utf8.RuneCountInString(value), 0) return nil }) return nil diff --git a/cointop/sort.go b/cointop/sort.go index e0bf77f..c42b402 100644 --- a/cointop/sort.go +++ b/cointop/sort.go @@ -14,14 +14,14 @@ func (ct *Cointop) Sort(sortBy string, desc bool, list []*Coin, renderHeaders bo ct.debuglog("sort()") sortlock.Lock() defer sortlock.Unlock() + ct.State.sortBy = sortBy + ct.State.sortDesc = desc if list == nil { return } if len(list) < 2 { return } - ct.State.sortBy = sortBy - ct.State.sortDesc = desc sort.Slice(list[:], func(i, j int) bool { if ct.State.sortDesc { i, j = j, i diff --git a/cointop/statusbar.go b/cointop/statusbar.go index 38812f5..6469ee8 100644 --- a/cointop/statusbar.go +++ b/cointop/statusbar.go @@ -2,6 +2,7 @@ package cointop import ( "fmt" + "unicode/utf8" "github.com/miguelmota/cointop/pkg/open" "github.com/miguelmota/cointop/pkg/pad" @@ -53,9 +54,10 @@ func (ct *Cointop) UpdateStatusbar(s string) error { base := fmt.Sprintf("%s %sChart %sRange %sSearch %sConvert %s %s", helpStr, "[Enter]", "[[ ]]", "[/]", "[C]", favoritesText, portfolioText) str := pad.Right(fmt.Sprintf("%v %sPage %v/%v %s", base, "[← →]", currpage, totalpages, s), ct.width(), " ") v := ct.Version() - end := len(str) - len(v) + 2 - if end > len(str) { - end = len(str) + size := utf8.RuneCountInString(str) + end := size - utf8.RuneCountInString(v) + 2 + if end > size { + end = size } content = str[:end] + v