Current section
Files
Jump to
Current section
Files
src/utils@text.erl
-module(utils@text).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/utils/text.gleam").
-export([overwrite_with_padding/2, get_box_chars/1, align_text/3]).
-file("src/utils/text.gleam", 6).
-spec overwrite_with_padding(binary(), binary()) -> nil.
overwrite_with_padding(Old_text, New_text) ->
Old_length = string:length(Old_text),
New_length = string:length(New_text),
Padding_needed = case Old_length > New_length of
true ->
Old_length - New_length;
false ->
0
end,
Padding = gleam@string:repeat(<<" "/utf8>>, Padding_needed),
gleam_stdlib:print(
<<<<"\r"/utf8, New_text/binary>>/binary, Padding/binary>>
).
-file("src/utils/text.gleam", 17).
-spec get_box_chars(types@box_style:box_style()) -> {binary(),
binary(),
binary(),
binary(),
binary(),
binary()}.
get_box_chars(Style) ->
case Style of
single ->
{<<"┌"/utf8>>,
<<"┐"/utf8>>,
<<"└"/utf8>>,
<<"┘"/utf8>>,
<<"─"/utf8>>,
<<"│"/utf8>>};
double ->
{<<"╔"/utf8>>,
<<"╗"/utf8>>,
<<"╚"/utf8>>,
<<"╝"/utf8>>,
<<"═"/utf8>>,
<<"║"/utf8>>};
rounded ->
{<<"╭"/utf8>>,
<<"╮"/utf8>>,
<<"╰"/utf8>>,
<<"╯"/utf8>>,
<<"─"/utf8>>,
<<"│"/utf8>>};
thick ->
{<<"┏"/utf8>>,
<<"┓"/utf8>>,
<<"┗"/utf8>>,
<<"┛"/utf8>>,
<<"━"/utf8>>,
<<"┃"/utf8>>}
end.
-file("src/utils/text.gleam", 28).
-spec align_text(binary(), integer(), types@alignment:alignment()) -> binary().
align_text(Text, Width, Alignment) ->
Text_length = string:length(Text),
case Text_length >= Width of
true ->
gleam@string:slice(Text, 0, Width);
false ->
Padding = Width - Text_length,
case Alignment of
left ->
<<Text/binary,
(gleam@string:repeat(<<" "/utf8>>, Padding))/binary>>;
right ->
<<(gleam@string:repeat(<<" "/utf8>>, Padding))/binary,
Text/binary>>;
center ->
Left_pad = Padding div 2,
Right_pad = Padding - Left_pad,
<<<<(gleam@string:repeat(<<" "/utf8>>, Left_pad))/binary,
Text/binary>>/binary,
(gleam@string:repeat(<<" "/utf8>>, Right_pad))/binary>>
end
end.