mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-28 12:29:40 -08:00
fix(writer): correct width calculation for emoji's
This commit is contained in:
parent
9e238adbb9
commit
0f66661f6e
|
@ -35,6 +35,7 @@ require (
|
||||||
github.com/goccy/go-yaml v1.11.3
|
github.com/goccy/go-yaml v1.11.3
|
||||||
github.com/gookit/goutil v0.6.16
|
github.com/gookit/goutil v0.6.16
|
||||||
github.com/hashicorp/hcl/v2 v2.21.0
|
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/pelletier/go-toml/v2 v2.2.2
|
||||||
github.com/spf13/cobra v1.8.1
|
github.com/spf13/cobra v1.8.1
|
||||||
github.com/spf13/pflag v1.0.5
|
github.com/spf13/pflag v1.0.5
|
||||||
|
@ -78,7 +79,6 @@ require (
|
||||||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
||||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||||
github.com/mattn/go-localereader v0.0.1 // 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/mitchellh/go-wordwrap v1.0.1 // indirect
|
||||||
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
|
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
|
||||||
github.com/muesli/cancelreader v0.2.2 // indirect
|
github.com/muesli/cancelreader v0.2.2 // indirect
|
||||||
|
|
|
@ -4,14 +4,18 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode/utf8"
|
|
||||||
|
|
||||||
"github.com/jandedobbeleer/oh-my-posh/src/color"
|
"github.com/jandedobbeleer/oh-my-posh/src/color"
|
||||||
"github.com/jandedobbeleer/oh-my-posh/src/log"
|
"github.com/jandedobbeleer/oh-my-posh/src/log"
|
||||||
"github.com/jandedobbeleer/oh-my-posh/src/regex"
|
"github.com/jandedobbeleer/oh-my-posh/src/regex"
|
||||||
"github.com/jandedobbeleer/oh-my-posh/src/shell"
|
"github.com/jandedobbeleer/oh-my-posh/src/shell"
|
||||||
|
"github.com/mattn/go-runewidth"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
runewidth.DefaultCondition.EastAsianWidth = false
|
||||||
|
}
|
||||||
|
|
||||||
type style struct {
|
type style struct {
|
||||||
AnchorStart string
|
AnchorStart string
|
||||||
AnchorEnd 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
|
lastRune = s
|
||||||
builder.WriteRune(s)
|
builder.WriteRune(s)
|
||||||
}
|
}
|
||||||
|
|
|
@ -246,7 +246,7 @@ func TestWriteLength(t *testing.T) {
|
||||||
{
|
{
|
||||||
Case: "Emoji",
|
Case: "Emoji",
|
||||||
Input: " ⏰ ",
|
Input: " ⏰ ",
|
||||||
Expected: 4,
|
Expected: 5,
|
||||||
Colors: &color.Set{Foreground: "black", Background: color.ParentBackground},
|
Colors: &color.Set{Foreground: "black", Background: color.ParentBackground},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue