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.