Adam Saponara [Tue, 29 Apr 2025 01:45:55 +0000 (21:45 -0400)]
fix alignment warnings
some architectures don't support reading an `int16_t` on an odd
memory. so several `int16_t` explicit casts while parsing terminfo
caps emit warnings. change these to `memcpy` to fix.
replace `header[n]` with variable names in `parse_terminfo_caps`.
Adam Saponara [Mon, 21 Apr 2025 04:34:59 +0000 (00:34 -0400)]
add built-in replacements for `iswprint(3)` and `wcwidth(3)`
in b075ddd, we added an `iswprint` check to prevent untrusted input
from garbling the terminal. `iswprint` is locale-dependent, so if the
caller did not `setlocale` to a UTF-8 `LC_CTYPE`, the check would
fail. this affected several library users.
termbox has always had built-in support for converting between UTF-8
and 32-bit codepoints (i.e., replacements for `wcrtomb(3)` and
`mbrtowc(3)`). this patch adds built-in support for `iswprint` and
`wcwidth` as well, which makes the entire library Unicode compatible
independent of locale.
a compile-time option to use the libc versions is supported.
Adam Saponara [Wed, 18 Dec 2024 03:12:25 +0000 (22:12 -0500)]
fix bug with adding combining chars to a full-width char
the logic was incorrectly sending the combinin char to x-1, but that
assumed a wcwidth==1 char. save last printed x coord and use that
instead.
xterm's ansi output for this is a little strange. unlike other
`expected.ansi` files, cat-ing this one to stdout doesn't seem to
render the correct output, and if you peek at its contents you'll see
some "\xef\xbf\xbf" (U+FFFF) which is an invalid codepoint. in any
case, it still picks up the regression so i'm adding it.
Adam Saponara [Fri, 4 Oct 2024 23:33:51 +0000 (19:33 -0400)]
`setlocale` in demo
since around cd42ba3, we rely on `iswprint`, which itself is
locale-dependent. callers using unicode (like the demo) must be sure
to set a unicode locale prior to initializing.
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.