feat(compat): drop-in termbox2.h + editor example (DoD #8)#55
Merged
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
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 — ROADMAP DoD #8.Changes
compat/termbox2.h— aliases struct tags (tb_cell/tb_event), constants, ~37 functions; adaptstb_get_cell(snapshot, back-buffer only) andtb_put_cell;#errors the genuinely-unsupported functions with a message naming thelt_path.tests/compat_smoke.c— exhaustively references every alias (130 constants + 39 funcs) so a typo in any alias fails the build.tests/test_compat_get_cell.c— pty-backedtb_get_cellround-trip + back-buffer-only contract.tests/test_compat_editor.c— white-box buffer-model regression test (POSIX-only; guards theinsert_newlineuse-after-free under ASan).examples/editor.c— minimal real editor built against the compat header.Runtime fixes (found by running the editor)
insert_newlineuse-after-free → "out of memory" on Enter: it held ag_rowspointer acrossrealloc. Re-index after the grow; ASan-guarded by the new test.ch+LT_MOD_CTRL,key==0). The editor opts intotb_set_input_mode(LT_INPUT_COMPAT)— the one documented adaptation.Testing
ctest→ 100% passed, 37 tests; full-DLIBTERM_WARNINGS_AS_ERRORS=ONbuild clean (gcc + clang);clang-formatclean tree-wide.examples/editor.creferences exactly oneLT_*symbol (the documented compat opt-in); everything else istb_/TB_.