diff --git a/src/go.mod b/src/go.mod index 06fdaf1e..58620295 100644 --- a/src/go.mod +++ b/src/go.mod @@ -35,6 +35,7 @@ require ( github.com/goccy/go-yaml v1.11.3 github.com/gookit/goutil v0.6.16 github.com/hashicorp/hcl/v2 v2.21.0 + github.com/mattn/go-runewidth v0.0.16 github.com/pelletier/go-toml/v2 v2.2.2 github.com/spf13/cobra v1.8.1 github.com/spf13/pflag v1.0.5 @@ -78,7 +79,6 @@ require ( github.com/lucasb-eyer/go-colorful v1.2.0 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-localereader v0.0.1 // indirect - github.com/mattn/go-runewidth v0.0.16 // indirect github.com/mitchellh/go-wordwrap v1.0.1 // indirect github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect github.com/muesli/cancelreader v0.2.2 // indirect diff --git a/src/terminal/writer.go b/src/terminal/writer.go index 7bafc1f6..977a34ff 100644 --- a/src/terminal/writer.go +++ b/src/terminal/writer.go @@ -4,14 +4,18 @@ import ( "fmt" "os" "strings" - "unicode/utf8" "github.com/jandedobbeleer/oh-my-posh/src/color" "github.com/jandedobbeleer/oh-my-posh/src/log" "github.com/jandedobbeleer/oh-my-posh/src/regex" "github.com/jandedobbeleer/oh-my-posh/src/shell" + "github.com/mattn/go-runewidth" ) +func init() { + runewidth.DefaultCondition.EastAsianWidth = false +} + type style struct { AnchorStart string AnchorEnd string @@ -396,7 +400,8 @@ func write(s rune) { } } - length += utf8.RuneCountInString(string(s)) + // length += utf8.RuneCountInString(string(s)) + length += runewidth.RuneWidth(s) lastRune = s builder.WriteRune(s) } diff --git a/src/terminal/writer_test.go b/src/terminal/writer_test.go index a69b8972..a50a64c1 100644 --- a/src/terminal/writer_test.go +++ b/src/terminal/writer_test.go @@ -246,7 +246,7 @@ func TestWriteLength(t *testing.T) { { Case: "Emoji", Input: " ⏰ ", - Expected: 4, + Expected: 5, Colors: &color.Set{Foreground: "black", Background: color.ParentBackground}, }, {