From 8ceece82af888ad86b8ccccf4d7705ebe3f2803f Mon Sep 17 00:00:00 2001 From: Miguel Mota Date: Fri, 8 Oct 2021 17:32:01 -0700 Subject: [PATCH] Set currency symbol width to rune string width --- cointop/conversion.go | 10 +++++++++- 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