diff options
author | Miguel Mota <hello@miguelmota.com> | 2021-10-08 17:40:25 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-08 17:40:25 -0700 |
commit | b22c040ffbc05673ea7a529ee03bdf267f10488d (patch) | |
tree | 858e810d6acba05012fb752a2d9873dcca1039f0 | |
parent | 4ba9f52a87275d2754faed69a6352ce5f3391f98 (diff) | |
parent | 8ceece82af888ad86b8ccccf4d7705ebe3f2803f (diff) |
Merge pull request #211 from cointop-sh/fix/rune-width
Set currency symbol width to rune string width
-rw-r--r-- | cointop/conversion.go | 10 | ||||
-rw-r--r-- | cointop/table_header.go | 7 |
2 files changed, 10 insertions, 7 deletions
diff --git a/cointop/conversion.go b/cointop/conversion.go index 0cf146b..7094ad7 100644 --- a/cointop/conversion.go +++ b/cointop/conversion.go @@ -8,6 +8,7 @@ import ( "github.com/cointop-sh/cointop/pkg/color" "github.com/cointop-sh/cointop/pkg/pad" + "github.com/mattn/go-runewidth" log "github.com/sirupsen/logrus" ) @@ -249,7 +250,14 @@ func (ct *Cointop) SetCurrencyConverstionFn(convert string) func() error { // CurrencySymbol returns the symbol for the currency conversion func (ct *Cointop) CurrencySymbol() string { log.Debug("CurrencySymbol()") - return CurrencySymbol(ct.State.currencyConversion) + symbol := CurrencySymbol(ct.State.currencyConversion) + + width := runewidth.StringWidth(symbol) + if width > 1 { + symbol = pad.Right(symbol, width, " ") + } + + return symbol } // ShowConvertMenu shows the convert menu view diff --git a/cointop/table_header.go b/cointop/table_header.go index ffd222f..7c9df10 100644 --- a/cointop/table_header.go +++ b/cointop/table_header.go @@ -212,12 +212,7 @@ func (ct *Cointop) UpdateTableHeader() error { leftAlign := ct.GetTableColumnAlignLeft(col) switch col { case "price", "balance": - spacing := "" - // Add an extra space because "satoshi" UTF-8 chracter overlaps text on right - if ct.State.currencyConversion == "SATS" { - spacing = " " - } - label = fmt.Sprintf("%s%s%s", ct.CurrencySymbol(), spacing, label) + label = fmt.Sprintf("%s%s", ct.CurrencySymbol(), label) } if leftAlign { label = label + arrow |