Packages
glint
1.1.0
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]).
-file("/home/runner/work/glint/glint/src/glint/internal/utils.gleam", 8).
-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).
-file("/home/runner/work/glint/glint/src/glint/internal/utils.gleam", 27).
-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.
-file("/home/runner/work/glint/glint/src/glint/internal/utils.gleam", 63).
-spec space_split_lines(binary()) -> list(binary()).
space_split_lines(S) ->
Chunks = begin
_pipe = S,
_pipe@1 = gleam@string:trim(_pipe),
_pipe@2 = gleam@string:to_graphemes(_pipe@1),
gleam@list:chunk(_pipe@2, fun(S@1) -> S@1 =:= <<"\n"/utf8>> end)
end,
Lines = (gleam@list:fold(
Chunks,
{[], false},
fun(Acc, Chunk) -> case {Chunk, erlang:element(1, Acc)} of
{[<<"\n"/utf8>>, <<"\n"/utf8>> | Rest], [S@2 | Accs]} ->
{[<<S@2/binary, (gleam@string:concat(Rest))/binary>> | Accs],
true};
{[<<"\n"/utf8>>], [S@3 | Accs@1]} ->
{[<<S@3/binary, " "/utf8>> | Accs@1], false};
{_, [S@4 | Accs@2]} when not erlang:element(2, Acc) ->
{[<<S@4/binary, (gleam@string:concat(Chunk))/binary>> |
Accs@2],
false};
{_, _} ->
{[gleam@string:concat(Chunk) | erlang:element(1, Acc)],
false}
end end
)),
lists:reverse(erlang:element(1, Lines)).
-file("/home/runner/work/glint/glint/src/glint/internal/utils.gleam", 19).
-spec wordwrap(binary(), integer()) -> list(binary()).
wordwrap(S, Max_width) ->
gleam@bool:guard(
S =:= <<""/utf8>>,
[],
fun() ->
gleam@list:flat_map(space_split_lines(S), fun(Line) -> _pipe = Line,
_pipe@1 = gleam@string:split(_pipe, <<" "/utf8>>),
do_wordwrap(_pipe@1, Max_width, <<""/utf8>>, []) end)
end
).