Current section

Files

Jump to
shiny src ui@progress.erl
Raw

src/ui@progress.erl

-module(ui@progress).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/ui/progress.gleam").
-export([progress_bar/3]).
-file("src/ui/progress.gleam", 5).
-spec progress_bar(integer(), integer(), integer()) -> binary().
progress_bar(Current, Total, Width) ->
Progress = case Total of
0 ->
+0.0;
_ ->
case erlang:float(Total) of
+0.0 -> +0.0;
-0.0 -> -0.0;
Gleam@denominator -> erlang:float(Current) / Gleam@denominator
end
end,
Filled = erlang:round(Progress * erlang:float(Width)),
Filled_str = gleam@string:repeat(<<"█"/utf8>>, Filled),
Empty_str = gleam@string:repeat(<<"░"/utf8>>, Width - Filled),
Percentage = erlang:round(Progress * 100.0),
<<<<<<<<<<"["/utf8, Filled_str/binary>>/binary, Empty_str/binary>>/binary,
"] "/utf8>>/binary,
(erlang:integer_to_binary(Percentage))/binary>>/binary,
"%"/utf8>>.