Rauli Laine [Sat, 14 Sep 2024 19:31:39 +0000 (22:31 +0300)]
Mention Node.js wrapper on README
I recently created termbox2 (termbox1 already exists but is
unmaintained) wrapper library for Node.js JavaScript engine
and thought it would be nice to mention about it in README.md in case
anyone else than me needs one.
Adam Saponara [Sat, 27 Jul 2024 20:59:09 +0000 (16:59 -0400)]
make `tb_print*` functions a little kinder
* handle newlines. previously they would mess up rendering.
* replace other non-printable codepoints with U+FFFD.
* skip over cells that would go out of bounds instead of erroring.
Adam Saponara [Fri, 17 Nov 2023 01:03:06 +0000 (20:03 -0500)]
fix compile warning in demo
```
In file included from demo/keyboard.c:5:
demo/keyboard.c: In function ‘draw_keyboard’:
demo/../termbox2.h:252:33: warning: unsigned conversion from ‘int’ to ‘uint16_t’ {aka ‘short unsigned int’} changes value from ‘16777222’ to ‘6’ [-Woverflow]
252 | #define TB_MAGENTA 0x0006
| ^
demo/keyboard.c:512:22: note: in expansion of macro ‘TB_MAGENTA’
512 | printf_tb(33, 1, TB_MAGENTA | TB_BOLD, TB_DEFAULT, "Keyboard demo!");
```
Adam Saponara [Thu, 13 Jul 2023 06:57:59 +0000 (02:57 -0400)]
add support for more style attrs and 64-bit attrs (#56)
probably should have broken this into multiple commits but it was all
inter-related:
* deprecate TB_OPT_TRUECOLOR in favor of TB_OPT_ATTR_W which defaults
to 16, but can be 32 (truecolor) or 64 (truecolor + additional
styles). for back compat, TB_OPT_TRUECOLOR sets TB_OPT_ATTR_W to 32
if not already set.
* add TB_BRIGHT, available in TB_OUTPUT_NORMAL only.
* add TB_DIM and TB_INVISIBLE. TB_INVISIBLE is available only when
TB_OPT_ATTR_W=64.
* add TB_STRIKEOUT, TB_UNDERLINE_2, TB_OVERLINE, available only when
TB_OPT_ATTR_W=64. these are hard-coded caps because they don't
appear to be in terminfo.
* deprecate TB_256_BLACK and TB_TRUECOLOR_BLACK in favor of
TB_HI_BLACK which can be used in any of the hi-color modes.
* deprecate all TB_TRUECOLOR_* style attributes. users can use
TB_BOLD, TB_UNDERLINE, etc in truecolor mode now.
Adam Saponara [Fri, 7 Jul 2023 00:30:14 +0000 (20:30 -0400)]
skip empty caps (#57)
this slipped under the radar because none of the built-in terms have
more than one empty key cap, or an empty string for one of the caps
we use in init/shutdown.
some terms do of course have multiple empty caps. for example,
`xterm-color` is missing `khome`, `kend`, and `kcbt` (back-tab),
which leads to adding `""` more than once, which leads to a
`TB_ERR_CAP_COLLISION` error on init. other terms don't have caps for
hiding and showing the cursor, for example.
to avoid these errors, we avoid adding empty caps to the trie, and
similarly avoid emitting empty caps.
it's kind of hard to add a functional test for this as it gets into
testing multiple term envs and terminal emulators which is a bit of a
pandora's box. as an alternative, i'm going to do some more manual
testing on various terms on my system.
Adam Saponara [Sun, 2 Apr 2023 22:10:10 +0000 (18:10 -0400)]
restore `TB_DEFAULT==0` in all modes (#51)
this removes `TB_TRUECOLOR_DEFAULT` added in 846bba4b and goes back to
`TB_DEFAULT==0` in all modes. instead, hi-bit macros `TB_256_BLACK`
and `TB_TRUECOLOR_BLACK` are added which provide a way to emit black
in those modes.
turns out there were some subtle bugs associated with `TB_DEFAULT!=0`
(in addition to the bug identified in #51). the bugs were fixable but
required uglying up some code. zero as default in all modes is more
intuitive and easier to reason about (e.g., `memset(..., 0, ...)`).
Adam Saponara [Thu, 6 Oct 2022 06:03:04 +0000 (02:03 -0400)]
fix the no-cap case of `get_terminfo_string`
a negative string offset indicates the corresponding cap is
not supported on that terminal. return an empty string in
this case. previously we'd return garbage.
for a test case, observe what happens when fetching `smcup`
on `TERM=linux`.
Adam Saponara [Sun, 18 Sep 2022 22:05:50 +0000 (18:05 -0400)]
support default colors in non-`TB_OUTPUT_NORMAL` modes (#41)
`TB_DEFAULT` is now defined as a bitwise attribute similar to
`TB_BOLD`. previously it was defined as 0 which made it impossible to
use default colors in non-`TB_OUTPUT_NORMAL` modes.
for convenience and limited back-compat, 0 is still interpreted as
`TB_DEFAULT` in `TB_OUTPUT_NORMAL`, `TB_OUTPUT_216`, and
`TB_OUTPUT_GRAYSCALE`, though `TB_DEFAULT` may be used as well.
in `TB_OUTPUT_256` and `TB_OUTPUT_TRUECOLOR`, 0 is black, so
`TB_DEFAULT` and `TB_TRUECOLOR_DEFAULT` respectively must be used if
a default color is desired.
Adam Saponara [Sat, 4 Jun 2022 21:27:20 +0000 (17:27 -0400)]
Run tests for non-truecolor and non-egc builds.
This patch introduces a few new things:
* Build artifact termbox.ffi.h for easier FFI header file parsing. As a result, no more `__ffi_strip` bs, but probably more complex overall. The other idea I had would have been uglier. I think the test coverage is worth it.
* Functions `tb_has_truecolor` and `tb_has_egc` for determining support for those features at runtime.
* Test container uses `debian:11-slim` image instead of `debian:10-slim`.
* Test container uses PHP 8 instead of PHP 7.
* Test container now accepts `cflags` build argument.
* Tests can now be skipped via `$test->skip()`.
* Test suite covers 3 different builds: normal, non-truecolor, non-egc.
Adam Saponara [Thu, 6 Jan 2022 06:06:30 +0000 (01:06 -0500)]
fix bug in `extract_esc_cap`.
previously we were able to read past the actual end of the
input buffer (`global.in.buf`). we would not segfault due
to how bytebufs are implemented, but we could erroneously
re-process segments of input. in practice i think this
could only occur with an instantaneous burst of tty input
greater than the read buffer in `wait_event` (64 bytes). i
noticed this by accidentally mouse-wheeling very fast in
xfce4-terminal which, in my setup, sends a bunch of
up-arrow events (`\x1bOA`) all at once, in which case
termbox was pseduo-randomly emitting "O" and "A" events.
Adam Saponara [Sun, 19 Sep 2021 01:07:56 +0000 (21:07 -0400)]
replace linear cap search with trie.
for every input, termbox used to iterate over termcaps one
at a time, `strncmp`ing it to the input buffer. the benefit
of this approach was that it had a very simple
implementation. the downside was that it was inefficient,
increasingly so as we added more caps such as modified
arrow keys.
the trie makes it easy to detect when there are overlaps in
termcaps. the obvious one is `TB_KEY_ESC` versus all other
escape codes. in the future we can modify function
`extract_esc_cap` to, e.g., potentially return `TB_KEY_ESC`
in `TB_INPUT_ALT` mode if no further input is available
after a certain amount of time.