Git Product home page Git Product logo

termbox's Introduction

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.

termbox's People

Contributors

adsr avatar bmsauer avatar cellularmitosis avatar dcat avatar ei-grad avatar galdor avatar george-b avatar jonasp avatar klardotsh avatar kropelka avatar luxint avatar nsf avatar osa1 avatar robem avatar rodrigues avatar rofl0r avatar sgbeal avatar shayneoatnorwood avatar sru avatar ssharunas avatar stites avatar svenstaro avatar talanis85 avatar techtonik avatar thinkyfish avatar tzador avatar utkarshkukreti avatar voker57 avatar weqqr avatar zyedidia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

termbox's Issues

npm install needs to be tweaked?

$ gcc --version
gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2

$ uname -a
Linux kiwi 3.18.7-rt1 #1 SMP PREEMPT RT Mon Feb 23 07:43:39 CET 2015 x86_64 x86_64 x86_64 GNU/Linux

$ cat /etc/issue
Ubuntu 14.04.1 LTS \n \l

$ npm --version
1.4.3

$ node --version
v0.10.26

$ npm install termbox
npm http GET https://registry.npmjs.org/termbox
npm http 200 https://registry.npmjs.org/termbox
npm http GET https://registry.npmjs.org/termbox/-/termbox-0.1.0.tgz
npm http 200 https://registry.npmjs.org/termbox/-/termbox-0.1.0.tgz

> [email protected] install /tmp/node_modules/termbox
> node-gyp rebuild

make: Entering directory `/tmp/node_modules/termbox/build'
  CXX(target) Release/obj.target/termbox/src/termbox.o
../src/termbox.cpp:13:21: fatal error: termbox.h: No such file or directory
 #include <termbox.h>
                     ^
compilation terminated.
make: *** [Release/obj.target/termbox/src/termbox.o] Error 1
make: Leaving directory `/tmp/node_modules/termbox/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/mnt/data/opt/node-v0.10.26-linux-x64/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:267:23)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:797:12)
gyp ERR! System Linux 3.18.7-rt1
gyp ERR! command "node" "/mnt/data/opt/node-v0.10.26-linux-x64/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /tmp/node_modules/termbox
gyp ERR! node -v v0.10.26
gyp ERR! node-gyp -v v0.12.2
gyp ERR! not ok 
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the termbox package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls termbox
npm ERR! There is likely additional logging output above.

npm ERR! System Linux 3.18.7-rt1
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" "termbox"
npm ERR! cwd /tmp
npm ERR! node -v v0.10.26
npm ERR! npm -v 1.4.3
npm ERR! code ELIFECYCLE
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /tmp/npm-debug.log
npm ERR! not ok code 0

Please add 'gnu_dirs' support

We need to be able to use --libdir option to waf configure.

In wscript, please add

--- wscript.rpm 2014-09-12 08:37:18.266568098 +0200
+++ wscript 2014-09-12 08:37:23.268590579 +0200
@@ -7,6 +7,7 @@
 import sys

 def options(opt):
+   opt.load('gnu_dirs')
    opt.load('compiler_c')
    opt.add_option(
        '--debug',
@@ -17,6 +18,7 @@

 def configure(conf):
    conf.env.VERSION = VERSION
+   conf.load('gnu_dirs')
    conf.load('compiler_c')
    conf.env.append_unique('CFLAGS', ['-std=gnu99', '-Wall', '-Wextra'])
    if conf.options.debug:

[python] 'termbox.Termbox' object has no attribute '_poll_lock'

Is something broken in current master?

ei-grad@ei-grad ~ » pytbclock
Traceback (most recent call last):
  File "/usr/bin/pytbclock", line 123, in <module>
    Clock().run()
  File "/usr/bin/pytbclock", line 100, in run
    with termbox.Termbox() as tb:
  File "termboxmodule.pyx", line 145, in termbox.Termbox.__cinit__ (src/termboxmodule.c:1064)
AttributeError: 'termbox.Termbox' object has no attribute '_poll_lock'

test script has wrong tuple

line 108 of test_termboxmodule.py reads

(type, ch, key, mod, w, h) = event_here

however is should be

(typee, char, key, mod, width, height, mousex, mousey) = event_here

because event_here is returned by t.poll_event() which in the most recent sources returns an length 8 tuple (the extra two being the mouse coordinates)

Allow clearing of text attributes

Output can be printed with a set foreground and background, but text attributes cannot be reset.

For example, if I did this:

>>> print "\033[34;41mHello\033[0m Hello"
Hello World

The word hello would be printed in blue on red, same as you would by printing 'Hello' using

terminal.change_cell(x, y, ord(u'H'), termbox.Blue, termbox.RED)

However the word 'World' would be printed without any text attributes, and the terminal would display it with it's own foreground and background colors. (Some terminals use a no background color as the default, allowing for transparent terminals - being forced to use a background color means that loses it's effect.)

