Skip to content

Instantly share code, notes, and snippets.

@hymkor
Created November 5, 2025 10:13
Show Gist options
  • Select an option

  • Save hymkor/b3e1e19139f5fcc227b7d89a394466a6 to your computer and use it in GitHub Desktop.

Select an option

Save hymkor/b3e1e19139f5fcc227b7d89a394466a6 to your computer and use it in GitHub Desktop.
//go:build orgxwidth
package moji
import (
"unicode"
"golang.org/x/text/width"
)
func newRuneWidth(ambiguousIsWide bool) func(rune) int {
var aw int
if ambiguousIsWide {
aw = 2
} else {
aw = 1
}
return func(r rune) int {
if !unicode.IsPrint(r) {
return 0
}
switch width.LookupRune(r).Kind() {
case width.Neutral, width.EastAsianNarrow, width.EastAsianHalfwidth:
return 1
case width.EastAsianWide, width.EastAsianFullwidth:
return 2
case width.EastAsianAmbiguous:
return aw
default:
return 0
}
}
}
var runeWidth = newRuneWidth(AmbiguousIsWide)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment