ElementTui: an Elixir library to create terminal user interfaces (tui).
Find a file
Edwin van Leeuwen 9111dd7cbd
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Merge tag 'v0.5.1' into develop
0.5.1

- Add component protocol
- Various bug fixes
2024-10-30 20:01:59 +00:00
config ci: Don't start the application (genserver) when running tests 2024-08-20 15:40:33 +00:00
lib feat: Rename expand to the more appropriate flex 2024-10-06 07:24:41 +01:00
src input: Support adding a cursor to text 2024-06-05 06:23:17 +00:00
test feat: Rename expand to the more appropriate flex 2024-10-06 07:24:41 +01:00
.formatter.exs tui: Move the library to a separate repository and commit 2024-04-11 16:43:54 +00:00
.gitignore git: Remove mix.lock from git 2024-05-19 08:13:56 +01:00
.woodpecker.yaml ci: Remove whitespace 2024-10-30 19:57:11 +00:00
LICENSE Add LICENSE 2024-04-11 16:46:36 +00:00
Makefile release: Version bump 2024-05-19 07:57:29 +01:00
mix.exs release: Update version number 2024-10-30 20:01:28 +00:00
README.md doc: Small clarification in the README 2024-10-30 19:44:35 +00:00

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.