Current section
Files
Jump to
Current section
Files
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, port_link/2, reference/1, storage/1, storage_words/1, storage_detailed/1, bool/1, named_remote_process/2, system_primitive_interactive/2, function/1, number/1]).
-file("/Users/jonas/Projects/spectator/src/spectator/internal/views/display.gleam", 15).
-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", 63).
-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", 76).
-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", 80).
-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", 19).
-spec pid_button(
gleam@erlang@process:pid_(),
gleam@option:option(gleam@erlang@atom:atom_()),
gleam@option:option(binary()),
fun((gleam@erlang@process:pid_()) -> APRO)
) -> lustre@internals@vdom:element(APRO).
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, Tag@1}} ->
lustre@element@html:button(
[lustre@event:on_click(On_click(Pid)),
lustre@attribute:class(
<<"interactive-primitive tagged"/utf8>>
)],
[lustre@element@html:text(
<<Tag@1/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(
<<<<<<Tag@2/binary, "<"/utf8>>/binary,
(erlang:atom_to_binary(Name@2))/binary>>/binary,
">"/utf8>>
)]
)
end.
-file("/Users/jonas/Projects/spectator/src/spectator/internal/views/display.gleam", 67).
-spec port_link(
gleam@erlang@port:port_(),
gleam@option:option(gleam@erlang@atom:atom_())
) -> lustre@internals@vdom:element(any()).
port_link(Port, Name) ->
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:href(<<"#"/utf8>>)],
[lustre@element@html:text(Label)]
).
-file("/Users/jonas/Projects/spectator/src/spectator/internal/views/display.gleam", 84).
-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", 93).
-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", 89).
-spec storage_words(integer()) -> lustre@internals@vdom:element(any()).
storage_words(Words) ->
storage(Words * spectator_ffi:get_word_size()).
-file("/Users/jonas/Projects/spectator/src/spectator/internal/views/display.gleam", 101).
-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", 114).
-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", 121).
-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", 125).
-spec system_primitive_interactive(
spectator@internal@api:system_primitive(),
fun((gleam@erlang@process:pid_()) -> APSC)
) -> lustre@internals@vdom:element(APSC).
system_primitive_interactive(Primitive, On_process_click) ->
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);
{nif_resource_primitive, _} ->
lustre@element@html:text(<<"NIF Res"/utf8>>)
end.
-file("/Users/jonas/Projects/spectator/src/spectator/internal/views/display.gleam", 138).
-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", 150).
-spec number(integer()) -> lustre@internals@vdom:element(any()).
number(N) ->
lustre@element@html:text(gleam@int:to_string(N)).