TERMBOX2-NIF

ContributorsForksIssuesHex.pm VersionLicense


About The Project

A modern, cross-platform BEAM (Erlang/Elixir/Gleam) wrapper for the termbox2 terminal UI library.

Published on Hex.pm:https://hex.pm/packages/termbox2_nif

Note: The repository name was changed because the original "termbox2" name was already taken by the upstream C project. This package provides BEAM/Elixir/Erlang/Gleam bindings for termbox2, not the original C library itself.


Table of Contents


Getting Started

Prerequisites

Installation

Erlang

Add to your rebar.config:

{deps, [
  {termbox2_nif, {path, "termbox2_nif"}}
]}.

Fetch and compile:

rebar3 get-deps
rebar3 compile

Elixir

See wrappers/elixir/README.md for full instructions.

Gleam

See wrappers/gleam/README.md for full instructions.


Usage

Erlang Quickstart

%% Define default attributes (foreground/background)
-define(TB_DEFAULT, 0).

ok = termbox2_nif:tb_init(),
ok = termbox2_nif:tb_clear(),
Str = "Hello, termbox!",
X = 1, Y = 1,
Fg = ?TB_DEFAULT, Bg = ?TB_DEFAULT,
ok = termbox2_nif:tb_print(X, Y, Fg, Bg, Str),
ok = termbox2_nif:tb_present(),
{ok, _Type, _Mod, _KeyOrChar} = termbox2_nif:tb_poll_event(),
ok = termbox2_nif:tb_shutdown().

Elixir Quickstart

# In your mix.exs, add:
# {:termbox2, path: "wrappers/elixir"}, {:termbox2_nif, "~> 2.0.0"}

:ok = Termbox2.init()
:ok = Termbox2.set_cell(0, 0, ?A, :red, :default)
:ok = Termbox2.present()
:ok = Termbox2.shutdown()

Gleam Quickstart

import termbox2_gleam
import termbox2_gleam.{Red, Default, set_cell_friendly, print_friendly}

pub fn main() {
  case termbox2_gleam.init() {
    Ok(_) -> {
      set_cell_friendly(0, 0, 65, Red, Default)
      print_friendly(1, 1, Red, Default, "Hello, world!")
      termbox2_gleam.present()
      termbox2_gleam.shutdown()
    }
    Error(e) -> {
      io.println("Failed to initialize termbox2: " <> e)
    }
  }
}

Testing & NIF Loading

If you encounter NIF loading errors, ensure you have built the project from the root using the Makefile or wrapper-specific instructions.


Advanced/Wrapper-Specific Docs


Roadmap

See open issues for a full list of proposed features and known issues.


License

Distributed under the MIT License. See LICENSE for more information.


Wrappers Summary

NIF binary: built to termbox2_nif/priv/. Wrappers symlink/copy from here as needed.

Build all: make build-all (see Makefile for details)