Use Condition for custom width configurations
masterIf the default behavior (based on the RUNEWIDTH_EASTASIAN environment variable) does not suit your needs, use the Condition struct to define custom width rules.
Configuration Options
EastAsianWidth: Set totrueto treat CJK characters as double-width.StrictEmojiNeutral: Iftrue, emoji handling follows strict rules. Iffalse, it may help with broken font rendering by treating some emojis as double-width.ZeroWidthJoiner: (Deprecated) No longer has an effect as ZWJ sequences are handled via grapheme segmentation.
Performance Optimization
If you are performing many width calculations with a custom Condition, call CreateLUT() to generate an in-memory lookup table. This significantly speeds up RuneWidth and StringWidth calls. Note: CreateLUT should not be called concurrently with other operations on the same Condition instance, and must be re-called if you change the condition's settings.
import "github.com/mattn/go-runewidth"
cond := runewidth.NewCondition()
cond.EastAsianWidth = true
cond.StrictEmojiNeutral = false
// Optimize for high-frequency calls
cond.CreateLUT()
width := cond.StringWidth("some string")