Current section

Files

Jump to
spectator src spectator@internal@views@display.erl
Raw

src/spectator@internal@views@display.erl

-module(spectator@internal@views@display).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([pid/1, port/1, inspect/1, atom/1, pid_button/4, pid_link/4, port_link/3, reference/1, storage/1, storage_words/2, storage_detailed/1, bool/1, named_remote_process/2, system_primitive_interactive/3, system_primitive/2, function/1, number/1]).
-file("/Users/jonas/Projects/spectator/src/spectator/internal/views/display.gleam", 16).
-spec pid(gleam@erlang@process:pid_()) -> lustre@internals@vdom:element(any()).
pid(Pid) ->
lustre@element@html:text(spectator_ffi:format_pid(Pid)).
-file("/Users/jonas/Projects/spectator/src/spectator/internal/views/display.gleam", 146).
-spec port(gleam@erlang@port:port_()) -> lustre@internals@vdom:element(any()).
port(Port) ->
lustre@element@html:text(spectator_ffi:format_port(Port)).
-file("/Users/jonas/Projects/spectator/src/spectator/internal/views/display.gleam", 172).
-spec inspect(gleam@dynamic:dynamic_()) -> lustre@internals@vdom:element(any()).
inspect(D) ->
lustre@element@html:text(gleam@string:inspect(D)).
-file("/Users/jonas/Projects/spectator/src/spectator/internal/views/display.gleam", 176).
-spec atom(gleam@erlang@atom:atom_()) -> lustre@internals@vdom:element(any()).
atom(A) ->
lustre@element@html:text(erlang:atom_to_binary(A)).
-file("/Users/jonas/Projects/spectator/src/spectator/internal/views/display.gleam", 20).
-spec pid_button(
gleam@erlang@process:pid_(),
gleam@option:option(gleam@erlang@atom:atom_()),
gleam@option:option(binary()),
fun((gleam@erlang@process:pid_()) -> AQNZ)
) -> lustre@internals@vdom:element(AQNZ).
pid_button(Pid, Name, Tag, On_click) ->
case {Name, Tag} of
{none, none} ->
lustre@element@html:button(
[lustre@event:on_click(On_click(Pid)),
lustre@attribute:class(<<"interactive-primitive"/utf8>>)],
[lustre@element@html:text(spectator_ffi:format_pid(Pid))]
);
{{some, Name@1}, none} ->
lustre@element@html:button(
[lustre@event:on_click(On_click(Pid)),
lustre@attribute:class(
<<"interactive-primitive named"/utf8>>
),
lustre@attribute:title(
<<"PID"/utf8, (spectator_ffi:format_pid(Pid))/binary>>
)],
[lustre@element@html:text(erlang:atom_to_binary(Name@1))]
);
{none, {some, <<"__spectator_internal"/utf8, Internal_tag/binary>>}} ->
lustre@element@html:button(
[lustre@event:on_click(On_click(Pid)),
lustre@attribute:class(
<<"interactive-primitive muted"/utf8>>
),
lustre@attribute:title(
<<"This process is used for the Spectator application"/utf8>>
)],
[lustre@element@html:text(
<<<<"🔍"/utf8, Internal_tag/binary>>/binary,
(spectator_ffi:format_pid(Pid))/binary>>
)]
);
{none, {some, Tag@1}} ->
lustre@element@html:button(
[lustre@event:on_click(On_click(Pid)),
lustre@attribute:class(
<<"interactive-primitive tagged"/utf8>>
)],
[lustre@element@html:text(
<<<<"🔖 "/utf8, Tag@1/binary>>/binary,
(spectator_ffi:format_pid(Pid))/binary>>
)]
);
{{some, Name@2}, {some, Tag@2}} ->
lustre@element@html:button(
[lustre@event:on_click(On_click(Pid)),
lustre@attribute:class(
<<"interactive-primitive named tagged"/utf8>>
),
lustre@attribute:title(
<<"PID"/utf8, (spectator_ffi:format_pid(Pid))/binary>>
)],
[lustre@element@html:text(
<<<<<<<<"🔖 "/utf8, Tag@2/binary>>/binary, "<"/utf8>>/binary,
(erlang:atom_to_binary(Name@2))/binary>>/binary,
">"/utf8>>
)]
)
end.
-file("/Users/jonas/Projects/spectator/src/spectator/internal/views/display.gleam", 73).
-spec pid_link(
gleam@erlang@process:pid_(),
gleam@option:option(gleam@erlang@atom:atom_()),
gleam@option:option(binary()),
list({binary(), binary()})
) -> lustre@internals@vdom:element(any()).
pid_link(Pid, Name, Tag, Params) ->
case {Name, Tag} of
{none, none} ->
lustre@element@html:a(
[lustre@attribute:href(
<<"/processes"/utf8,
(begin
_pipe = spectator@internal@common:add_param(
Params,
<<"selected"/utf8>>,
spectator@internal@api:serialize_pid(Pid)
),
spectator@internal@common:encode_params(_pipe)
end)/binary>>
),
lustre@attribute:class(<<"interactive-primitive"/utf8>>)],
[lustre@element@html:text(spectator_ffi:format_pid(Pid))]
);
{{some, Name@1}, none} ->
lustre@element@html:a(
[lustre@attribute:href(
<<"/processes"/utf8,
(begin
_pipe@1 = spectator@internal@common:add_param(
Params,
<<"selected"/utf8>>,
spectator@internal@api:serialize_pid(Pid)
),
spectator@internal@common:encode_params(_pipe@1)
end)/binary>>
),
lustre@attribute:class(
<<"interactive-primitive named"/utf8>>
),
lustre@attribute:title(
<<"PID"/utf8, (spectator_ffi:format_pid(Pid))/binary>>
)],
[lustre@element@html:text(erlang:atom_to_binary(Name@1))]
);
{none, {some, <<"__spectator_internal"/utf8, Internal_tag/binary>>}} ->
lustre@element@html:a(
[lustre@attribute:href(
<<"/processes"/utf8,
(begin
_pipe@2 = spectator@internal@common:add_param(
Params,
<<"selected"/utf8>>,
spectator@internal@api:serialize_pid(Pid)
),
spectator@internal@common:encode_params(_pipe@2)
end)/binary>>
),
lustre@attribute:class(
<<"interactive-primitive muted"/utf8>>
),
lustre@attribute:title(
<<"This process is used for the Spectator application"/utf8>>
)],
[lustre@element@html:text(
<<<<"🔍"/utf8, Internal_tag/binary>>/binary,
(spectator_ffi:format_pid(Pid))/binary>>
)]
);
{none, {some, Tag@1}} ->
lustre@element@html:a(
[lustre@attribute:href(
<<"/processes"/utf8,
(begin
_pipe@3 = spectator@internal@common:add_param(
Params,
<<"selected"/utf8>>,
spectator@internal@api:serialize_pid(Pid)
),
spectator@internal@common:encode_params(_pipe@3)
end)/binary>>
),
lustre@attribute:class(
<<"interactive-primitive tagged"/utf8>>
)],
[lustre@element@html:text(
<<<<"🔖 "/utf8, Tag@1/binary>>/binary,
(spectator_ffi:format_pid(Pid))/binary>>
)]
);
{{some, Name@2}, {some, Tag@2}} ->
lustre@element@html:a(
[lustre@attribute:href(
<<"/processes"/utf8,
(begin
_pipe@4 = spectator@internal@common:add_param(
Params,
<<"selected"/utf8>>,
spectator@internal@api:serialize_pid(Pid)
),
spectator@internal@common:encode_params(_pipe@4)
end)/binary>>
),
lustre@attribute:class(
<<"interactive-primitive named tagged"/utf8>>
),
lustre@attribute:title(
<<"PID"/utf8, (spectator_ffi:format_pid(Pid))/binary>>
)],
[lustre@element@html:text(
<<<<<<<<"🔖 "/utf8, Tag@2/binary>>/binary, "<"/utf8>>/binary,
(erlang:atom_to_binary(Name@2))/binary>>/binary,
">"/utf8>>
)]
)
end.
-file("/Users/jonas/Projects/spectator/src/spectator/internal/views/display.gleam", 150).
-spec port_link(
gleam@erlang@port:port_(),
gleam@option:option(gleam@erlang@atom:atom_()),
list({binary(), binary()})
) -> lustre@internals@vdom:element(any()).
port_link(Port, Name, Params) ->
Label = case Name of
none ->
spectator_ffi:format_port(Port);
{some, N} ->
<<<<<<(spectator_ffi:format_port(Port))/binary, " ("/utf8>>/binary,
(erlang:atom_to_binary(N))/binary>>/binary,
")"/utf8>>
end,
lustre@element@html:a(
[lustre@attribute:class(<<"interactive-primitive"/utf8>>),
lustre@attribute:href(
<<"/ports"/utf8,
(begin
_pipe = spectator@internal@common:add_param(
Params,
<<"selected"/utf8>>,
spectator@internal@api:serialize_port(Port)
),
spectator@internal@common:encode_params(_pipe)
end)/binary>>
)],
[lustre@element@html:text(Label)]
).
-file("/Users/jonas/Projects/spectator/src/spectator/internal/views/display.gleam", 180).
-spec reference(gleam@erlang:reference_()) -> lustre@internals@vdom:element(any()).
reference(Ref) ->
lustre@element@html:text(gleam@string:inspect(Ref)).
-file("/Users/jonas/Projects/spectator/src/spectator/internal/views/display.gleam", 188).
-spec storage(integer()) -> lustre@internals@vdom:element(any()).
storage(Size) ->
case Size of
_ when Size < 1024 ->
lustre@element@html:text(
<<(gleam@int:to_string(Size))/binary, " B"/utf8>>
);
_ when Size < 1048576 ->
lustre@element@html:text(
<<(gleam@int:to_string(Size div 1024))/binary, " KiB"/utf8>>
);
_ ->
lustre@element@html:text(
<<(gleam@int:to_string((Size div 1024) div 1024))/binary,
" MiB"/utf8>>
)
end.
-file("/Users/jonas/Projects/spectator/src/spectator/internal/views/display.gleam", 184).
-spec storage_words(integer(), integer()) -> lustre@internals@vdom:element(any()).
storage_words(Words, Word_size) ->
storage(Words * Word_size).
-file("/Users/jonas/Projects/spectator/src/spectator/internal/views/display.gleam", 196).
-spec storage_detailed(integer()) -> lustre@internals@vdom:element(any()).
storage_detailed(Size) ->
Byte_size = <<(gleam@int:to_string(Size))/binary, " Bytes"/utf8>>,
case Size of
_ when Size < 1024 ->
lustre@element@html:text(Byte_size);
_ when Size < 1048576 ->
lustre@element@html:text(
<<<<<<Byte_size/binary, " ("/utf8>>/binary,
(gleam@int:to_string(Size div 1024))/binary>>/binary,
" KiB)"/utf8>>
);
_ ->
lustre@element@html:text(
<<<<<<Byte_size/binary, " ("/utf8>>/binary,
(gleam@int:to_string((Size div 1024) div 1024))/binary>>/binary,
" MiB)"/utf8>>
)
end.
-file("/Users/jonas/Projects/spectator/src/spectator/internal/views/display.gleam", 209).
-spec bool(boolean()) -> lustre@internals@vdom:element(any()).
bool(B) ->
case B of
true ->
lustre@element@html:text(<<"true"/utf8>>);
false ->
lustre@element@html:text(<<"false"/utf8>>)
end.
-file("/Users/jonas/Projects/spectator/src/spectator/internal/views/display.gleam", 216).
-spec named_remote_process(gleam@erlang@atom:atom_(), gleam@erlang@atom:atom_()) -> lustre@internals@vdom:element(any()).
named_remote_process(Name, Node) ->
lustre@element@html:text(
<<<<(erlang:atom_to_binary(Name))/binary, " on "/utf8>>/binary,
(erlang:atom_to_binary(Node))/binary>>
).
-file("/Users/jonas/Projects/spectator/src/spectator/internal/views/display.gleam", 220).
-spec system_primitive_interactive(
spectator@internal@api:system_primitive(),
fun((gleam@erlang@process:pid_()) -> AQOQ),
list({binary(), binary()})
) -> lustre@internals@vdom:element(AQOQ).
system_primitive_interactive(Primitive, On_process_click, Params) ->
case Primitive of
{process_primitive, Pid, Name, Tag} ->
pid_button(Pid, Name, Tag, On_process_click);
{remote_process_primitive, Name@1, Node} ->
named_remote_process(Name@1, Node);
{port_primitive, Port_id, Name@2} ->
port_link(Port_id, Name@2, Params);
{nif_resource_primitive, _} ->
lustre@element@html:text(<<"NIF Res."/utf8>>)
end.
-file("/Users/jonas/Projects/spectator/src/spectator/internal/views/display.gleam", 234).
-spec system_primitive(
spectator@internal@api:system_primitive(),
list({binary(), binary()})
) -> lustre@internals@vdom:element(any()).
system_primitive(Primitive, Params) ->
case Primitive of
{process_primitive, Pid, Name, Tag} ->
pid_link(Pid, Name, Tag, Params);
{remote_process_primitive, Name@1, Node} ->
named_remote_process(Name@1, Node);
{port_primitive, Port_id, Name@2} ->
port_link(Port_id, Name@2, Params);
{nif_resource_primitive, _} ->
lustre@element@html:text(<<"NIF Res."/utf8>>)
end.
-file("/Users/jonas/Projects/spectator/src/spectator/internal/views/display.gleam", 243).
-spec function(
{gleam@erlang@atom:atom_(), gleam@erlang@atom:atom_(), integer()}
) -> lustre@internals@vdom:element(any()).
function(Ref) ->
{Module, Function, Arity} = Ref,
lustre@element@html:text(
<<<<<<<<(erlang:atom_to_binary(Module))/binary, ":"/utf8>>/binary,
(erlang:atom_to_binary(Function))/binary>>/binary,
"/"/utf8>>/binary,
(gleam@int:to_string(Arity))/binary>>
).
-file("/Users/jonas/Projects/spectator/src/spectator/internal/views/display.gleam", 255).
-spec number(integer()) -> lustre@internals@vdom:element(any()).
number(N) ->
lustre@element@html:text(gleam@int:to_string(N)).