readr

Minimal Terminal RSS Reader
Log | Files | Refs | README | LICENSE

tui.c (952B)



#include "tui.h"

#define TB_IMPL
#include "termbox2.h"

int
present(app_t* app)
{
	struct tb_event ev = { 0 };
	int can_poll = -1;
	int cannot_init = tb_init();

	tb_hide_cursor();

	if (cannot_init) {
		fprintf(stderr, "could not TUI\n");
		return 1;
	}

	render(app);

	while (1) {
		can_poll = tb_poll_event(&ev);

		if (can_poll == TB_OK) {
			switch (ev.type) {
			case (TB_EVENT_KEY):

				if (ev.key == TB_KEY_CTRL_Q        //
					|| ev.key == TB_KEY_ESC    //
					|| ev.key == TB_KEY_CTRL_C //
					|| ev.ch == 'q')
					goto RIP;

				handle_key(app, ev);

				break;
			case (TB_EVENT_MOUSE):
				break;
			case (TB_EVENT_RESIZE):
				break;
			}

			render(app);

		} else if (can_poll == TB_ERR_POLL && tb_last_errno() == EINTR) {
			continue;

		} else if (can_poll != TB_ERR_NO_EVENT) {
			fprintf(stderr, "(aborting) renderer error: %s\n", tb_strerror(can_poll));
			goto RIP;
		}
	}

RIP:
	tb_shutdown();
	printf("\n");
	return 0;
}