static void send_char(int x, int y, uint32_t c) { char buf[7]; int bw = tb_utf8_unicode_to_char(buf, c); if (x-1 != lastx || y != lasty) write_cursor(x, y); lastx = x; lasty = y; if(!c) buf[0] = ' '; // replace 0 with whitespace bytebuffer_append(&output_buffer, buf, bw); }
char Window::wait_for_input() { // Blocks until keypress tb_poll_event(&input); switch (input.key) { case TB_KEY_BACKSPACE2: return '\b'; case TB_KEY_ENTER: return '\n'; case TB_KEY_SPACE: return ' '; case TB_KEY_TAB: return '\t'; } char c; tb_utf8_unicode_to_char(&c, input.ch); return c; }
static int lua_tb_peek_event( lua_State *L ) { int event_type = 0; struct luabox_State *lbstate; struct tb_event *event_struct; lua_pushlightuserdata( L, L ); lua_gettable( L, LUA_REGISTRYINDEX ); lbstate = lua_touserdata( L, -1 ); event_struct = &lbstate->event; if ( lua_isnumber( L, 1 ) ) { event_type = tb_peek_event( event_struct, (int) lua_tonumber( L, 1 )); } else { event_type = tb_poll_event( event_struct ); } switch ( event_type ) { LUABOX_CALL( TB_EVENT_KEY ) if ( event_struct->ch ) { char buffer[8] = {0}; tb_utf8_unicode_to_char( buffer, event_struct->ch ); lua_pushstring( L, buffer ); lua_pushnumber( L, event_struct->ch ); } else { lua_pushstring( L, "" ); lua_pushnumber( L, event_struct->key ); } lua_pushnumber( L, event_struct->mod ); LUABOX_RETURN( TB_EVENT_KEY, 3, 0 ) LUABOX_CALL( TB_EVENT_RESIZE ) lua_pushnumber( L, event_struct->w ); lua_pushnumber( L, event_struct->h ); LUABOX_RETURN( TB_EVENT_RESIZE, 2, 0 ) LUABOX_CALL( TB_EVENT_MOUSE ) lua_pushnumber( L, event_struct->x ); lua_pushnumber( L, event_struct->y ); lua_pushnumber( L, event_struct->key ); LUABOX_RETURN( TB_EVENT_MOUSE, 3, 0 ) } return 0; }