Skip to content

Commit

Permalink
Merge pull request #47 from junegunn/eastasian-ambiguous
Browse files Browse the repository at this point in the history
Allow configuring the width of East Asian ambiguous width characters
  • Loading branch information
rivo committed Jan 27, 2024
2 parents 3628fa1 + 1f39ebc commit 97691fc
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions width.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package uniseg

// EastAsianAmbiguousWidth specifies the monospace width for East Asian
// characters classified as Ambiguous. The default is 1 but some rare fonts
// render them with a width of 2.
var EastAsianAmbiguousWidth = 1

// runeWidth returns the monospace width for the given rune. The provided
// grapheme property is a value mapped by the [graphemeCodePoints] table.
//
Expand Down Expand Up @@ -36,6 +41,8 @@ func runeWidth(r rune, graphemeProperty int) int {
switch property(eastAsianWidth, r) {
case prW, prF:
return 2
case prA:
return EastAsianAmbiguousWidth
}

return 1
Expand Down

0 comments on commit 97691fc

Please sign in to comment.