Port to Python 3

I tried to translate the code myself by

2to3 src/python/termboxconfig.pyx
2to3 src/python/termboxmodule.pyx

band then to install it

./waf configure --prefix=/usr/local                          
./waf                                                       
./waf install --destdir=/usr/local
sudo python3 setup.py install 

that worked fine. But when I tried to use it it printed:

Traceback (most recent call last):
  File "rr.py", line 2, in <module>
    import termbox
  File "termboxmodule.pyx", line 1, in init termbox (src/python/termboxmodule.c:3377)
NameError: name 'unichr' is not defined

So what to do now?

Assertion !"unreachable" failed.

This was triggered by pasting more than 64 bytes to the terminal. I fixed this easily for my own purposes by increasing ENOUGH_DATA_FOR_PARSING, but I thought it would be worth noting.
Great job on the library, by the way, I love the design of it. :-)

termbox can't detect resize events when in select()

In my application I'm using tb_poll_event() in a select() loop. I'm calling tb_poll_event() only when stdin is ready. The problem is termbox can't detect resize events when I do that. As a test, if I remove my select() loop and use tb_peek_event(), it works fine. Note that I don't have any signal handlers for SIGWINCH or anything.

I thought of implementing my own SIGWINCH handler and calling termbox's update_size() but unfortunately that's a static functions so I can't do that.

Any ideas what may be causing this problem? Would it make sense to add a tb_update_size() function to manually trigger a resize in termbox?

Thanks.

Add Windows support to the C version of termbox

