Current section
Files
Jump to
Current section
Files
src/plushie@command_encode.erl
-module(plushie@command_encode).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/plushie/command_encode.gleam").
-export([classify/1]).
-export_type([wire_op/1]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
" Command-to-wire classification.\n"
"\n"
" Converts a `Command(msg)` into a `WireOp(msg)`, a tagged union that\n"
" separates the payload construction (shared between BEAM and JS runtimes)\n"
" from the actual send mechanism (runtime-specific). Both runtimes\n"
" pattern-match on `WireOp` and dispatch to their own transport layer.\n"
).
-type wire_op(JZT) :: no_op |
exit |
{run_batch, list(plushie@command:command(JZT))} |
{done_immediate,
gleam@dynamic:dynamic_(),
fun((gleam@dynamic:dynamic_()) -> JZT)} |
{schedule_timer, integer(), JZT} |
{spawn_async, binary(), fun(() -> gleam@dynamic:dynamic_())} |
{spawn_stream,
binary(),
fun((fun((gleam@dynamic:dynamic_()) -> nil)) -> gleam@dynamic:dynamic_())} |
{cancel_task, binary()} |
{command,
binary(),
binary(),
gleam@dict:dict(binary(), plushie@node:prop_value())} |
{command_batch,
list({binary(),
binary(),
gleam@dict:dict(binary(), plushie@node:prop_value())})} |
{widget_op, binary(), list({binary(), plushie@node:prop_value()})} |
{window_op, binary(), binary(), list({binary(), plushie@node:prop_value()})} |
{window_query, binary(), binary(), binary()} |
{system_op, binary(), list({binary(), plushie@node:prop_value()})} |
{system_query, binary(), binary()} |
{image_op, binary(), list({binary(), plushie@node:prop_value()})} |
{load_font_message, binary(), bitstring()} |
{effect_request,
binary(),
binary(),
binary(),
gleam@dict:dict(binary(), plushie@node:prop_value())} |
{advance_frame, integer()}.
-file("src/plushie/command_encode.gleam", 206).
-spec classify_window(plushie@command:window_command()) -> wire_op(any()).
classify_window(Cmd) ->
case Cmd of
{close_window, Window_id} ->
{window_op, <<"close"/utf8>>, Window_id, []};
{resize_window, Window_id@1, Width, Height} ->
{window_op,
<<"resize"/utf8>>,
Window_id@1,
[{<<"width"/utf8>>, {float_val, Width}},
{<<"height"/utf8>>, {float_val, Height}}]};
{move_window, Window_id@2, X, Y} ->
{window_op,
<<"move"/utf8>>,
Window_id@2,
[{<<"x"/utf8>>, {float_val, X}}, {<<"y"/utf8>>, {float_val, Y}}]};
{maximize_window, Window_id@3, Maximized} ->
{window_op,
<<"maximize"/utf8>>,
Window_id@3,
[{<<"maximized"/utf8>>, {bool_val, Maximized}}]};
{minimize_window, Window_id@4, Minimized} ->
{window_op,
<<"minimize"/utf8>>,
Window_id@4,
[{<<"minimized"/utf8>>, {bool_val, Minimized}}]};
{set_window_mode, Window_id@5, Mode} ->
{window_op,
<<"set_mode"/utf8>>,
Window_id@5,
[{<<"mode"/utf8>>, {string_val, Mode}}]};
{toggle_maximize, Window_id@6} ->
{window_op, <<"toggle_maximize"/utf8>>, Window_id@6, []};
{toggle_decorations, Window_id@7} ->
{window_op, <<"toggle_decorations"/utf8>>, Window_id@7, []};
{focus_window, Window_id@8} ->
{window_op, <<"gain_focus"/utf8>>, Window_id@8, []};
{set_window_level, Window_id@9, Level} ->
{window_op,
<<"set_level"/utf8>>,
Window_id@9,
[{<<"level"/utf8>>, {string_val, Level}}]};
{drag_window, Window_id@10} ->
{window_op, <<"drag"/utf8>>, Window_id@10, []};
{drag_resize_window, Window_id@11, Direction} ->
{window_op,
<<"drag_resize"/utf8>>,
Window_id@11,
[{<<"direction"/utf8>>, {string_val, Direction}}]};
{request_user_attention, Window_id@12, Urgency} ->
Payload = case Urgency of
{some, U} ->
[{<<"urgency"/utf8>>, {string_val, U}}];
none ->
[]
end,
{window_op, <<"request_attention"/utf8>>, Window_id@12, Payload};
{screenshot, Window_id@13, Tag} ->
{window_op,
<<"screenshot"/utf8>>,
Window_id@13,
[{<<"tag"/utf8>>, {string_val, Tag}}]};
{set_resizable, Window_id@14, Resizable} ->
{window_op,
<<"set_resizable"/utf8>>,
Window_id@14,
[{<<"resizable"/utf8>>, {bool_val, Resizable}}]};
{set_min_size, Window_id@15, Width@1, Height@1} ->
{window_op,
<<"set_min_size"/utf8>>,
Window_id@15,
[{<<"width"/utf8>>, {float_val, Width@1}},
{<<"height"/utf8>>, {float_val, Height@1}}]};
{set_max_size, Window_id@16, Width@2, Height@2} ->
{window_op,
<<"set_max_size"/utf8>>,
Window_id@16,
[{<<"width"/utf8>>, {float_val, Width@2}},
{<<"height"/utf8>>, {float_val, Height@2}}]};
{enable_mouse_passthrough, Window_id@17} ->
{window_op,
<<"mouse_passthrough"/utf8>>,
Window_id@17,
[{<<"enabled"/utf8>>, {bool_val, true}}]};
{disable_mouse_passthrough, Window_id@18} ->
{window_op,
<<"mouse_passthrough"/utf8>>,
Window_id@18,
[{<<"enabled"/utf8>>, {bool_val, false}}]};
{show_system_menu, Window_id@19} ->
{window_op, <<"show_system_menu"/utf8>>, Window_id@19, []};
{set_resize_increments, Window_id@20, Width@3, Height@3} ->
Payload@1 = case {Width@3, Height@3} of
{{some, W}, {some, H}} ->
[{<<"width"/utf8>>, {float_val, W}},
{<<"height"/utf8>>, {float_val, H}}];
{{some, W@1}, none} ->
[{<<"width"/utf8>>, {float_val, W@1}}];
{none, {some, H@1}} ->
[{<<"height"/utf8>>, {float_val, H@1}}];
{none, none} ->
[]
end,
{window_op,
<<"set_resize_increments"/utf8>>,
Window_id@20,
Payload@1};
{set_icon, Window_id@21, Rgba_data, Width@4, Height@4} ->
{window_op,
<<"set_icon"/utf8>>,
Window_id@21,
[{<<"data"/utf8>>,
{string_val,
gleam_stdlib:base64_encode(Rgba_data, true)}},
{<<"width"/utf8>>, {int_val, Width@4}},
{<<"height"/utf8>>, {int_val, Height@4}}]};
{get_window_size, Window_id@22, Tag@1} ->
{window_query, <<"get_size"/utf8>>, Window_id@22, Tag@1};
{get_window_position, Window_id@23, Tag@2} ->
{window_query, <<"get_position"/utf8>>, Window_id@23, Tag@2};
{is_maximized, Window_id@24, Tag@3} ->
{window_query, <<"is_maximized"/utf8>>, Window_id@24, Tag@3};
{is_minimized, Window_id@25, Tag@4} ->
{window_query, <<"is_minimized"/utf8>>, Window_id@25, Tag@4};
{get_mode, Window_id@26, Tag@5} ->
{window_query, <<"get_mode"/utf8>>, Window_id@26, Tag@5};
{get_scale_factor, Window_id@27, Tag@6} ->
{window_query, <<"get_scale_factor"/utf8>>, Window_id@27, Tag@6};
{raw_window_id, Window_id@28, Tag@7} ->
{window_query, <<"raw_id"/utf8>>, Window_id@28, Tag@7};
{monitor_size, Window_id@29, Tag@8} ->
{window_query, <<"monitor_size"/utf8>>, Window_id@29, Tag@8}
end.
-file("src/plushie/command_encode.gleam", 304).
-spec classify_system(plushie@command:system_command()) -> wire_op(any()).
classify_system(Cmd) ->
case Cmd of
{allow_automatic_tabbing, Enabled} ->
{system_op,
<<"allow_automatic_tabbing"/utf8>>,
[{<<"enabled"/utf8>>, {bool_val, Enabled}}]};
{get_system_theme, Tag} ->
{system_query, <<"get_system_theme"/utf8>>, Tag};
{get_system_info, Tag@1} ->
{system_query, <<"get_system_info"/utf8>>, Tag@1}
end.
-file("src/plushie/command_encode.gleam", 315).
-spec classify_image(plushie@command:image_command()) -> wire_op(any()).
classify_image(Cmd) ->
case Cmd of
{create_image, Handle, Data} ->
{image_op,
<<"create_image"/utf8>>,
[{<<"handle"/utf8>>, {string_val, Handle}},
{<<"data"/utf8>>, {binary_val, Data}}]};
{create_image_rgba, Handle@1, Width, Height, Pixels} ->
{image_op,
<<"create_image"/utf8>>,
[{<<"handle"/utf8>>, {string_val, Handle@1}},
{<<"width"/utf8>>, {int_val, Width}},
{<<"height"/utf8>>, {int_val, Height}},
{<<"pixels"/utf8>>, {binary_val, Pixels}}]};
{update_image, Handle@2, Data@1} ->
{image_op,
<<"update_image"/utf8>>,
[{<<"handle"/utf8>>, {string_val, Handle@2}},
{<<"data"/utf8>>, {binary_val, Data@1}}]};
{update_image_rgba, Handle@3, Width@1, Height@1, Pixels@1} ->
{image_op,
<<"update_image"/utf8>>,
[{<<"handle"/utf8>>, {string_val, Handle@3}},
{<<"width"/utf8>>, {int_val, Width@1}},
{<<"height"/utf8>>, {int_val, Height@1}},
{<<"pixels"/utf8>>, {binary_val, Pixels@1}}]};
{delete_image, Handle@4} ->
{image_op,
<<"delete_image"/utf8>>,
[{<<"handle"/utf8>>, {string_val, Handle@4}}]};
{list_images, Tag} ->
{image_op, <<"list"/utf8>>, [{<<"tag"/utf8>>, {string_val, Tag}}]};
clear_images ->
{image_op, <<"clear"/utf8>>, []}
end.
-file("src/plushie/command_encode.gleam", 348).
-spec politeness_to_wire(plushie@command:politeness()) -> binary().
politeness_to_wire(Politeness) ->
case Politeness of
polite ->
<<"polite"/utf8>>;
assertive ->
<<"assertive"/utf8>>
end.
-file("src/plushie/command_encode.gleam", 88).
-spec classify_renderer(plushie@command:renderer_command()) -> wire_op(any()).
classify_renderer(Cmd) ->
case Cmd of
{focus, Widget_id} ->
{command, Widget_id, <<"focus"/utf8>>, maps:new()};
focus_next ->
{widget_op, <<"focus_next"/utf8>>, []};
focus_previous ->
{widget_op, <<"focus_previous"/utf8>>, []};
{focus_next_within, Scope} ->
{widget_op,
<<"focus_next_within"/utf8>>,
[{<<"scope"/utf8>>, {string_val, Scope}}]};
{focus_previous_within, Scope@1} ->
{widget_op,
<<"focus_previous_within"/utf8>>,
[{<<"scope"/utf8>>, {string_val, Scope@1}}]};
{select_all, Widget_id@1} ->
{command, Widget_id@1, <<"select_all"/utf8>>, maps:new()};
{move_cursor_to_front, Widget_id@2} ->
{command, Widget_id@2, <<"move_cursor_to_front"/utf8>>, maps:new()};
{move_cursor_to_end, Widget_id@3} ->
{command, Widget_id@3, <<"move_cursor_to_end"/utf8>>, maps:new()};
{move_cursor_to, Widget_id@4, Position} ->
{command,
Widget_id@4,
<<"move_cursor_to"/utf8>>,
maps:from_list([{<<"position"/utf8>>, {int_val, Position}}])};
{select_range, Widget_id@5, Start_pos, End_pos} ->
{command,
Widget_id@5,
<<"select_range"/utf8>>,
maps:from_list(
[{<<"start_pos"/utf8>>, {int_val, Start_pos}},
{<<"end_pos"/utf8>>, {int_val, End_pos}}]
)};
{scroll_to, Widget_id@6, X, Y} ->
{command,
Widget_id@6,
<<"scroll_to"/utf8>>,
maps:from_list(
[{<<"x"/utf8>>, {float_val, X}},
{<<"y"/utf8>>, {float_val, Y}}]
)};
{snap_to, Widget_id@7, X@1, Y@1} ->
{command,
Widget_id@7,
<<"snap_to"/utf8>>,
maps:from_list(
[{<<"x"/utf8>>, {float_val, X@1}},
{<<"y"/utf8>>, {float_val, Y@1}}]
)};
{snap_to_end, Widget_id@8} ->
{command, Widget_id@8, <<"snap_to_end"/utf8>>, maps:new()};
{scroll_by, Widget_id@9, X@2, Y@2} ->
{command,
Widget_id@9,
<<"scroll_by"/utf8>>,
maps:from_list(
[{<<"x"/utf8>>, {float_val, X@2}},
{<<"y"/utf8>>, {float_val, Y@2}}]
)};
{announce, Text, Politeness} ->
{widget_op,
<<"announce"/utf8>>,
[{<<"text"/utf8>>, {string_val, Text}},
{<<"politeness"/utf8>>,
{string_val, politeness_to_wire(Politeness)}}]};
{tree_hash_query, Tag} ->
{widget_op,
<<"tree_hash"/utf8>>,
[{<<"tag"/utf8>>, {string_val, Tag}}]};
{find_focused, Tag@1} ->
{widget_op,
<<"find_focused"/utf8>>,
[{<<"tag"/utf8>>, {string_val, Tag@1}}]};
{load_font, Family, Data} ->
{load_font_message, Family, Data};
{pane_split, Pane_grid_id, Pane_id, Axis, New_pane_id} ->
{command,
Pane_grid_id,
<<"pane_split"/utf8>>,
maps:from_list(
[{<<"pane"/utf8>>, {string_val, Pane_id}},
{<<"axis"/utf8>>, {string_val, Axis}},
{<<"new_pane_id"/utf8>>, {string_val, New_pane_id}}]
)};
{pane_close, Pane_grid_id@1, Pane_id@1} ->
{command,
Pane_grid_id@1,
<<"pane_close"/utf8>>,
maps:from_list([{<<"pane"/utf8>>, {string_val, Pane_id@1}}])};
{pane_swap, Pane_grid_id@2, Pane_a, Pane_b} ->
{command,
Pane_grid_id@2,
<<"pane_swap"/utf8>>,
maps:from_list(
[{<<"a"/utf8>>, {string_val, Pane_a}},
{<<"b"/utf8>>, {string_val, Pane_b}}]
)};
{pane_maximize, Pane_grid_id@3, Pane_id@2} ->
{command,
Pane_grid_id@3,
<<"pane_maximize"/utf8>>,
maps:from_list([{<<"pane"/utf8>>, {string_val, Pane_id@2}}])};
{pane_restore, Pane_grid_id@4} ->
{command, Pane_grid_id@4, <<"pane_restore"/utf8>>, maps:new()};
{window, Window_cmd} ->
classify_window(Window_cmd);
{system, System_cmd} ->
classify_system(System_cmd);
{image, Image_cmd} ->
classify_image(Image_cmd);
{effect, Id, Tag@2, Kind, Payload} ->
{effect_request, Id, Tag@2, Kind, Payload};
{native_command, Node_id, Op, Payload@1} ->
case plushie@command:is_valid_native_op(Op) of
true ->
{command, Node_id, Op, Payload@1};
false ->
no_op
end;
{native_commands, Commands} ->
case gleam@list:all(
Commands,
fun(Cmd@1) ->
plushie@command:is_valid_native_op(erlang:element(2, Cmd@1))
end
) of
true ->
{command_batch, Commands};
false ->
no_op
end;
{advance_frame, Timestamp} ->
{advance_frame, Timestamp}
end.
-file("src/plushie/command_encode.gleam", 74).
?DOC(
" Classify a command into a wire operation. All payload construction\n"
" happens here; the caller only needs to route the result to the\n"
" appropriate transport.\n"
).
-spec classify(plushie@command:command(JZU)) -> wire_op(JZU).
classify(Cmd) ->
case Cmd of
none ->
no_op;
exit ->
exit;
{batch, Commands} ->
{run_batch, Commands};
{done, Value, Mapper} ->
{done_immediate, Value, Mapper};
{send_after, Delay_ms, Msg} ->
{schedule_timer, Delay_ms, Msg};
{async, Work, Tag} ->
{spawn_async, Tag, Work};
{stream, Work@1, Tag@1} ->
{spawn_stream, Tag@1, Work@1};
{cancel, Tag@2} ->
{cancel_task, Tag@2};
{renderer, Renderer_cmd} ->
classify_renderer(Renderer_cmd)
end.