Skip to content

feat(compat): drop-in termbox2.h + editor example (DoD #8)#54

Closed
rizukirr wants to merge 7 commits into
mainfrom
vibe/compat-termbox2
Closed

feat(compat): drop-in termbox2.h + editor example (DoD #8)#54
rizukirr wants to merge 7 commits into
mainfrom
vibe/compat-termbox2

Conversation

@rizukirr

@rizukirr rizukirr commented Jun 13, 2026

Copy link
Copy Markdown
Owner

Summary

A drop-in compat/termbox2.h mapping the supported termbox2 tb_/TB_ API onto libterm's lt_/LT_ symbols, plus a minimal real text editor that builds against it — satisfying ROADMAP DoD #8.

Changes

  • compat/termbox2.h — single drop-in header. Aliases struct tags (#define tb_cell lt_cell / tb_event lt_event; typedef lt_attr uintattr_t), the full TB_KEY_*/TB_* constant surface, and ~37 functions. Adapts the one signature-divergent function (tb_get_cell, pointer-return → snapshot copy; back-buffer only) and tb_put_cell. Rejects the genuinely-unsupported functions (tb_init_rwfd, tb_set_func, tb_has_truecolor, tb_cell_buffer, tb_key_i) with an on-use compile error whose message names the lt_ alternative.
  • tests/compat_smoke.c — exhaustively references every alias (130 constants + 39 function/allocator aliases + TB_RGB + adapters), so a typo in any alias fails the build rather than surfacing silently at first use.
  • tests/test_compat_get_cell.c — pty-backed adapter test: round-trips a cell via the snapshot pointer and enforces the back==0 → TB_ERR (back-buffer-only) contract.
  • examples/editor.c — minimal but real text editor (open/edit/save/quit), built against ONLY compat/termbox2.h with zero lt_/LT_ symbols — the DoD feat(input): report Ctrl+letter and control bytes as termbox2 key codes #8 drop-in proof.

Input semantics

tb_init uses libterm's modern key model by default (single Esc; Ctrl+letter as ch+mod). For exact termbox2 key semantics, call tb_set_input_mode(LT_INPUT_COMPAT) after tb_init — documented in the header.

Testing

  • Full suite: ctest100% tests passed, 0 tests failed out of 36 (+compat_smoke +test_compat_get_cell).
  • Full project warnings-as-errors build (-DLIBTERM_WARNINGS_AS_ERRORS=ON) → exit 0, under the full -Wall -Wextra -Werror -Wpedantic -Wshadow -Wstrict-prototypes -Wmissing-prototypes -Wcast-align -Wpointer-arith -Wwrite-strings set on gcc and clang.
  • examples/editor.c: grep -cE "\blt_[a-z]|\bLT_[A-Z]"0 (pure drop-in).
  • Bucket-C reject + alias-typo catch confirmed by negative compile tests.
  • CI: the existing build-test matrix builds the editor (-Werror) and runs the compat tests via ctest; no new CI job needed.

rizukirr added 7 commits June 13, 2026 17:07
Reference all 130 value constants + 39 function/allocator aliases (plus TB_RGB
and the tb_get_cell/tb_put_cell adapters), so a typo in any alias fails the
build here instead of silently when a consumer first uses the symbol. Bucket-C
unsupported macros are deliberately not referenced.
…f memory')

append_row() reallocs g_rows and may move it, but insert_newline held a pointer
into the old array across that call and dereferenced it — a garbage length led
to a huge failing malloc reported as 'out of memory' when Enter split a line.
Realloc the array directly and re-index g_rows[g_cy] afterwards (also drops a
latent 1-byte leak). Add a terminal-free white-box regression test that includes
the editor TU (main() guarded by EDITOR_NO_MAIN) and asserts split/join
contents; it trips ASan heap-use-after-free against the old code.
libterm defaults to its modern key model (Ctrl+letter -> ch + LT_MOD_CTRL,
key == 0), so the editor's termbox2-idiom checks (ev.key == TB_KEY_CTRL_S/Q)
never matched and Ctrl-S/Ctrl-Q typed 's'/'q' instead. Opt into termbox2
control-byte semantics with the documented one-line adaptation.
clang-format: reflow compat/termbox2.h, compat_smoke.c, editor.c to satisfy the
format check. windows-mingw-native: test_compat_editor #includes editor.c, which
uses POSIX getline() (undeclared on MinGW); gate it to if(NOT WIN32) — examples
are already EXAMPLES=OFF on the Windows lanes, and the buffer logic is covered on
Linux/macOS.
@rizukirr rizukirr closed this Jun 13, 2026
@rizukirr rizukirr deleted the vibe/compat-termbox2 branch June 13, 2026 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant