Termbox is a library that provides minimalistic API which allows the programmer to write text-based user interfaces.

Related tags

GUI termbox
Overview

IMPORTANT

This library is no longer maintained. It's pretty small if you have a big project that relies on it, just maintain it yourself. Or look for forks. Or look for alternatives. Or better - avoid using terminals for UI. Never the less, thanks to all who ever contributed.

Termbox

Termbox is a library that provides minimalistic API which allows the programmer to write text-based user interfaces.

It is based on a very simple abstraction. The main idea is viewing terminals as a table of fixed-size cells and input being a stream of structured messages. Would be fair to say that the model is inspired by windows console API. The abstraction itself is not perfect and it may create problems in certain areas. The most sensitive ones are copy & pasting and wide characters (mostly Chinese, Japanese, Korean (CJK) characters). When it comes to copy & pasting, the notion of cells is not really compatible with the idea of text. And CJK runes often require more than one cell to display them nicely. Despite the mentioned flaws, using such a simple model brings benefits in a form of simplicity. And KISS principle is important.

At this point one should realize, that CLI (command-line interfaces) aren't really a thing termbox is aimed at. But rather pseudo-graphical user interfaces.

Installation

Termbox comes with a waf-based build scripts. In order to configure, build and install it, do the following::

./waf configure --prefix=/usr                                (configure)
./waf                                                        (build)
./waf install --destdir=DESTDIR                              (install)

By default termbox will install the header file and both shared and static libraries. If you want to install a shared library or static library alone, use the following as an install command::

./waf install --targets=termbox_shared --destdir=PREFIX      (shared library)

or::

./waf install --targets=termbox_static --destdir=PREFIX      (static library)
Python

In order to install the python module, use the following command (as root or via sudo)::

python setup.py install

for Python 3::

python3 setup.py install

Getting started

Termbox's interface only consists of 12 functions::

tb_init() // initialization
tb_shutdown() // shutdown

tb_width() // width of the terminal screen
tb_height() // height of the terminal screen

tb_clear() // clear buffer
tb_present() // sync internal buffer with terminal

tb_put_cell()
tb_change_cell()
tb_blit() // drawing functions

tb_select_input_mode() // change input mode
tb_peek_event() // peek a keyboard event
tb_poll_event() // wait for a keyboard event

See src/termbox.h header file for full detail.

Links

If you want me to add your Termbox project here, send me a pull request or drop a note via email, you can find my email below.

Language bindings
Other implementations
Applications

Bugs & questions

Report bugs to the https://github.com/nsf/termbox issue tracker. Send rants and questions to me: [email protected].

Changes

v1.1.2:

  • Properly include changelog into the tagged version commit. I.e. I messed up by tagging v1.1.1 and describing it in changelog after tagged commit. This commit marked as v1.1.2 includes changelog for both v1.1.1 and v1.1.2. There are no code changes in this minor release.

v1.1.1:

v1.1.0:

  • API: tb_width() and tb_height() are guaranteed to be negative if the termbox wasn't initialized.
  • API: Output mode switching is now possible, adds 256-color and grayscale color modes.
  • API: Better tb_blit() function. Thanks, Gunnar Zötl [email protected].
  • API: New tb_cell_buffer() function for direct back buffer access.
  • API: Add new init function variants which allow using arbitrary file descriptor as a terminal.
  • Improvements in input handling code.
  • Calling tb_shutdown() twice is detected and results in abort() to discourage doing so.
  • Mouse event handling is ported from termbox-go.
  • Paint demo port from termbox-go to demonstrate mouse handling capabilities.
  • Bug fixes in code and documentation.

v1.0.0:

  • Remove the Go directory. People generally know about termbox-go and where to look for it.
  • Remove old terminfo-related python scripts and backport the new one from termbox-go.
  • Remove cmake/make-based build scripts, use waf.
  • Add a simple terminfo database parser. Now termbox prefers using the terminfo database if it can be found. Otherwise it still has a fallback built-in database for most popular terminals.
  • Some internal code cleanups and refactorings. The most important change is that termbox doesn't leak meaningless exported symbols like 'keys' and 'funcs' now. Only the ones that have 'tb_' as a prefix are being exported.
  • API: Remove unsigned ints, use plain ints instead.
  • API: Rename UTF-8 functions 'utf8_' -> 'tb_utf8_'.
  • API: TB_DEFAULT equals 0 now, it means you can use attributes alones assuming the default color.
  • API: Add TB_REVERSE.
  • API: Add TB_INPUT_CURRENT.
  • Move python module to its own directory and update it due to changes in the termbox library.
