string_width

Package VersionHex Docs

gleam add string_width@1
import string_width
pub fn main() {
string_width.dimensions("hello,\n안녕하세요", [])
// --> #(2, 10)
string_width.line("👩‍👩‍👦‍👦", [string_width.HandleGraphemeClusters])
// --> 2
}

A small package estimates the required number of cells when printing a string on the terminal. It supports all Gleam targets.

Limitations

Sources

This library is heavily based on musl libc wcwidth implementation, the ansi-regex npm package, and uses many of the test cases of the string-width npm package.