diff --git a/buffer_test.go b/buffer_test.go index ccdb4620..d7dfdb2f 100644 --- a/buffer_test.go +++ b/buffer_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/charmbracelet/x/ansi" - "github.com/rivo/uniseg" + "github.com/clipperhouse/displaywidth" ) func TestBufferUniseg(t *testing.T) { @@ -36,10 +36,10 @@ func TestBufferUniseg(t *testing.T) { buf := NewBuffer(width(c.input), height(c.input)) for y, line := range strings.Split(c.input, "\n") { var x int - seg := uniseg.NewGraphemes(line) + seg := displaywidth.StringGraphemes(line) for seg.Next() { cell := &Cell{ - Content: seg.Str(), + Content: seg.Value(), Width: seg.Width(), } buf.SetCell(x, y, cell) @@ -720,7 +720,7 @@ func TestRenderLineWideCellTail(t *testing.T) { if want := "A 你"; visible != want { t.Errorf("Render() = %q, want %q; output=%q", visible, want, output) } - if w := uniseg.StringWidth(visible); w != 6 { + if w := displaywidth.String(visible); w != 6 { t.Errorf("Render() visible width = %d, want 6; output=%q", w, output) } } diff --git a/decoder.go b/decoder.go index 65d3f0bd..9e37b15a 100644 --- a/decoder.go +++ b/decoder.go @@ -15,7 +15,7 @@ import ( "github.com/charmbracelet/x/ansi" "github.com/charmbracelet/x/ansi/parser" xwindows "github.com/charmbracelet/x/windows" - "github.com/rivo/uniseg" + "github.com/clipperhouse/uax29/v2/graphemes" ) // Flags to control the behavior of the parser. @@ -1114,7 +1114,7 @@ func (p *EventDecoder) parseUtf8(b []byte) (int, Event) { return 1, UnknownEvent(b[0]) } - cluster, _, _, _ := uniseg.FirstGraphemeCluster(b, -1) + cluster := graphemes.FromBytes(b).First() text := string(cluster) for i := range text { if i > 0 { diff --git a/examples/advanced/layout/main.go b/examples/advanced/layout/main.go index aa8e8f49..3d3349af 100644 --- a/examples/advanced/layout/main.go +++ b/examples/advanced/layout/main.go @@ -11,8 +11,8 @@ import ( uv "github.com/charmbracelet/ultraviolet" "github.com/charmbracelet/ultraviolet/screen" "github.com/charmbracelet/x/ansi" + "github.com/clipperhouse/displaywidth" "github.com/lucasb-eyer/go-colorful" - "github.com/rivo/uniseg" ) const ( @@ -437,10 +437,10 @@ func max(a, b int) int { } func applyGradient(base lipgloss.Style, input string, from, to color.Color) string { - g := uniseg.NewGraphemes(input) + g := displaywidth.StringGraphemes(input) var chars []string for g.Next() { - chars = append(chars, g.Str()) + chars = append(chars, g.Value()) } a, _ := colorful.MakeColor(to) diff --git a/examples/go.mod b/examples/go.mod index 36d89523..ebd384fb 100644 --- a/examples/go.mod +++ b/examples/go.mod @@ -10,9 +10,9 @@ require ( github.com/charmbracelet/x/ansi v0.11.9 github.com/charmbracelet/x/mosaic v0.0.0-20260906004030-3986e9119cf9 github.com/charmbracelet/x/term v0.2.2 + github.com/clipperhouse/displaywidth v0.11.0 github.com/lucasb-eyer/go-colorful v1.4.1 github.com/mattn/go-runewidth v0.0.30 - github.com/rivo/uniseg v0.4.7 ) require ( @@ -20,9 +20,9 @@ require ( github.com/charmbracelet/colorprofile v0.4.3 // indirect github.com/charmbracelet/x/termios v0.1.1 // indirect github.com/charmbracelet/x/windows v0.2.2 // indirect - github.com/clipperhouse/displaywidth v0.11.0 // indirect github.com/clipperhouse/uax29/v2 v2.7.0 // indirect github.com/muesli/cancelreader v0.2.2 // indirect + github.com/rivo/uniseg v0.4.7 // indirect github.com/xo/terminfo v1.0.0 // indirect golang.org/x/image v0.45.0 // indirect golang.org/x/sync v0.22.0 // indirect diff --git a/go.mod b/go.mod index c1da1ee9..4baf4242 100644 --- a/go.mod +++ b/go.mod @@ -10,15 +10,14 @@ require ( github.com/charmbracelet/x/windows v0.2.2 github.com/clipperhouse/uax29/v2 v2.7.0 github.com/muesli/cancelreader v0.2.2 - github.com/rivo/uniseg v0.4.7 github.com/xo/terminfo v1.0.0 golang.org/x/sync v0.22.0 golang.org/x/sys v0.47.0 ) +require github.com/mattn/go-runewidth v0.0.30 // indirect + require ( - github.com/clipperhouse/displaywidth v0.11.0 // indirect - github.com/mattn/go-runewidth v0.0.30 // indirect + github.com/clipperhouse/displaywidth v0.11.0 + github.com/lucasb-eyer/go-colorful v1.4.1 ) - -require github.com/lucasb-eyer/go-colorful v1.4.1 diff --git a/go.sum b/go.sum index db966fe1..a1fb2941 100644 --- a/go.sum +++ b/go.sum @@ -18,8 +18,6 @@ github.com/mattn/go-runewidth v0.0.30 h1:+KUuiDA4fF0R1p5FeueHefjDm+GIM+kWfFnDjyb github.com/mattn/go-runewidth v0.0.30/go.mod h1:3qAiGCV4Koz/yuveO58qUefmUTRm8r0IGEXZ9jeHp/8= github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA= github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo= -github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= -github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/xo/terminfo v1.0.0 h1:2ZpYzqWzyyytjk3TP6aJVDhkMAkc99/1xKQdA3TDTBY= github.com/xo/terminfo v1.0.0/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM= golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E= diff --git a/terminal_reader.go b/terminal_reader.go index b3b79cd0..8b082358 100644 --- a/terminal_reader.go +++ b/terminal_reader.go @@ -15,8 +15,8 @@ import ( "unicode/utf8" "github.com/charmbracelet/x/ansi" + "github.com/clipperhouse/uax29/v2/graphemes" "github.com/muesli/cancelreader" - "github.com/rivo/uniseg" ) // ErrReaderNotStarted is returned when the reader has not been started yet. @@ -396,10 +396,10 @@ func (d *eventScanner) encodeGraphemeBufs() []byte { b = append(b, string(d.graphemeBuf[kd])...) case 0: // Encode the release grapheme as Kitty Keyboard to get the release event. - grs := uniseg.NewGraphemes(string(d.graphemeBuf[kd])) + grs := graphemes.FromString(string(d.graphemeBuf[kd])) for grs.Next() { var codepoints string - gr := grs.Str() + gr := grs.Value() for i, r := range gr { if r == 0 { continue