ElementTui

An Elixir library to create terminal user interfaces (tui), using termbox2 under the hood. Elementtui provides the basic building blocks for a TUI. There is a companion library available with more complicated components. Code examples are available in a separate repository.

Installation

The package can be installed by adding elementtui to your list of dependencies in mix.exs:

def deps do
  [
    {:elementtui, "~> 0.5"}
  ]
end

Usage

There are some simple examples available on codeberg that should help you get started. Also see the documentation on hexdocs.

Minimal hello world example:

ElementTui.run_loop(
  fn _, ev -> case ev do
      {:key,  _, _, ?q} ->
        # Exit the programme when q is pressed
        {:halt, nil}

      _ ->
        ElementTui.Element.text("Hello World")
        |> ElementTui.render(5, 5, 100, 1)

        ElementTui.present()

        {:cont, nil}
    end
  end,
  nil,
  timeout: 1000
)

Note that when starting your own project you need to make sure elixir/erlang does not listen for input, by setting -noinput in the mix.exs file.

Two panels with a dividing line:

ElementTui.run_loop(
  fn _, ev -> case ev do
      {:key,  _, _, ?q} ->
        # Exit the programme when q is pressed
        {:halt, nil}

      _ ->
        [
          Element.text("Text in pane 1") |> Element.wrap() |> Element.flex(:horizontal),
          Element.text("Text in pane 2") |> Element.wrap() |> Element.flex(:horizontal)
        ]
        # Dividing line
        |> Enum.intersperse(Element.text("┃") |> Element.vfill())
        |> Element.hbox()
        |> ElementTui.render(0, 0, ElementTui.width(), ElementTui.height())

        ElementTui.present()

        {:cont, nil}
    end
  end,
  nil,
  timeout: 1000
)

Examples

For the code to create these examples see codeberg/elementtui_examples

Performance example

performance

Popup example

popup

Component example

Example of the tab and xygraph components. See the examples repository for the code.

component

Rtttex

rtttex is a full fledged tui build using the elementtui library.