-
-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgraded rivo/uniseg to latest version, switched StringWidth/Truncate to speedier version #63
base: master
Are you sure you want to change the base?
Changes from 4 commits
835809f
a8413cf
2e820a2
0a21090
f052c83
01f382a
8f4e6bc
669734a
b18c354
6dff02e
10a3ce9
2c6a438
73a4cd2
5f0dad1
bb452ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module github.com/mattn/go-runewidth | ||
|
||
go 1.9 | ||
go 1.18 | ||
|
||
require github.com/rivo/uniseg v0.2.0 | ||
require github.com/rivo/uniseg v0.4.2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= | ||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= | ||
github.com/rivo/uniseg v0.3.1 h1:SDPP7SHNl1L7KrEFCSJslJ/DM9DT02Nq2C61XrfHMmk= | ||
github.com/rivo/uniseg v0.3.1/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= | ||
github.com/rivo/uniseg v0.4.2 h1:YwD0ulJSJytLpiaWua0sBDusfsCZohxjxzVTYjwxfV8= | ||
github.com/rivo/uniseg v0.4.2/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
//go:build ignore | ||
// +build ignore | ||
|
||
// Generate runewidth_table.go from data at https://unicode.org/ | ||
|
@@ -166,6 +167,16 @@ func emoji(out io.Writer, in io.Reader) error { | |
}) | ||
} | ||
|
||
// We also want regional indicator symbols (flags) to be part of the Emoji | ||
// table. They are U+1F1E6..U+1F1FF. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add link to documentation of the specification? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. http://www.unicode.org/reports/tr51/#def_emoji_flag_sequence documents how flags are constructed using Regional Indicator code points. Regional Indicator code points are not classified as Extended_Pictographic so they don't show up in your emoji table. But for the sake of calculating the width, they behave the same as other emojis. So the simplest solution is to add them to your emoji table. Alternatively, you could add the detection of Regional Indicators to all other parts of your code. That would be overkill, in my opinion, but it's up to you. In any case, you'll want You'll find them in the same file (look for "Regional Indicator"): |
||
for index, r := range arr { | ||
if r.lo >= 0x1f1ff { | ||
arr = append(arr[:index+1], arr[index:]...) | ||
arr[index] = rrange{lo: 0x1f1e6, hi: 0x1f1ff} | ||
break | ||
} | ||
} | ||
|
||
shapeup(&arr) | ||
generate(out, "emoji", arr) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope to keep go1.16 but do you have something problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately,
rivo/uniseg
uses generics and the new build tag syntax, both of which were introduced with Go 1.18.I could probably downgrade it in
go-runewidth
to a previous version but that old version was much slower than the new version. If I do, Go 1.16 will work.Let me know how you'd like to proceed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What version of uniseg is it possible to build with go-runewidth with 1.16?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v0.3.4
But if you use v0.3.4, you also need to make adjustments to your code.
Here's my suggestion: I prepare a second PR with the same output as this one, but based on
uniseg
v.0.3.4 and the older Go version. We can leave this PR (#63) open and you can merge it once you're ready to switch to Go 1.18.What do you think of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about to separate files for runewidth_go118.go and runewidth_go117.go ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just submitted a commit that does this but it gives me merge conflicts. It looks like you made/accepted other changes in the meantime. I'm not able to resolve these conflicts, only you can.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I was able to resolve the merge conflict. Please have a look.