Packages
glint
1.0.0-rc3
1.3.0
1.2.1
1.2.0
1.1.1
1.1.0
1.0.1
1.0.0
1.0.0-rc5
1.0.0-rc4
1.0.0-rc3
1.0.0-rc2
1.0.0-rc1
0.18.1
0.18.0
0.17.1
0.17.0
0.16.0
0.16.0-rc1
0.15.0
0.15.0-rc2
0.15.0-rc1
0.14.0
0.13.0
0.12.0
0.12.0-rc6
0.12.0-rc5
0.12.0-rc4
0.12.0-rc3
0.12.0-rc2
0.12.0-rc1
0.11.4
0.11.3
0.11.2
0.11.0
0.10.0
0.9.0
0.8.0
0.7.4
0.7.3
0.7.2
0.7.1
0.7.0
0.6.0
0.5.0
0.4.0
0.3.0
0.2.0
0.1.3
0.1.2
0.1.1
0.1.0
Gleam command-line argument parsing with flags and automated help text generation.
Current section
Files
Jump to
Current section
Files
src/glint@internal@utils.erl
-module(glint@internal@utils).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([max_string_length/1, wordwrap/2]).
-spec max_string_length(list(binary())) -> integer().
max_string_length(Strings) ->
gleam@list:fold(Strings, 0, fun(Max, F) -> _pipe = F,
_pipe@1 = gleam@string:length(_pipe),
gleam@int:max(_pipe@1, Max) end).
-spec do_wordwrap(list(binary()), integer(), binary(), list(binary())) -> list(binary()).
do_wordwrap(Tokens, Max_width, Line, Lines) ->
case Tokens of
[Token | Tokens@1] ->
Token_length = gleam@string:length(Token),
Line_length = gleam@string:length(Line),
case {Line, ((Line_length + 1) + Token_length) =< Max_width} of
{<<""/utf8>>, _} ->
do_wordwrap(Tokens@1, Max_width, Token, Lines);
{_, true} ->
do_wordwrap(
Tokens@1,
Max_width,
<<<<Line/binary, " "/utf8>>/binary, Token/binary>>,
Lines
);
{_, false} ->
do_wordwrap(Tokens@1, Max_width, Token, [Line | Lines])
end;
[] when Line =:= <<""/utf8>> ->
lists:reverse(Lines);
[] ->
lists:reverse([Line | Lines])
end.
-spec wordwrap(binary(), integer()) -> list(binary()).
wordwrap(S, Max_width) ->
gleam@list:flat_map(
gleam@string:split(S, <<"\n"/utf8>>),
fun(Line) -> _pipe = Line,
_pipe@1 = gleam@string:split(_pipe, <<" "/utf8>>),
do_wordwrap(_pipe@1, Max_width, <<""/utf8>>, []) end
).