Skip to content

Commit

Permalink
Update statusbar spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelmota committed Feb 12, 2021
1 parent a9473e3 commit 00d654a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
5 changes: 3 additions & 2 deletions cointop/portfolio.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strconv"
"strings"
"time"
"unicode/utf8"

"github.com/miguelmota/cointop/pkg/asciitable"
"github.com/miguelmota/cointop/pkg/humanize"
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cointop/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions cointop/statusbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cointop

import (
"fmt"
"unicode/utf8"

"github.com/miguelmota/cointop/pkg/open"
"github.com/miguelmota/cointop/pkg/pad"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 00d654a

Please sign in to comment.