feat(compat): drop-in termbox2.h + editor example (DoD #8)#54
Closed
rizukirr wants to merge 7 commits into
Closed
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A drop-in
compat/termbox2.hmapping the supported termbox2tb_/TB_API onto libterm'slt_/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 fullTB_KEY_*/TB_*constant surface, and ~37 functions. Adapts the one signature-divergent function (tb_get_cell, pointer-return → snapshot copy; back-buffer only) andtb_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 thelt_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 theback==0 → TB_ERR(back-buffer-only) contract.examples/editor.c— minimal but real text editor (open/edit/save/quit), built against ONLYcompat/termbox2.hwith zerolt_/LT_symbols — the DoD feat(input): report Ctrl+letter and control bytes as termbox2 key codes #8 drop-in proof.Input semantics
tb_inituses libterm's modern key model by default (single Esc; Ctrl+letter as ch+mod). For exact termbox2 key semantics, calltb_set_input_mode(LT_INPUT_COMPAT)aftertb_init— documented in the header.Testing
ctest→100% tests passed, 0 tests failed out of 36(+compat_smoke+test_compat_get_cell).-DLIBTERM_WARNINGS_AS_ERRORS=ON) → exit 0, under the full-Wall -Wextra -Werror -Wpedantic -Wshadow -Wstrict-prototypes -Wmissing-prototypes -Wcast-align -Wpointer-arith -Wwrite-stringsset on gcc and clang.examples/editor.c:grep -cE "\blt_[a-z]|\bLT_[A-Z]"→0(pure drop-in).build-testmatrix builds the editor (-Werror) and runs the compat tests viactest; no new CI job needed.