Termbox started out with just 1 init function, tb_init. In 2016, tb_init_file and tb_init_fd were added. I added tb_init_rwfd in 2021 when I rewrote the library as termbox2, mainly for testing purposes, but also with some real world applications in mind.
Over time, feature requests have rolled in that would benefit from an init option. For example, an enable/disable flag for logging, region height for region mode, mask width for user-defined attributes, etc. Adding a new init function for all of these would explode the API, which we're trying very hard to keep tight and small. There's also a combinatoric problem. What if I want to initialize in region mode and pass in a tty fd?
This comment summarizes the potential solutions we've discussed:
- struct (ABI compat issues)
- struct with size
- variadic (arg1_type, arg1, arg2_type, arg2 ...)
- variadic (fmt, arg1, arg2, ...)
- uintptr_t array
- uintptr_t array with sentinel
- string
My proposal for this work is option 2:
// struct with size
struct tb_init_opts o = {0};
o.size = sizeof(o);
o.file = "/dev/tty";
o.region_h = 3;
tb_init_ex(&o); // only reads up to `o.size`
We keep type safety but somewhat limit ABI compat issues (when the library is dynamically linked) via the size field.
Termbox started out with just 1 init function,
tb_init. In 2016,tb_init_fileandtb_init_fdwere added. I addedtb_init_rwfdin 2021 when I rewrote the library as termbox2, mainly for testing purposes, but also with some real world applications in mind.Over time, feature requests have rolled in that would benefit from an init option. For example, an enable/disable flag for logging, region height for region mode, mask width for user-defined attributes, etc. Adding a new init function for all of these would explode the API, which we're trying very hard to keep tight and small. There's also a combinatoric problem. What if I want to initialize in region mode and pass in a tty fd?
This comment summarizes the potential solutions we've discussed:
My proposal for this work is option 2:
We keep type safety but somewhat limit ABI compat issues (when the library is dynamically linked) via the
sizefield.