nsf / termbox

Library for writing text-based user interfaces
http://code.google.com/p/termbox
MIT License
1.96k stars 184 forks source link

Pressing ESC after setting the mode to TB_MOUSE_INPUT triggers assertion error #55

Closed sru closed 9 years ago

sru commented 9 years ago

It triggers this assertion.

The program is:

#include "termbox.h"

int main(int argc, char **argv) {
    tb_init();
    tb_select_input_mode(TB_INPUT_MOUSE);

    struct tb_event ev;
    tb_poll_event(&ev);

    tb_shutdown();
    return 0;
}

See also: gchp/rustbox#32

nsf commented 9 years ago

That's true. Because TB_INPUT_MOUSE is invalid input mode. It's a bit flag that should only be used in conjuction with TB_INPUT_ESC or TB_INPUT_ALT. I should enforce that I guess.

sru commented 9 years ago

Would it increase complexity to just add TB_INPUT_MOUSE mode if it's the only mode passed?

nsf commented 9 years ago

But what would it mean? No keyboard input? :) Initially there were two modes: ESC and ALT. And MOUSE is an additional mode which works with either of those.

sru commented 9 years ago

Hmm... I see. It was just a passing thought. Then does it make sense to lump MOUSE mode with the two keyboard modes (ESC and ALT)?

On the other thought, how are you going to enforce it?

nsf commented 9 years ago

I can make one of the modes a default one. Perhaps the one which is enabled by default. That is ESC mode. :)

sru commented 9 years ago

+1. You might want to make sure that if mouse mode is passed alone, the keyboard mode changes to ESC mode.

panicbit commented 9 years ago

What's the point of TB_INPUT_CURRENT then if you have to pass TB_INPUT_ESC or TB_INPUT_ALT anyway?

sru commented 9 years ago

@panicbit https://github.com/nsf/termbox/blob/master/src/termbox.h#L237 It returns the current input mode.

panicbit commented 9 years ago

@nsf Can you think of any reason why I'm not getting the assertion using this C snippet (but do get the assertion when using the Rust wrapper of termbox)?

edit: Alright, I apparently didn't get the assertion because I was linking termbox as shared lib.