Skip to content

Support for getting raw input #128

@adsr

Description

@adsr

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:

  1. 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.
  2. 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.
  3. 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.

Footnotes

  1. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions