Something went wrong. Try again.
Measure the width of text in the terminal and build simple layouts!
Something went wrong. Try again.
2.9 kB · 111 lines
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112import gleam/listimport gleam/stringimport gleeunit/should
import string_width/internal/ansi
pub fn ansi_match_test() { ansi.match("foo\u{001B}[4mcake\u{001B}[0m") |> should.not_equal([]) ansi.match("\u{001B}[4mcake\u{001B}[0m") |> should.not_equal([]) ansi.match("foo\u{001B}[4mcake\u{001B}[0m") |> should.not_equal([]) ansi.match( "\u{001B}[0m\u{001B}[4m\u{001B}[42m\u{001B}[31mfoo\u{001B}[39m\u{001B}[49m\u{001B}[24mfoo\u{001B}[0m", ) |> should.not_equal([]) ansi.match("foo\u{001B}[mfoo") |> should.not_equal([])}
pub fn match_ls_output_test() { ansi.match( "\u{001B}[00;38;5;244m\u{001B}[m\u{001B}[00;38;5;33mfoo\u{001B}[0m", ) |> should.not_equal([])}
pub fn match_common_commands_test() { ansi.match("\u{001B}[0;33;49;3;9;4mbar\u{001B}[0m") |> should.equal([#(0, 16), #(19, 4)])}
pub fn match_clear_tabs_test() { ansi.match("foo\u{001B}[0gbar") |> should.equal([#(3, 4)])}
pub fn match_clear_right_test() { ansi.match("foo\u{001B}[Kbar") |> should.equal([#(3, 3)])}
pub fn match_clear_screen_test() { ansi.match("foo\u{001B}[2Jbar") |> should.equal([#(3, 4)])}
pub fn match_link_test() { use st <- list.each(["\u{07}", "\u{1b}\u{5c}"]) let l = string.byte_size(st) ansi.match( "\u{001B}]8;k=v;https://example-a.com/?a_b=1&c=2#tit%20le" <> st <> "click\u{001B}]8;;" <> st, ) |> should.equal([#(0, 49 + l), #(49 + l + 5, 5 + l)])
ansi.match( "\u{001B}]8;;mailto:no-reply@mail.com" <> st <> "mail-me\u{001B}]8;;" <> st, ) |> should.equal([#(0, 29 + l), #(29 + l + 7, 5 + l)])}
pub fn match_title_change_test() { ansi.match( "\u{001B}]0;sg@tota:~/git/\u{0007}\u{001B}[01;32m[sg@tota\u{001B}[01;37m misc-tests\u{001B}[01;32m]$", ) |> should.equal([#(0, 19), #(19, 8), #(35, 8), #(54, 8)])}
pub fn strip_color_test() { ansi.strip( "\u{001B}[0m\u{001B}[4m\u{001B}[42m\u{001B}[31mfoo\u{001B}[39m\u{001B}[49m\u{001B}[24mfoo\u{001B}[0m", ) |> should.equal("foofoo")}
pub fn strip_ls_test() { ansi.strip( "\u{001B}[00;38;5;244m\u{001B}[m\u{001B}[00;38;5;33mfoo\u{001B}[0m", ) |> should.equal("foo")}
pub fn strip_common_csi_test() { ansi.strip("\u{001B}[0;33;49;3;9;4mbar\u{001B}[0m") |> should.equal("bar")}
pub fn strip_link_test() { ansi.strip("\u{001B}]8;;https://github.com\u{0007}click\u{001B}]8;;\u{0007}") |> should.equal("click")}
pub fn strip_with_remainder_test() { ansi.strip("wibble\u{001B}[00;38;5;244mwobble") |> should.equal("wibblewobble")}
pub fn emoji_test() { ansi.strip( "👩👩👦👦\u{1b}[00;38;5;244mhello\u{1b}[m👩👩👦👦", ) |> should.equal("👩👩👦👦hello👩👩👦👦")}
pub fn docs_test() { ansi.strip("\u{1b}[0;33;49;3;9;4mhi~\u{1b}[0m") |> should.equal("hi~")
ansi.strip("check out \u{1b}]8;;https://gleam.run\u{7}Gleam!\u{1b}]8;;\u{7}") |> should.equal("check out Gleam!")}