Current section
Files
Jump to
Current section
Files
src/halo.erl
-module(halo).
-compile([no_auto_import, nowarn_unused_vars]).
-export([update_path/0, main/0]).
-export_type([notification/0, event/0]).
-type notification() :: {notification, binary(), list(event())}.
-type event() :: created | modified | removed | renamed | undefined.
-spec update_path() -> nil.
update_path() ->
_ = begin
Build_dir = <<"build/dev/erlang/"/utf8>>,
gleam@result:map(
gleam_erlang_ffi:list_directory(Build_dir),
fun(Modules) -> _pipe = Modules,
_pipe@1 = gleam@list:filter_map(
_pipe,
fun(Module) ->
case gleam@erlang@file:is_directory(
<<Build_dir/binary, Module/binary>>
) of
{ok, true} ->
{ok,
<<<<Build_dir/binary, Module/binary>>/binary,
"/ebin"/utf8>>};
_ ->
{error, nil}
end
end
),
halo@code:add_paths(_pipe@1) end
)
end,
nil.
-spec watch_loop() -> any().
watch_loop() ->
Notif = 'receive'(),
update_path(),
case gleam@string:ends_with(erlang:element(2, Notif), <<".gleam"/utf8>>) of
true ->
case shellout:command(
<<"gleam"/utf8>>,
[<<"build"/utf8>>],
<<"."/utf8>>,
[]
) of
{ok, _} ->
Modified = code:modified_modules(),
case gleam@list:length(Modified) of
0 ->
nil;
_ ->
case halo@code:soft_purge_all(Modified) of
{ok, nil} ->
_assert_subject = code:atomic_load(Modified),
ok = case _assert_subject of
ok -> _assert_subject;
_assert_fail ->
erlang:error(
#{gleam_error => assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail,
module => <<"halo"/utf8>>,
function => <<"watch_loop"/utf8>>,
line => 75}
)
end,
gleam@io:println(<<"REPL: reload."/utf8>>);
{error, Mod} ->
gleam@io:println(
<<<<"REPL: could not purge module "/utf8,
(halo_erl:module_name(Mod))/binary>>/binary,
", please clean up processes running old code."/utf8>>
)
end
end;
{error, _} ->
gleam@io:println(
<<"REPL: compilation failed, no reload."/utf8>>
)
end;
false ->
nil
end,
watch_loop().
-spec main() -> any().
main() ->
Fswatcher = erlang:binary_to_atom(<<"fswatcher"/utf8>>),
_assert_subject = fs:start_link(Fswatcher),
{ok, _} = case _assert_subject of
{ok, _} -> _assert_subject;
_assert_fail ->
erlang:error(#{gleam_error => assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail,
module => <<"halo"/utf8>>,
function => <<"main"/utf8>>,
line => 34})
end,
fs:subscribe(Fswatcher),
update_path(),
_assert_subject@1 = shell:start_interactive(),
ok = case _assert_subject@1 of
ok -> _assert_subject@1;
_assert_fail@1 ->
erlang:error(#{gleam_error => assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail@1,
module => <<"halo"/utf8>>,
function => <<"main"/utf8>>,
line => 39})
end,
watch_loop().
-spec 'receive'() -> notification().
'receive'() ->
Notif = begin
_pipe = gleam_erlang_ffi:new_selector(),
_pipe@5 = gleam@erlang@process:selecting_anything(
_pipe,
fun(Msg) ->
Msg@1 = begin
_pipe@1 = Msg,
(gleam@dynamic:tuple3(
fun gleam@dynamic:dynamic/1,
fun gleam@dynamic:dynamic/1,
fun(Payload) -> _pipe@2 = Payload,
(gleam@dynamic:tuple2(
gleam@dynamic:list(fun gleam@dynamic:int/1),
gleam@dynamic:list(fun halo_erl:decode_event/1)
))(_pipe@2) end
))(_pipe@1)
end,
gleam@result:'try'(
Msg@1,
fun(_use0) ->
{_, _, {Path, Events}} = _use0,
Path@1 = begin
_pipe@3 = Path,
_pipe@4 = gleam@list:map(
_pipe@3,
fun(I) ->
_assert_subject = gleam@string:utf_codepoint(
I
),
{ok, C} = case _assert_subject of
{ok, _} -> _assert_subject;
_assert_fail ->
erlang:error(
#{gleam_error => assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail,
module => <<"halo"/utf8>>,
function => <<"receive"/utf8>>,
line => 118}
)
end,
C
end
),
gleam@string:from_utf_codepoints(_pipe@4)
end,
{ok, {notification, Path@1, Events}}
end
)
end
),
gleam_erlang_ffi:select(_pipe@5)
end,
case Notif of
{ok, Notif@1} ->
Notif@1;
{error, _} ->
'receive'()
end.