-module(glitzer@progress). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([char_from_string/1, string_from_char/1, default_bar/0, slim_bar/0, fancy_slim_bar/0, fancy_slim_arrow_bar/0, thick_bar/0, fancy_thick_bar/0, new_bar/0, with_left_text/2, with_right_text/2, with_empty/2, with_fill/2, with_fill_finished/2, with_fill_head/2, with_fill_head_finished/2, with_length/2, tick/1, tick_by/2, finish/1, print_bar/1, map_iterator/3, map2_iterator/4, each_iterator/3, map_yielder/3, map2_yielder/4, each_yielder/3]). -export_type([char_/0, state/0, progress_style/0]). -opaque char_() :: {char, binary()}. -opaque state() :: {state, integer(), boolean()}. -opaque progress_style() :: {progress_style, binary(), binary(), char_(), char_(), gleam@option:option(char_()), gleam@option:option(char_()), gleam@option:option(char_()), integer(), state()}. -file("/home/motte/Projects/glitzer/src/glitzer/progress.gleam", 81). -spec char_from_string(binary()) -> char_(). char_from_string(In) -> Len = gleam@string:length(In), case Len of 1 -> {char, In}; _ -> {char, <<"#"/utf8>>} end. -file("/home/motte/Projects/glitzer/src/glitzer/progress.gleam", 91). -spec string_from_char(char_()) -> binary(). string_from_char(In) -> erlang:element(2, In). -file("/home/motte/Projects/glitzer/src/glitzer/progress.gleam", 117). -spec default_bar() -> progress_style(). default_bar() -> {progress_style, <<"["/utf8>>, <<"]"/utf8>>, {char, <<" "/utf8>>}, {char, <<"#"/utf8>>}, none, none, none, 100, {state, 0, false}}. -file("/home/motte/Projects/glitzer/src/glitzer/progress.gleam", 132). -spec slim_bar() -> progress_style(). slim_bar() -> Sym = <<"\x{2014}"/utf8>>, {progress_style, <<""/utf8>>, <<""/utf8>>, {char, <<" "/utf8>>}, {char, Sym}, none, none, none, 100, {state, 0, false}}. -file("/home/motte/Projects/glitzer/src/glitzer/progress.gleam", 148). -spec fancy_slim_bar() -> progress_style(). fancy_slim_bar() -> Sym = <<"\x{2014}"/utf8>>, {progress_style, <<""/utf8>>, <<""/utf8>>, {char, gleam_community@ansi:blue(Sym)}, {char, gleam_community@ansi:red(Sym)}, {some, {char, gleam_community@ansi:green(Sym)}}, none, none, 100, {state, 0, false}}. -file("/home/motte/Projects/glitzer/src/glitzer/progress.gleam", 164). -spec fancy_slim_arrow_bar() -> progress_style(). fancy_slim_arrow_bar() -> Sym = <<"\x{2014}"/utf8>>, Sym_head = <<"\x{2192}"/utf8>>, {progress_style, <<""/utf8>>, <<""/utf8>>, {char, gleam_community@ansi:blue(Sym)}, {char, gleam_community@ansi:red(Sym)}, {some, {char, gleam_community@ansi:green(Sym)}}, {some, {char, gleam_community@ansi:red(Sym_head)}}, {some, {char, gleam_community@ansi:green(Sym_head)}}, 100, {state, 0, false}}. -file("/home/motte/Projects/glitzer/src/glitzer/progress.gleam", 181). -spec thick_bar() -> progress_style(). thick_bar() -> Sym = <<"\x{2588}"/utf8>>, Empty_sym = <<"\x{2592}"/utf8>>, {progress_style, <<""/utf8>>, <<""/utf8>>, {char, Empty_sym}, {char, Sym}, none, none, none, 100, {state, 0, false}}. -file("/home/motte/Projects/glitzer/src/glitzer/progress.gleam", 198). -spec fancy_thick_bar() -> progress_style(). fancy_thick_bar() -> Sym = <<"\x{2588}"/utf8>>, Empty_sym = <<"\x{2592}"/utf8>>, {progress_style, <<""/utf8>>, <<""/utf8>>, {char, gleam_community@ansi:blue(Empty_sym)}, {char, gleam_community@ansi:red(Sym)}, {some, {char, gleam_community@ansi:green(Sym)}}, none, none, 100, {state, 0, false}}. -file("/home/motte/Projects/glitzer/src/glitzer/progress.gleam", 234). -spec new_bar() -> progress_style(). new_bar() -> {progress_style, <<""/utf8>>, <<""/utf8>>, {char, <<" "/utf8>>}, {char, <<" "/utf8>>}, none, none, none, 0, {state, 0, false}}. -file("/home/motte/Projects/glitzer/src/glitzer/progress.gleam", 249). -spec with_left_text(progress_style(), binary()) -> progress_style(). with_left_text(Bar, Text) -> erlang:setelement(2, Bar, Text). -file("/home/motte/Projects/glitzer/src/glitzer/progress.gleam", 257). -spec with_right_text(progress_style(), binary()) -> progress_style(). with_right_text(Bar, Text) -> erlang:setelement(3, Bar, Text). -file("/home/motte/Projects/glitzer/src/glitzer/progress.gleam", 266). -spec with_empty(progress_style(), char_()) -> progress_style(). with_empty(Bar, Char) -> erlang:setelement(4, Bar, Char). -file("/home/motte/Projects/glitzer/src/glitzer/progress.gleam", 272). -spec with_fill(progress_style(), char_()) -> progress_style(). with_fill(Bar, Char) -> erlang:setelement(5, Bar, Char). -file("/home/motte/Projects/glitzer/src/glitzer/progress.gleam", 277). -spec with_fill_finished(progress_style(), char_()) -> progress_style(). with_fill_finished(Bar, Char) -> erlang:setelement(6, Bar, {some, Char}). -file("/home/motte/Projects/glitzer/src/glitzer/progress.gleam", 285). -spec with_fill_head(progress_style(), char_()) -> progress_style(). with_fill_head(Bar, Char) -> erlang:setelement(7, Bar, {some, Char}). -file("/home/motte/Projects/glitzer/src/glitzer/progress.gleam", 291). -spec with_fill_head_finished(progress_style(), char_()) -> progress_style(). with_fill_head_finished(Bar, Char) -> erlang:setelement(8, Bar, {some, Char}). -file("/home/motte/Projects/glitzer/src/glitzer/progress.gleam", 299). -spec with_length(progress_style(), integer()) -> progress_style(). with_length(Bar, Len) -> erlang:setelement(9, Bar, Len). -file("/home/motte/Projects/glitzer/src/glitzer/progress.gleam", 304). -spec tick(progress_style()) -> progress_style(). tick(Bar) -> case erlang:element(2, erlang:element(10, Bar)) < (erlang:element(9, Bar) + 1) of true -> erlang:setelement( 10, Bar, erlang:setelement( 2, erlang:element(10, Bar), erlang:element(2, erlang:element(10, Bar)) + 1 ) ); false -> erlang:setelement( 10, Bar, {state, erlang:element(2, erlang:element(10, Bar)) + 1, true} ) end. -file("/home/motte/Projects/glitzer/src/glitzer/progress.gleam", 320). -spec tick_by(progress_style(), integer()) -> progress_style(). tick_by(Bar, I) -> case I > 0 of true -> Bar@1 = tick(Bar), tick_by(Bar@1, I - 1); false -> Bar end. -file("/home/motte/Projects/glitzer/src/glitzer/progress.gleam", 331). -spec finish(progress_style()) -> progress_style(). finish(Bar) -> erlang:setelement(10, Bar, {state, erlang:element(9, Bar) + 1, true}). -file("/home/motte/Projects/glitzer/src/glitzer/progress.gleam", 412). -spec get_finished_head_fill(gleam@string_tree:string_tree(), progress_style()) -> gleam@string_tree:string_tree(). get_finished_head_fill(Fill, Bar) -> case erlang:element(3, erlang:element(10, Bar)) of true -> gleam@string_tree:append( Fill, erlang:element( 2, gleam@option:unwrap( erlang:element(8, Bar), gleam@option:unwrap( erlang:element(7, Bar), gleam@option:unwrap( erlang:element(6, Bar), erlang:element(5, Bar) ) ) ) ) ); false -> gleam@string_tree:append( Fill, erlang:element( 2, gleam@option:unwrap( erlang:element(7, Bar), erlang:element(5, Bar) ) ) ) end. -file("/home/motte/Projects/glitzer/src/glitzer/progress.gleam", 435). -spec get_finished_fill(gleam@string_tree:string_tree(), progress_style()) -> gleam@string_tree:string_tree(). get_finished_fill(Fill, Bar) -> case erlang:element(3, erlang:element(10, Bar)) of true -> gleam@string_tree:append( Fill, erlang:element( 2, gleam@option:unwrap( erlang:element(6, Bar), erlang:element(5, Bar) ) ) ); false -> gleam@string_tree:append( Fill, erlang:element(2, erlang:element(5, Bar)) ) end. -file("/home/motte/Projects/glitzer/src/glitzer/progress.gleam", 389). -spec build_progress_fill( gleam@string_tree:string_tree(), progress_style(), integer(), integer() ) -> gleam@string_tree:string_tree(). build_progress_fill(Fill, Bar, Left_nonempty, Count) -> Fill@1 = case Left_nonempty > 0 of true -> case Left_nonempty =:= 1 of true -> get_finished_head_fill(Fill, Bar); false -> get_finished_fill(Fill, Bar) end; false -> gleam@string_tree:append( Fill, erlang:element(2, erlang:element(4, Bar)) ) end, case erlang:element(9, Bar) > Count of true -> build_progress_fill(Fill@1, Bar, Left_nonempty - 1, Count + 1); false -> Fill@1 end. -file("/home/motte/Projects/glitzer/src/glitzer/progress.gleam", 363). -spec print_bar(progress_style()) -> nil. print_bar(Bar) -> Bar@1 = erlang:setelement( 10, Bar, erlang:setelement( 3, erlang:element(10, Bar), erlang:element(2, erlang:element(10, Bar)) >= erlang:element(9, Bar) ) ), Fill = begin _pipe = build_progress_fill( gleam@string_tree:new(), Bar@1, erlang:element(2, erlang:element(10, Bar@1)) + 1, 0 ), gleam@string_tree:to_string(_pipe) end, End = case erlang:element(3, erlang:element(10, Bar@1)) of true -> <<"\n"/utf8, (<<"\x{001b}[?25h"/utf8>>)/binary>>; false -> <<""/utf8>> end, gleam@io:print_error( <<<<<<<<<<<<(<<"\x{001b}[?25l"/utf8>>)/binary, (<<"\x{001b}[2K"/utf8>>)/binary>>/binary, (<<"\r"/utf8>>)/binary>>/binary, (erlang:element(2, Bar@1))/binary>>/binary, Fill/binary>>/binary, (erlang:element(3, Bar@1))/binary>>/binary, End/binary>> ). -file("/home/motte/Projects/glitzer/src/glitzer/progress.gleam", 541). -spec tick_bar_by_i(progress_style(), integer()) -> progress_style(). tick_bar_by_i(Bar, I) -> case I > 0 of true -> tick_bar_by_i(tick(Bar), I - 1); false -> Bar end. -file("/home/motte/Projects/glitzer/src/glitzer/progress.gleam", 465). -spec map_iterator( gleam@iterator:iterator(OEY), progress_style(), fun((progress_style(), OEY) -> OFA) ) -> gleam@iterator:iterator(OFA). map_iterator(I, Bar, Fun) -> _pipe = gleam@iterator:index(I), gleam@iterator:map( _pipe, fun(Pair) -> {El, I@1} = Pair, _pipe@1 = tick_bar_by_i(Bar, I@1), Fun(_pipe@1, El) end ). -file("/home/motte/Projects/glitzer/src/glitzer/progress.gleam", 479). -spec map2_iterator( gleam@iterator:iterator(OFC), gleam@iterator:iterator(OFE), progress_style(), fun((progress_style(), OFC, OFE) -> OFG) ) -> gleam@iterator:iterator(OFG). map2_iterator(I1, I2, Bar, Fun) -> _pipe = gleam@iterator:zip(I1, I2), _pipe@1 = gleam@iterator:index(_pipe), gleam@iterator:map( _pipe@1, fun(Pair) -> {Pair@1, I} = Pair, {El1, El2} = Pair@1, _pipe@2 = tick_bar_by_i(Bar, I), Fun(_pipe@2, El1, El2) end ). -file("/home/motte/Projects/glitzer/src/glitzer/progress.gleam", 496). -spec each_iterator( gleam@iterator:iterator(OFI), progress_style(), fun((progress_style(), OFI) -> any()) ) -> nil. each_iterator(I, Bar, Fun) -> _pipe = gleam@iterator:index(I), gleam@iterator:each( _pipe, fun(Pair) -> {El, I@1} = Pair, _pipe@1 = tick_bar_by_i(Bar, I@1), Fun(_pipe@1, El) end ). -file("/home/motte/Projects/glitzer/src/glitzer/progress.gleam", 528). -spec map_yielder( gleam@yielder:yielder(OFL), progress_style(), fun((progress_style(), OFL) -> OFN) ) -> gleam@yielder:yielder(OFN). map_yielder(Y, Bar, Fun) -> _pipe = gleam@yielder:index(Y), gleam@yielder:map( _pipe, fun(Pair) -> {El, I} = Pair, _pipe@1 = tick_bar_by_i(Bar, I), Fun(_pipe@1, El) end ). -file("/home/motte/Projects/glitzer/src/glitzer/progress.gleam", 548). -spec map2_yielder( gleam@yielder:yielder(OFR), gleam@yielder:yielder(OFT), progress_style(), fun((progress_style(), OFR, OFT) -> OFV) ) -> gleam@yielder:yielder(OFV). map2_yielder(Y1, Y2, Bar, Fun) -> _pipe = gleam@yielder:zip(Y1, Y2), _pipe@1 = gleam@yielder:index(_pipe), gleam@yielder:map( _pipe@1, fun(Pair) -> {Pair@1, I} = Pair, {El1, El2} = Pair@1, _pipe@2 = tick_bar_by_i(Bar, I), Fun(_pipe@2, El1, El2) end ). -file("/home/motte/Projects/glitzer/src/glitzer/progress.gleam", 564). -spec each_yielder( gleam@yielder:yielder(OFX), progress_style(), fun((progress_style(), OFX) -> any()) ) -> nil. each_yielder(Y, Bar, Fun) -> _pipe = gleam@yielder:index(Y), gleam@yielder:each( _pipe, fun(Pair) -> {El, I} = Pair, _pipe@1 = tick_bar_by_i(Bar, I), Fun(_pipe@1, El) end ).