Zenity GUI for Elixir

Zenity GUI for Elixir

So I've recently switched to using Elixir as my main development platform.
One drawback of Elixir/Erlang is that it doesn't have any GUI(General User interface).

Yes, it's easy - even required - to use cowboy + plug or Phoenix to make a browser based (HTML, CSS and JavaScript) interface that works great across all devices.
But what when you want to interact with the user directly without the extra overhead?

Well, you can make bindings to GTK+, TK or QT! Search for a library that uses those and use it.

But why not something simple?

You can use Zenity for simple interactions. It works on Linux, there is a port for Windows and one for MacOsX.

You can usually find it in the package manager.

Sample Zenity module

defmodule Zenity do

@zenity "/usr/bin/zenity"

  def entry(text,entry_text \\ "") do
    exec @zenity, ["--entry", "--text",text, "--entry-text",entry_text]
  end

  def exec(exe, args) when is_list(args) do
    port = Port.open({:spawn_executable, exe}, [{:args, args} , :stream, :binary, :exit_status, :hide, :use_stdio, :stderr_to_stdout])
    handle_output(port)
  end

  def handle_output(port, data \\"") do
    receive do
      {^port, {:data, data}} ->
        handle_output(port,data)
      {^port, {:exit_status, status}} ->
        {data, status}

    end
  end
end

 

Usage Example

Official documentation:

I have compiled a few links with official documentation and examples.
https://help.gnome.org/users/zenity/3.22/
More examples:
http://linux.byexamples.com/archives/259/a-complete-zenity-dialog-examples-1/
https://www.linux.org/threads/zenity-gui-for-shell-scripts.9802/
https://linuxaria.com/howto/introduction-zenity-bash-gu

Conclusion

Zenity is worthy of usage within Elixir in the creation of user oriented scripts. And it works great in prototyping new apps.
It can do many things. For more advanced experiments and real software, consider using Phoenix in the browser.

You might enjoy these similar articles:

Be the first to comment!

Add a new comment

All comments are moderated and must adhere to the terms of service.

Subscribe to my awesome newsletter!








What to expect: Ultimate Knowledge regarding Business Efficiency, Personalized Marketing Experience, Software Development and Cyber Security tips and tricks. 1-3 mails per month. Unsubscribe any time. See the privacy policy to learn how we take care of your information.