Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"

"github.com/charmbracelet/x/ansi"
"github.com/rivo/uniseg"
"github.com/clipperhouse/displaywidth"
)

func TestBufferUniseg(t *testing.T) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}
Expand Down
4 changes: 2 additions & 2 deletions decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions examples/advanced/layout/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions examples/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ 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 (
github.com/bits-and-blooms/bitset v1.25.0 // indirect
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
Expand Down
9 changes: 4 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
6 changes: 3 additions & 3 deletions terminal_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down