aboutsummaryrefslogtreecommitdiff
path: root/src/util/term.cc
blob: 704f8724af0e35b9c838dfaf3ad18783c87c79d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "term.h"

#include <system_error>

#include <termbox.h>

namespace util {

void print_tb(
	std::size_t   x,
	std::size_t   y,
	std::uint16_t fg,
	std::uint16_t bg,
	const std::string& text
) {
	for ( const char& c : text ) {
		tb_change_cell(x, y, c, fg, bg);
		x++;
	}
}

TermGuard::TermGuard() {
	tb_init();
	tb_select_output_mode(TB_OUTPUT_NORMAL);
	tb_select_input_mode(TB_INPUT_ESC | TB_INPUT_MOUSE);
}

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;
	}
}

}