Comments
  • Documentation of C functions missing

    Documentation of C functions missing

    Maybe I simply don’t see it, but there is no function documentation in the C headers and hardly any comments in the source files.

    The Python bindings are documented, though.

    How come?

    opened by Profpatsch 25
  • keyboard input broken on OSX Terminal

    keyboard input broken on OSX Terminal

    Hi,

    I ran into some other problems, this time the wait_fill_event() function would hang on a keypress. Window resize worked fine. I traced the problem to fread() in termbox.c on line 428. It would always return 0 and control would jump back to while(1), going on forever. Turns out, some previous operation on *in descriptor had caused an EOF error and therefor all subsequent freads fail. Placing clearerr(in) before fread() solved the problem for me.

    G.

    opened by guncha 18
  • Add CMake build option and include it in the readme

    Add CMake build option and include it in the readme

    Some people probably want to use CMake to include termbox in their project. Waf is also not used a lot throughout the C/C++ community, but I'm leaving that as is.

    opened by rikvdh 12
  • Crash on terminal resize when waiting for events.

    Crash on terminal resize when waiting for events.

    I'm not sure precisely what's going on, though I've managed to narrow it down to what I believe to be the smallest crashing piece of code (if it was real code I'd probably issue a close() at the end, but it never gets there anyway in this demonstration).

    If I run the following script:

    import termbox
    
    tb = termbox.Termbox()
    
    while True:
        tb.poll_event()
    

    and then attempt to resize my terminal (both when resizing panes in tmux and resizing an xterm that it's running directly under), more often than not python will abort, simply dumping out this message:

    python3.2: src/termbox.c:521: wait_fill_event: Assertion `r > 0' failed.
    

    This also happens when using peek_event, and does not seem to be affected by the timeout passed to peek_event. It does not occur on key events, at least so far as I can tell.

    As I said before, I'm really not sure what's going on here, and I don't imagine what I've got so far is all that helpful, so any advice on how to get a more useful crash dump would be much appreciated.

    opened by jesskay 10
  • Pressing ESC after setting the mode to TB_MOUSE_INPUT triggers assertion error

    Pressing ESC after setting the mode to TB_MOUSE_INPUT triggers assertion error

    It triggers this assertion.

    The program is:

    #include "termbox.h"
    
    int main(int argc, char **argv) {
        tb_init();
        tb_select_input_mode(TB_INPUT_MOUSE);
    
        struct tb_event ev;
        tb_poll_event(&ev);
    
        tb_shutdown();
        return 0;
    }
    

    See also: gchp/rustbox#32

    Bug 
    opened by sru 9
  • Replace waf with Makefile

    Replace waf with Makefile

    Using Python to build a C library seems a bit... odd. Makefiles have been around for decades, and work perfectly for both small and large projects.

    Makefiles have the advantage of being ubiquitous across UNIX-like systems. Anyone with a C compiler will have make, but a lot of people with C compilers won't have Python, and many of those won't want to install it just to build a single library.

    Portability aside, Makefiles are a lot easier for contributors as well as for people who just want to use the library. Almost everyone who knows C can write, or at least understand, a Makefile, making it easier to contribute to projects that use them.


    I removed the src and build directories because the root of the repo felt a bit empty with only src, README.rst and COPYING. It's easy enough to add them back in if necessary though, so let me know.

    This also resolves issue #93, partly because I wanted to remove all Python code from the repo and partly because I couldn't be bothered to work out how the wrapper is generated and integrate that into the Makefile. Let me know if you'd prefer to keep it in and I'll see what I can do.

    opened by silversquirl 7
  • Cygwin peek/poll_event asserts wait_fill_event first read

    Cygwin peek/poll_event asserts wait_fill_event first read

    Using the same sequence of steps as keyboard.c, I get an assert in the very first block of reading code of wait_fill_event (currently line 581).

    I'm using the latest 32-bit Cygwin on Win7/64. Since I'm using CMake I made a static library for termbox.c and utf8.c to live in.

    I tried disabling the initial reading section of wait_fill_event, and that worked, until a resize occurred. Upon resizing the block of reading code in the while loop (currently line 613) would assert on errno==EAGAIN.

    opened by cardiffman 7
  • no mouse events in xterm and xfce4-terminal

    no mouse events in xterm and xfce4-terminal

    Using the termbox keyboard demo. The mouse events are reported as keyboard events, the reported key values appear to be random. Also, in xterm the box drawing characters are drawn as â.

    Arch Linux, xterm 325, xfce4-terminal 0.6.3, termbox trunk, $TERM = xterm

    opened by maep-- 6
  • "cygwin" terminal support

    Steps to reproduce:

    1. From cygwin, ssh to a linux machine.
    2. ./keyboard tb_init() failed with error code -1

    Note in this scenario $TERM == "cygwin".

    opened by thejoshwolfe 6
  • Handle NUL code point in tb_utf8_unicode_to_char.

    Handle NUL code point in tb_utf8_unicode_to_char.

    This is a bit semantic, but assuming the return value of tb_utf8_unicode_to_char is supposed to represent the length (as in strlen) of the resulting UTF-8 string out, a NUL code point should result in a 0-length string, not 1-length.

    opened by adsr 5
  • invalid pointer in tb_shutdown()

    invalid pointer in tb_shutdown()

    *** Error in `/home/lukas/Hacking/c/tinyrl/bin/tinyrl': munmap_chunk(): invalid pointer: 0x0000000000607f80 ***
    ^[[C======= Backtrace: =========
    /usr/lib/libc.so.6(+0x732ae)[0x7ffff77a62ae]
    /usr/lib/libc.so.6(+0x7872e)[0x7ffff77ab72e]
    /home/lukas/Hacking/c/tinyrl/bin/tinyrl[0x402c88]
    /home/lukas/Hacking/c/tinyrl/bin/tinyrl[0x4032f3]
    /home/lukas/Hacking/c/tinyrl/bin/tinyrl[0x4021bc]
    /usr/lib/libc.so.6(__libc_start_main+0xf0)[0x7ffff7753040]
    /home/lukas/Hacking/c/tinyrl/bin/tinyrl[0x400e59]
    ======= Memory map: ========
    00400000-00406000 r-xp 00000000 fe:03 3932165                            /home/lukas/Hacking/c/tinyrl/bin/tinyrl
    00606000-00607000 rw-p 00006000 fe:03 3932165                            /home/lukas/Hacking/c/tinyrl/bin/tinyrl
    00607000-00676000 rw-p 00000000 00:00 0                                  [heap]
    7ffff751d000-7ffff7533000 r-xp 00000000 fe:04 13590                      /usr/lib/libgcc_s.so.1
    7ffff7533000-7ffff7732000 ---p 00016000 fe:04 13590                      /usr/lib/libgcc_s.so.1
    7ffff7732000-7ffff7733000 rw-p 00015000 fe:04 13590                      /usr/lib/libgcc_s.so.1
    7ffff7733000-7ffff78cc000 r-xp 00000000 fe:04 13264                      /usr/lib/libc-2.20.so
    7ffff78cc000-7ffff7acc000 ---p 00199000 fe:04 13264                      /usr/lib/libc-2.20.so
    7ffff7acc000-7ffff7ad0000 r--p 00199000 fe:04 13264                      /usr/lib/libc-2.20.so
    7ffff7ad0000-7ffff7ad2000 rw-p 0019d000 fe:04 13264                      /usr/lib/libc-2.20.so
    7ffff7ad2000-7ffff7ad6000 rw-p 00000000 00:00 0 
    7ffff7ad6000-7ffff7bd9000 r-xp 00000000 fe:04 13263                      /usr/lib/libm-2.20.so
    7ffff7bd9000-7ffff7dd9000 ---p 00103000 fe:04 13263                      /usr/lib/libm-2.20.so
    7ffff7dd9000-7ffff7dda000 r--p 00103000 fe:04 13263                      /usr/lib/libm-2.20.so
    7ffff7dda000-7ffff7ddb000 rw-p 00104000 fe:04 13263                      /usr/lib/libm-2.20.so
    7ffff7ddb000-7ffff7dfd000 r-xp 00000000 fe:04 13237                      /usr/lib/ld-2.20.so
    7ffff7ff3000-7ffff7ff8000 rw-p 00000000 00:00 0 
    7ffff7ff8000-7ffff7ffa000 r--p 00000000 00:00 0                          [vvar]
    7ffff7ffa000-7ffff7ffc000 r-xp 00000000 00:00 0                          [vdso]
    7ffff7ffc000-7ffff7ffd000 r--p 00021000 fe:04 13237                      /usr/lib/ld-2.20.so
    7ffff7ffd000-7ffff7ffe000 rw-p 00022000 fe:04 13237                      /usr/lib/ld-2.20.so
    7ffff7ffe000-7ffff7fff000 rw-p 00000000 00:00 0 
    7ffffffde000-7ffffffff000 rw-p 00000000 00:00 0                          [stack]
    ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
    

    I recently experienced this strange error when my program quitted. It is related to tb_shutdown() as I found out by using valgrind: valgrind error. I don't have any idea how to fix this yet.

    opened by sternenseemann 5
  • tb_peek_event() buffers inputs with sleep_for() c++11

    tb_peek_event() buffers inputs with sleep_for() c++11

    I'm not sure if this behavior of tb_peek_event() is intentional or not. I encountered it while attempting to make Tetris using termbox and trying to implement a time function and any inputs would stack rather than update on loop.

    It can be replicated like this:

    simply hold space and release when it shows 1.

    #include <termbox.h> #include <thread> #include <chrono> int main(void) { int i; tb_init(); tb_cell c = {}; tb_event e = {}; while(i < 4) { tb_clear(); std::this_thread::sleep_for(std::chrono::milliseconds(2000)); tb_peek_event(&e, 0); if(e.key == TB_KEY_SPACE) { i++; } c.ch = 48 + i; tb_put_cell(0,0,&c); tb_present(); } tb_shutdown(); return(0); }

    opened by Mutaru16bit 1
  • Allow reading the front buffer?

    Allow reading the front buffer?

    Feature request/idea: reading the front buffer

    A function like tb_cell_buffer for the front buffer would be nice to have. I realize it comes with some amount of risk. If there is interest, I'd be happy to prototype something.

    My use case is below, but I think this could be helpful in a more generic sense:

    I've made a mini termbox based window manager of sorts and would like to implement some type of modal functionality. I'd like to be able to push the contents of the front buffer on a stack, show a modal, and then display the previous front buffer again after the modal is closed.

    Since each section of my terminal is managed by an arbitrary number of window objects, it is impractical and inefficient to track their states manually.

    opened by josharenson 0
  • Are extended terminfo files being correctly parsed?

    Are extended terminfo files being correctly parsed?

    Code contains #define TI_ALT_MAGIC 542, which is the alternative header for terminfo "extended storage format". This is ultimately used to correctly calculate the strings offset into the compiled terminfo database.

    However, term(5) states that the alt magic is 0542, which is octal. TI_ALT_MAGIC should be set to (int)354, or prefixed with a zero.

    I don't have any extended storage format terminfo files handy, but I am happy to test if you point me to where I can get some.

    opened by mlabbe 2
  • Documentation of the API could be more helpful

    Documentation of the API could be more helpful

    The README says "Termbox's interface only consists of 12 functions", which is not really accurate (there's 21 functions), and lists just the function names. I think it would be helpful to give argument names (e.g. tb_change_cell(x, y, ch, fg, bg) instead of just tb_change_cell()) and either list all 21 functions, or explicitly say that the listed functions are only the most commonly used ones, but the API has a some other functions too.

    opened by bruce-hill 1
  • Add tb_poll_fds() to obtain file descriptors for polling

    Add tb_poll_fds() to obtain file descriptors for polling

    This adds a function to obtain file descriptors from termbox that can be be polled for IO-readiness. This can be used to integrate termbox into an event loop like asyncio or curio in python, or libuv in C, so the program can process other things (like network sockets) asynchronously with UI events.

    The idea is to use tb_poll_fds() to get a set of descriptors, register them for polling (e.g. with EPOLLIN), and when any events arrive, the next tb_poll_event() can be expected to complete quickly.

    (edit: markdown formatting and C usage example)

    opened by tobyp 2
SixtyFPS is a toolkit to efficiently develop fluid graphical user interfaces for any display: embedded devices and desktop applications. We support multiple programming languages, such as Rust, C++ or JavaScript.

SixtyFPS is a toolkit to efficiently develop fluid graphical user interfaces for any display: embedded devices and desktop applications. We support multiple programming languages, such as Rust, C++ or JavaScript.

SixtyFPS 5.5k Jan 1, 2023
A simple Iced application that I wrote as a learning activity, which allows you to browse the full list of regular Material Icons.

Iced Material Icon Browser Iced Material Icon Browser is a simple Iced application that I wrote as a learning activity, which allows you to browse the

BB-301 4 Sep 18, 2023
Minimalistic volume mixer.

Mixxc Mixxc is a minimalistic and customizable volume mixer, created to seamlessly complement desktop widgets. Currently, it supports only pulseaudio

null 4 Oct 23, 2023
write your next slideshow in rust 🦀, as a self-contained binary 📦.

?? bema Write your next slideshow in rust ?? , as a self-contained binary ?? . ?? DSL See examples/basic.rs. ?? frontends There are several ways you c

Olivier Abdesselam 21 Sep 5, 2022
Write and render svg-animations with Rust ✨

rusvid Write and render svg-animations with Rust ✨ (no gui or cli, under active development) Dependencies Ffmpeg in path rustc 1.63.0-nightly Simple u

Domenic Melcher 2 Jul 17, 2022
This is a demo Library of fltk-rs, which is used to learn various new gadgets of experimental fltk-rs.

fltk-rs Demo This is a demo Library of fltk-rs, which is used to learn various new gadgets of experimental fltk-rs. Demos demo9 Demo9 is an applicatio

WumaCoder 6 Dec 28, 2022
Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies

Dear ImGui (This library is available under a free and permissive license, but needs financial support to sustain its continued improvements. In addit

omar 44.4k Jan 5, 2023
A graphical user interface toolkit for audio plugins.

HexoTK - A graphic user interface toolkit for audio plugins State of Development Super early! Building cargo run --example demo TODO / Features Every

Weird Constructor 14 Oct 20, 2022
Provides Rust bindings for GTK libraries

The gtk-rs organization aims to provide safe Rust binding over GObject-based libraries

null 431 Dec 30, 2022
Provides Rust bindings for Gnome libraries

gtk-rs-core The gtk-rs organization aims to provide safe Rust binding over GObject-based libraries. You can find more about it on https://gtk-rs.org.

null 174 Dec 26, 2022
A tongue-in-cheek GUI that provides similar functionality to GNU cat

catboy a tongue-in-cheek GUI that provides similar functionality to GNU cat information: Attribute Value Development Status: Active Neglect Price: I h

toasterrepairman 2 Feb 9, 2022
Provides Rust bindings for GTK libraries

gtk3-rs The gtk-rs organization aims to provide safe Rust binding over GObject-based libraries. You can find more about it on https://gtk-rs.org. This

null 431 Dec 30, 2022
Provides core language-agnostic functionality for LiveView Native across platforms

LiveView Native Core This repository contains an implementation of the LiveView Native core library, which is intended to handle all the details which

LiveView Native 35 Dec 27, 2022
Provides event handling for egui in SDL2 window applications.

egui-sdl2-event Provides event handling for egui when SDL2 is used as the windowing system. This crate does not perform any rendering, but it can be c

Valtteri Vallius 8 Feb 15, 2023
A tray icon to uwuify your text

uwu-tray fastest uwuifier in the west... now in your system tray for even faster uwufication! FAQ Which platforms are supported? Windows Linux MacOS H

Catherine Gilbert 29 Dec 10, 2022
Simple GTK Rust Fuzzer which aims to test all available classes and functions in GTK.

Gtk Rust Fuzzer Simple GTK Rust Fuzzer which aims to test all available classes and functions in GTK. It finds bugs inside GTK functions, GTK exported

Rafał Mikrut 8 Nov 19, 2022
Idiomatic, GTK+-based, GUI library, inspired by Elm, written in Rust

Relm Asynchronous, GTK+-based, GUI library, inspired by Elm, written in Rust. This library is in beta stage: it has not been thoroughly tested and its

null 2.2k Dec 31, 2022
An idiomatic GUI library inspired by Elm and based on gtk4-rs

An idiomatic GUI library inspired by Elm and based on gtk4-rs. Relm4 is a new version of relm that's built from scratch and is compatible with GTK4 an

Aaron Erhardt 722 Dec 31, 2022
A fast, zbus-based, permissively licensed AT-SPI library written in pure Rust!

AT-SPI for Rust Higher level, asynchronous Rust bindings to AT-SPI2, using zbus. Part of the Odilia screen reader project. Design Fully documented, wi

Odilia 12 Dec 31, 2022