Currently, termbox.c seems to use hard-coded VT100 escape codes like \033[ for cursor movement and text colors. It would be nice to have at least a rudimentary (#ifdef-based) alternative for Windows console support. (The Go version seems to have very fleshed-out cross-platform support; is anything holding back the C version from getting it too, or is it just that nobody's gotten around to it?)

(Great work on this, BTW -- hate to sound like I'm complaining about missing features when this library is actually really good!)

ESC considered to be F1 in keyboard events

Hi! I'm new here and I'm trying to make the output demo work in a GNOME terminal. The while loop in the main function clearly shows that it should exit when the ESC key is pressed, but it doesn't work. I always get a 0xFFFF as ev.key instead of TB_KEY_ESC.

I believe the problem is in the extract_event, which calls parse_escape_seq when the first character of the input buffer is ESC. The parse_escape_seq will then find this single-character buffer matches the first sequence in the keys array, which is F1.

I added a len > 1 condition above the call to parse_escape_seq as a workaround. Not sure if I've done anything wrong as such a fundamental feature should be broken.

Move Python wrapper into separate repository

Personally, I don't think a Python wrapper belongs in the same repo as a C library.

I'm not 100% sure how the wrapper is generated, but I'm assuming it doesn't need the full C source tree. If it does, git submodules could be used to include the C sources into the Python wrapper's repo while still providing separation between the two.

"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".

Can't read Alt key in TB_INPUT_ESC mode

Is it possible to read the Alt key when not in INPUT_ALT mode?

Using the keyboard demo, pressing Alt+f for example only highlights the f key, unless I change to TB_INPUT_ALT mode, where the same key sequence highlights both keys.

I need to be able to get normal Esc behaviour, and still use the Alt key. Is this possible? Could just be missing something simple here.

Input doesn't work on bash for Windows

Tried compiling and running the demos through the newly released bash on Ubuntu on Windows; compilation and running the demos worked fine, but input doesn't work. Seemingly holding down ctrl C + Q for a few seconds does trigger an exit on the keyboard demo, but it's not immediate.

I'm wondering what the problem is, and where in the code I might begin trying to fix it. I had a brief look at the event polling functions, but without any concrete idea what might be causing the issue I wasn't sure how to proceed. Any ideas?

Delayed ESC event in INPUT_ESC mode

Even though I use INPUT_ESC mode (and thus assume no special behaviour for the Escape key), the Escape key event takes longer than other keys.

To reproduce, run this code in a python3 REPL:

import termbox
tb = termbox.Termbox(); tb.select_input_mode(termbox.INPUT_ESC); tb.poll_event(); tb.close()

Upon pressing any key, termbox will exit quickly; but when pressing Escape, it takes a bit longer.

I checked how fast vim responds (it is almost instantaneous), so I assume this should be possible. (I hope they didn't apply insane hackery.) Edit: I did that check by opening a new terminal and running vim in it; as I just found out, vim responds slowly too when run inside of tmux. See my comment below.

_XOPEN_SOURCE is not defined for python extensions

compiler error:

x86_64-pc-linux-gnu-gcc -fPIC -I/usr/include/python3.4m -c src/termbox.c -o /tmp/portage/sys-libs/termbox-1.1.0/work/termbox-1.1.0-python3_4/temp.linux-x86_64-3.4/src/termbox.o -Wno-error=declaration-after-statement
src/termbox.c: In function 'tb_present':
src/termbox.c:187:8: warning: implicit declaration of function 'wcwidth' [-Wimplicit-function-declaration]
    w = wcwidth(back->ch);
        ^

my workaround:

setup.py:

- ext_modules = [Extension('termbox', sourcefiles, extra_compile_args=["-Wno-error=declaration-after-statement"])],
+ ext_modules = [Extension('termbox', sourcefiles, extra_compile_args=["-D_XOPEN_SOURCE", "-Wno-error=declaration-after-statement"])],

clear (\033[m) is put after each call to tb_change_cell

try the following code snippet in normal color mode:

for (color = 1; color < 8; color++) {
    tb_change_cell(color, 2, 'X', 2, color);
}
tb_present();

The forground color changes after the first tb_change_cell() to white.

Only the bg (color) parameter changes that's why the code calls write_sgr_bg() but somehow a clear was introduced earlier so that the foreground value is negated/overwritten by the default one.

I tested it against e742ddb5908dff205dde338b50f3a92ec2e844e1 and it worked.
So my commits introduced a bug.
I will look into it tomorrow evening.

Failed installation on win7

(I'm a fan of termbox-go on WIndows, but wanted to try compiling the C library - btw, could this be distributed is as a single source file to build together with the application? I saw this approach with http://duktape.org/ and it was super easy to use. Antirez does something similar with https://github.com/antirez/linenoise)

D:\inst\termbox>python waf
Waf: Entering directory `D:\inst\termbox\build'
[ 1/10] c: src\termbox.c -> build\src\termbox.c.1.o
[ 2/10] c: src\utf8.c -> build\src\utf8.c.1.o
[ 3/10] c: src\termbox.c -> build\src\termbox.c.2.o
[ 4/10] c: src\utf8.c -> build\src\utf8.c.2.o
cl : Command line error D8021 : invalid numeric argument '/Wextra'

cl : Command line error D8021 : invalid numeric argument '/Wextra'

cl : Command line error D8021 : invalid numeric argument '/Wextra'

cl : Command line error D8021 : invalid numeric argument '/Wextra'

Waf: Leaving directory `D:\inst\termbox\build'
Build failed
-> task in 'termbox_shared' failed (exit status 2):
{task 40143568: c termbox.c -> termbox.c.1.o}
['D:\msvc12\VC\BIN\amd64\CL.exe', '/nologo', '-std=gnu99', '-Wall', '-Wextra', '-O3', '/IC:\Program Files (x86)\M
icrosoft Visual Studio 10.0\VC\INCLUDE', '/IC:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\ATLMFC\INCLUDE
', '/IC:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include', '/ID:\msvc12\VC\INCLUDE', '/ID:\msvc12\VC
\ATLMFC\INCLUDE', '/IC:\Program Files (x86)\Windows Kits\8.1\include\shared', '/IC:\Program Files (x86)\Windows
Kits\8.1\include\um', '/IC:\Program Files (x86)\Windows Kits\8.1\include\winrt', '', '..\src\termbox.c', '/FC'
, '/c', '/Fo', 'D:\inst\termbox\build\src\termbox.c.1.o']

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

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?

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.

Clear specified area

It'd be nice to be able to clear only a specific area, as then subroutines that separate off from the main event loop for a bit could be written without needing to re-draw the existing content.

For example, if a program were to have a dialog pop up, it would be nice to be able to let a separate subroutine draw that dialog and handle events for it without the subroutine needing to be aware of the rest of the program state. This is particularly relevant in text entry, where the display needs to be cleared for a character to actually disappear.

This may already be possible and I'm just missing something (it'd be nice to have an IRC channel or something where I can go to check these things).

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.

Doesn't work well with urxvt?

I just tried the keyboard example (in src/demo) with urxvt, and it doesn't work as well as it works on other terminals. For example, it can't detect keys F1 to F4. In addition, some keys are handled differently. For example, alt + arrow keys are detected as if only arrows are pressed, whereas in other terminals they're detected as shift + c, shift + d etc.

I'm wondering if this is expected?

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.

Keyboard input corrupted when scrolling in python on a macintosh

scrolltest.txt
I found my termbox based program was quitting when scrolling with the touchpad on a macbook.
I traced this to the program receiving ESCs while scrolling, when it should only be getting arrow up or down events.

I wrote a test case that gets counts the events.
Run it, scroll up a few times, then press X to quit and print the results.
Without a time delay in the loop, this works fine. You only get up arrow events.
I added a time delay in the loop to simulate the delay in updating the view in my program. Then 3 other different events are received, including ESC.

Without delay..
$ ./scrolltest.py
(1, None, 65516, 0, 0, 0, 0, 0) : 14

With delay..
./scrolltest.py
(1, u'O', 0, 0, 0, 0, 0, 0) : 1
(1, u'B', 0, 0, 0, 0, 0, 0) : 1
(1, None, 65516, 0, 0, 0, 0, 0) : 104
(1, None, 27, 0, 0, 0, 0, 0) : 1

So something is up with the event handling. It seems to be chopping up the escape sequences into smaller chunks before they are interpreted as key strokes.

scrolltest.py...

Basic TUI widgets

Hey.

I wanted to ask, is there a way to have easier handles to native widgets such as Windows, changing the terminal's entire background, and the like? I want to create a TUI for a tool I am writing.

Kind regards,
Ingwie.

Termbox does not start in LXC

Termbox does not start in LXC with a TurnKeyLinux container, it gives the following error:
consoleui failed: Failed to initialize terminal: termbox: error while reading terminfo data: termbox: unsupported terminal
I connect throughout ssh and it works like a charm.

Python installation issues in Fedora

Experienced on Fedora 23

When running python3 setup.py install I get the following error:

running install
running build
running build_ext
skipping 'src/python/termboxmodule.c' Cython extension (up-to-date)
building 'termbox' extension
gcc -pthread -Wno-unused-result -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/python3.4m -c src/python/termboxmodule.c -o build/temp.linux-x86_64-3.4/src/python/termboxmodule.o -Wno-error=declaration-after-statement
gcc: error: /usr/lib/rpm/redhat/redhat-hardened-cc1: No such file or directory
error: command 'gcc' failed with exit status 1

My guess is that the build script considers Fedora a RHEL install.

Included waf has trouble with certain Python versions

Included waf version has issues with Python 3.4, trying to do waf configure gives us:

Waf: Entering directory `/home/karoru/dev/termbox/build'
[ 1/11] c: src/termbox.c -> build/src/termbox.c.1.o

[...] 

[11/11] vnum: build/src/libtermbox.so -> build/src/libtermbox.so.1 build/src/libtermbox.so.1.0.0
Waf: Leaving directory `/home/karoru/dev/termbox/build'
Traceback (most recent call last):
  File "/home/karoru/dev/termbox/.waf3-1.7.9-0437e76702658aaf2ece405140bd2de8/waflib/Scripting.py", line 97, in waf_entry_point
    run_commands()
  File "/home/karoru/dev/termbox/.waf3-1.7.9-0437e76702658aaf2ece405140bd2de8/waflib/Scripting.py", line 153, in run_commands
    ctx=run_command(cmd_name)
  File "/home/karoru/dev/termbox/.waf3-1.7.9-0437e76702658aaf2ece405140bd2de8/waflib/Scripting.py", line 146, in run_command
    ctx.execute()
  File "/home/karoru/dev/termbox/.waf3-1.7.9-0437e76702658aaf2ece405140bd2de8/waflib/Scripting.py", line 351, in execute
    return execute_method(self)
  File "/home/karoru/dev/termbox/.waf3-1.7.9-0437e76702658aaf2ece405140bd2de8/waflib/Build.py", line 106, in execute
    self.execute_build()
  File "/home/karoru/dev/termbox/.waf3-1.7.9-0437e76702658aaf2ece405140bd2de8/waflib/Build.py", line 115, in execute_build
    self.compile()
  File "/home/karoru/dev/termbox/.waf3-1.7.9-0437e76702658aaf2ece405140bd2de8/waflib/Build.py", line 196, in compile
    self.store()
  File "/home/karoru/dev/termbox/.waf3-1.7.9-0437e76702658aaf2ece405140bd2de8/waflib/Utils.py", line 386, in f
    ret=fun(*k,**kw)
  File "/home/karoru/dev/termbox/.waf3-1.7.9-0437e76702658aaf2ece405140bd2de8/waflib/Build.py", line 170, in store
    cPickle.dump(data,f,-1)
_pickle.PicklingError: Can't pickle <class 'waflib.Node.Context.__init__.<locals>.node_class'>: attribute lookup Context.__init__.<locals>.node_class on waflib.Node failed

Build process on the same machine works very well using python2.

Allow the use of default colors

When clear is called it sets the background to black and foreground to white, but these colors may not be the default foreground and background colors. Also, when drawing to the screen, there does not seem to be an option to use the default foreground and background colors. This is annoying, since some applications will look better if they respect the foreground and background colors the user has set for his terminal. Is there some way support for using the default colors could be added? Currently, the programmer can write his own clear method and use a hack to use the default colors, but he should not have to do this.

64bit compile (add -fPIC)

cc termbox.c term.c input.c ringbuffer.c utf8.c -shared -o libtermbox.so
/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.5/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/cc5QXqJb.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/tmp/cc5QXqJb.o: could not read symbols: Bad value
collect2: ld returned 1 exit status
make: *** [libtermbox.so] Error 1

go binding doesn't compile

libtermbox.so compiles fine but the go binding doesn't.
The first line in go/Makefile is:
#include $(GOROOT)/src/Make.inc
but there is no such file in my go installation.
Replacing it with
#include $(GOROOT)/src/Make.$(GOARCH)
yields following output:
shogg@fhtagn:~/go/src/pkg/github.com/nsf/termbox/go$ make
CGOPKGPATH= /home/shogg/bin/cgo termbox.go
gcc failed:
:10: error: 'struct_tb_cell' undeclared here (not in a function)
cc1: warnings being treated as errors
:10: error: type defaults to 'int' in declaration of '__cgo__3'
:18: error: 'struct_tb_event' undeclared here (not in a function)
:18: error: type defaults to 'int' in declaration of '__cgo__11'
on input:
typedef struct { char *p; int n; } GoString;
GoString GoString(char *p);
char *CString(GoString);
#include "../termbox.h"
typeof(tb_height) *__cgo__0;
typeof(tb_set_cursor) *__cgo__1;
typeof(int) *__cgo__2;
typeof(struct_tb_cell) *__cgo__3;
typeof(tb_blit) *__cgo__4;
typeof(unsigned int) *__cgo__5;
typeof(tb_poll_event) *__cgo__6;
typeof(tb_present) *__cgo__7;
typeof(tb_put_cell) *__cgo__8;
typeof(uint16_t) *__cgo__9;
typeof(tb_clear) *__cgo__10;
typeof(struct_tb_event) *__cgo__11;
typeof(uint32_t) *__cgo__12;
typeof(tb_select_input_mode) *__cgo__13;
typeof(tb_peek_event) *__cgo__14;
typeof(tb_shutdown) *__cgo__15;
typeof(tb_init) *__cgo__16;
typeof(tb_change_cell) *__cgo__17;
typeof(tb_width) *__cgo__18;

make: *** [_cgo_defun.c] Fehler 2

Replacing C.struct_tb_cell and C.struct_tb_event by C.tb_cell and C.tb_event in termbox.go doesn't work either.

valgrind reports uninitialized var (plus patch)

Hiho,

Valgrind is telling me:

==27059== Syscall param rt_sigaction(act->sa_mask) points to uninitialised byte(s)
==27059==    at 0x506F0F5: __libc_sigaction (sigaction.c:66)
==27059==    by 0x5E44E76: tb_init (termbox.c:98)
------------------- ^^^^^^^ here
==27059==    by 0x5C39A59: cb_init (mod_termbox.c:43)
... my code after that ... 

==27059==  Address 0x7feffe778 is on thread 1's stack
==27059==  Uninitialised value was created by a stack allocation
==27059==    at 0x5E44DD2: tb_init (termbox.c:79)

The code is:

    struct sigaction sa;
    sa.sa_handler = sigwinch_handler;
    sa.sa_flags = 0;
    sigaction(SIGWINCH, &sa, 0);

Adding this line after the sa decl:

memset(&sa, 0, sizeof(sa));

fixes it.

Python errors aren't shown

When an error occurs while running a Python-Script with termbox, the script simply exits and no errors are shown.
I tested it like this:

[...]
def lol():
    lol()

t.clear()
lol()
[...]

Is there any possibility to show the errors?

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.

Feature request: Ability to choose cell anchors

I'd like the ability to choose how to pack my cells into the given space when using tb_blit.

Specifically, I'd like to be able to pack them into the left top, left bottom (default), right top, right bottom and possibly left center, right center, center top, center bottom and center.

Sorry if this is already possible.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.