diff --git a/src/color/text.go b/src/color/text.go index 44c809e0..dacc8f0d 100644 --- a/src/color/text.go +++ b/src/color/text.go @@ -3,14 +3,19 @@ package color import ( "oh-my-posh/regex" "strings" - "unicode/utf8" + + "github.com/mattn/go-runewidth" ) +func init() { // nolint:gochecknoinits + runewidth.DefaultCondition.EastAsianWidth = false +} + func (ansi *Ansi) MeasureText(text string) int { // skip strings with ANSI if !strings.Contains(text, "\x1b") { text = ansi.TrimEscapeSequences(text) - length := utf8.RuneCountInString(text) + length := runewidth.StringWidth(text) return length } if strings.Contains(text, "\x1b]8;;") { @@ -21,7 +26,7 @@ func (ansi *Ansi) MeasureText(text string) int { } text = ansi.TrimAnsi(text) text = ansi.TrimEscapeSequences(text) - length := utf8.RuneCountInString(text) + length := runewidth.StringWidth(text) return length } diff --git a/src/go.mod b/src/go.mod index 525d65dd..d2dfc6e6 100644 --- a/src/go.mod +++ b/src/go.mod @@ -38,6 +38,7 @@ require ( github.com/charmbracelet/bubbletea v0.22.0 github.com/charmbracelet/lipgloss v0.5.0 github.com/hashicorp/hcl/v2 v2.13.0 + github.com/mattn/go-runewidth v0.0.13 github.com/spf13/cobra v1.5.0 golang.org/x/mod v0.5.1 gopkg.in/yaml.v3 v3.0.1 @@ -74,7 +75,6 @@ require ( github.com/google/go-cmp v0.5.8 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect - github.com/mattn/go-runewidth v0.0.13 // indirect github.com/mitchellh/go-wordwrap v1.0.1 // indirect github.com/muesli/ansi v0.0.0-20211031195517-c9f0611b6c70 // indirect github.com/muesli/cancelreader v0.2.2 // indirect