README.md

# ElementTui

An Elixir library to create terminal user interfaces (tui), using [termbox2](https://github.com/termbox/termbox2) under the hood. Current functionality was build to support [rtttex](https://codeberg.org/edwinvanl/rtttex), but I am happy with the base functionality and open to merge requests to improve and expand it.

## Installation

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

```elixir
def deps do
  [
    {:elementtui, "~> 0.4"}
  ]
end
```

## Usage

There are some simple examples available on [codeberg](https://codeberg.org/edwinvanl/elementtui_examples) that should help you get started. Also see the documentation on [hexdocs](https://hexdocs.pm/elementtui/api-reference.html).

Minimal `hello world` example:

```elixir
ElementTui.run_loop(
  fn _, ev ->
    case ev do
      {:key,  _, _, ?q} ->
        {: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](https://codeberg.org/edwinvanl/elementtui_examples/src/branch/main/mix.exs#L14) in the `mix.exs` file. 

## Examples

For the code to create these examples see [codeberg/elementtui_examples](https://codeberg.org/edwinvanl/elementtui_examples)

### Performance example 

![performance](https://codeberg.org/edwinvanl/elementtui/wiki/raw/uploads/performance.gif)

### Popup example

![popup](https://codeberg.org/edwinvanl/elementtui/wiki/raw/uploads/c95e9becc78aff37ec867ad64925082d/popup.gif)