summaryrefslogtreecommitdiffstats
path: root/src/core/ephraim_gui.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/ephraim_gui.erl')
-rw-r--r--src/core/ephraim_gui.erl28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/core/ephraim_gui.erl b/src/core/ephraim_gui.erl
new file mode 100644
index 0000000..79433e0
--- /dev/null
+++ b/src/core/ephraim_gui.erl
@@ -0,0 +1,28 @@
+-module(ephraim_gui).
+-compile([debug_info, export_all]).
+
+-spec init() -> ok.
+init() ->
+ Port = open_port({spawn_executable, "ephraim-gtk"}, [binary, nouse_stdio, {packet, 4}]),
+ ephraim ! {register_ui, self()},
+ loop(Port),
+ ephraim ! {unregister_ui, self()}.
+
+-spec loop(port()) -> ok.
+loop(Port) ->
+ receive
+ stop ->
+ ok;
+ {Port, {data, Data}} ->
+ Msg = binary_to_term(Data),
+ case Msg of
+ stop ->
+ ok;
+ _ ->
+ ephraim ! Msg,
+ loop(Port)
+ end;
+ Msg ->
+ Port ! {self(), {command, term_to_binary(Msg)}},
+ loop(Port)
+ end.