Sometimes it may be useful to get at raw input data in addition to or instead of tb_event structs. For example, if one were writing a faithful readline clone, one would need to support key bindings specified as raw input, not as logical keys. There is a way to get around this presently1 but it's a bit circuitous.
There are lot of ways to accomplish this. For example:
- Add a
tb_event.raw field. Would be annoying if we alloc-d for every tb_event, since the user would have to keep freeing it. If we didn't alloc, we could come up with a way that the raw data is valid until the next function call or something, which sounds complex.
- Make separate functions
tb_(poll|peek)_raw that return raw data instead of tb_event. Either make the _raw functions automatically append to the input buffer or add a tb_push_raw function so the caller could explicitly feed the input buffer. Unclear how this would handle resizes.
- Keep a separate raw buffer alongside the input buffer. Make functions for consuming this buffer. Make an init flag for enabling this behavior.
Or maybe this is too niche. Feedback encouraged.
Sometimes it may be useful to get at raw input data in addition to or instead of
tb_eventstructs. For example, if one were writing a faithful readline clone, one would need to support key bindings specified as raw input, not as logical keys. There is a way to get around this presently1 but it's a bit circuitous.There are lot of ways to accomplish this. For example:
tb_event.rawfield. Would be annoying if we alloc-d for every tb_event, since the user would have to keep freeing it. If we didn't alloc, we could come up with a way that the raw data is valid until the next function call or something, which sounds complex.tb_(poll|peek)_rawthat return raw data instead oftb_event. Either make the_rawfunctions automatically append to the input buffer or add atb_push_rawfunction so the caller could explicitly feed the input buffer. Unclear how this would handle resizes.Or maybe this is too niche. Feedback encouraged.
Footnotes
Initialize termbox to read from a pipe instead of the tty. Read the tty yourself (raw) then copy to termbox via the pipe. https://github.com/termbox/termbox2/blob/918369f9697dc8bb5927f69b3277a3ffbb920df4/demo/readline.c#L129 ↩