Something went wrong. Try again.
Measure the width of text in the terminal and build simple layouts!
Something went wrong. Try again.
2.3 kB · 84 lines
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485import gleeunit/shouldimport string_width
fn sw(str: String) { let options = string_width.new() |> string_width.mode_2027_ext
string_width.line_with(str, options)}
@target(erlang)pub fn despair1_test() { // 2 grapheme clusters in Unicode 15 sw("র্য") |> should.equal(2)}
@target(javascript)pub fn despair1_test() { // 1 grapheme cluster in unicode 15.1 // We return 2 because of our custom extension. sw("র্য") |> should.equal(2)}
@target(erlang)pub fn despair2_test() { // 2 grapheme clusters in Unicde 15. // NOTE: this string is different from the one above in that it includes // an additional ZWJ between the letters! sw("র্য") |> should.equal(2)}
@target(javascript)pub fn despair2_test() { // 1 grapheme cluster in Unicde 15.1 // NOTE: this string is different from the one above in that it includes // an additional ZWJ between the letters! // // VSCode treats it as 2 separate characters though, and everyone renders it wide. // // We return 2 because of our custom extension. sw("র্য") |> should.equal(2)}
@target(erlang)pub fn despair3_test() { // 5 grapheme clusters un Unicode 15 // in particular, "च्छे" is split into 2 clusters sw("अनुच्छेद") |> should.equal(5)}
@target(javascript)pub fn despair3_test() { // 4 grapheme clusters un Unicode 15.1 // in particular, "च्छे" is a single grapheme cluster, but every terminal and editor // I ever tried renders it as a wide character, even though there is nothing // in the database that I know of that would tell it to. // // We return 5 instead of 4 because of our custom extension. sw("अनुच्छेद") |> should.equal(5)}
@target(erlang)pub fn despair4_test() { // 2 grapheme clusters in Unicode 15 sw("क्षि") |> should.equal(2)}
@target(javascript)pub fn despair4_test() { // 1 grapheme cluster in Unicode 15.1 // We return 2 because of our custom extension. sw("क्षि") |> should.equal(2)}
pub fn despair5_test() { // this is always segmented into a single grapheme cluster, but most apps // still render it wide. // Our "2 codepoints with width force it wide rule" makes it wide, but other // implementations disagree. sw("バ") |> should.equal(2)}