Repository navigation
refactor: replace uniseg with uax29 and displaywidth - #237
Open
badger3478 wants to merge 1 commit into
Open
badger3478 wants to merge 1 commit into
badger3478 wants to merge 1 commit into
Conversation
Finish the move off github.com/rivo/uniseg that charmbracelet/x#606 began: the decoder takes a key's first grapheme cluster from uax29/graphemes, and the terminal reader iterates a release grapheme with it; the buffer test and the layout example measure with displaywidth. uax29 was already a direct dependency, and uniseg is no longer one.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Replaces ultraviolet's remaining
github.com/rivo/uniseguses with packages it already depends on:decoder.go:uniseg.FirstGraphemeCluster(b, -1)becomesgraphemes.FromBytes(b).First().terminal_reader.go: the release grapheme is iterated withgraphemes.FromStringandValue(), in place ofuniseg.NewGraphemesandStr().buffer_test.goandexamples/advanced/layoutmeasure withdisplaywidth.github.com/rivo/unisegis no longer a requirement ingo.mod.Why
charmbracelet/x#606 moved
ansifrom uniseg todisplaywidth, and charmbracelet/lipgloss#592 followed formaxRuneWidth. This finishes the move in ultraviolet, so it segments and measures text the same wayansiand lipgloss do.Behaviour
uniseg v0.4.7 (February 2024) implements Unicode 15.0.0;
clipperhouse/uax29/v2andclipperhouse/displaywidthimplement Unicode 17. They give the same answers for ASCII, Latin with combining marks, CJK, Hangul, box drawing, braille, arrows and most emoji. Where they differ, the difference follows the newer rules:क्षwas two clusters.1️⃣measures 2 cells, as terminals draw it, where uniseg measured 1.Over 200,000 random strings mixing those scripts, emoji and zero-width joiners, about 5% segment differently and about 2.5% measure differently, all from the newer Unicode data.
Testing
go test ./...andgo vet ./...give the same results as onmain, andgo mod tidy -diffis clean.go.workover the three), a downstream Bubble Tea app no longer linksgithub.com/rivo/uniseg, and its TUI tests pass.This PR stands on its own. I'll follow with the same change in lipgloss and bubbles; uniseg leaves a Bubble Tea app's module graph once all three are released.
CONTRIBUTING.md.