diff options
-rw-r--r-- | life.cc | 9 | ||||
-rw-r--r-- | src/util/term.cc | 12 |
2 files changed, 14 insertions, 7 deletions
@@ -42,14 +42,9 @@ int main(int, char*[]) { draw(worldOffsetX, worldOffsetY, world); while ( true ) { - struct tb_event ev; - int t = tb_poll_event(&ev); + struct tb_event ev{ guard.poll() }; - if ( t == -1 ) { - return -1; - } - - switch ( t ) { + switch ( ev.type ) { case TB_EVENT_KEY: switch ( ev.key ) { case TB_KEY_ESC: diff --git a/src/util/term.cc b/src/util/term.cc index 9e4c101..704f872 100644 --- a/src/util/term.cc +++ b/src/util/term.cc @@ -1,5 +1,7 @@ #include "term.h" +#include <system_error> + #include <termbox.h> namespace util { @@ -27,4 +29,14 @@ TermGuard::~TermGuard() { tb_shutdown(); } +tb_event TermGuard::poll() const { + struct tb_event event; + + if ( tb_poll_event(&event) == -1 ) { + throw std::system_error(); + } else { + return event; + } +} + } |