talira

go-runewidth

wcwidth for Go: the display width of characters and strings

open sourceMITfree

go-runewidth is a Go library, a wcwidth equivalent, that returns how many terminal cells a character or string takes, so text with East Asian wide characters and emoji lines up. It has an East Asian width mode for CJK locales, in which ambiguous Latin letters still count as one cell. It's by Yasuhiro Matsumoto (mattn).

Problems it solves

  • align CJK text in a Go terminal UI
  • measure the column width of a string in Go
  • pad table columns with emoji correctly in Go

Features

  • display width of runes and strings
  • East Asian width mode for CJK locales
  • wcwidth equivalent for Go