wolfadex / elm-ansi / Ansi.String

Various functions for working with ANSI strings. E.g. when measuring the width of an ANSI string you don't want to include any of the command characters, only those that are displayed in the terminal.

width : String -> Basics.Int

Measures the width of a String in terminal columns.

Copied from https://github.com/sindresorhus/string-width/blob/main/index.js

padRight : Basics.Int -> String -> String -> String

Add the specified string to the right side of your String so that it's the specified length. If this is impossible, e.g. in padRight 10 "🌈" "hello" the 🌈 is 2 columns wide meaning that your result will be either 9 or 11 columns wide, then white space will be added to fill the remaining space.

strip : String -> String

Remove ANSI characters from a String. Mostly useful for things like measuring a String's width.

regex : Regex

Matches ANSI characters

Borrowed from https://github.com/chalk/ansi-regex

emojiRegex : Regex

Matches emojis

Borrowed from https://github.com/mathiasbynens/emoji-regex