Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ read -r -d '' terminfo_funcs <<'EOD'
rmkx EXIT_KEYPAD
dim DIM
invis INVISIBLE
ed CLEAR_EOS
EOD

read -r -d '' extra_keys <<'EOD'
Expand Down
6 changes: 5 additions & 1 deletion demo/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,11 @@ int main(int argc, char **argv)

setlocale(LC_ALL, "");

ret = tb_init();
if (argc >= 2 && atoi(argv[1]) > 0) {
ret = tb_init_ex(1, TB_INIT_REGION, 24);
} else {
ret = tb_init();
}
if (ret) {
fprintf(stderr, "tb_init() failed with error code %d\n", ret);
return 1;
Expand Down
34 changes: 34 additions & 0 deletions demo/region.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// cc -DTB_IMPL -I.. region.c -o region
#include <termbox2.h>

int main(int argc, char **argv) {
int sel, y, h, done;

tb_init_ex(1, TB_INIT_REGION, argc >= 2 ? atoi(argv[1]) : 10);

done = 0;
sel = 0;
while (!done) {
tb_clear();
for (y = 0; y < tb_height(); y++) {
tb_printf(0, y, 0, y == sel ? TB_REVERSE : 0, "Item %d", y);
}
tb_present();

struct tb_event ev;
tb_poll_event(&ev);
h = tb_height();

switch (ev.key) {
case TB_KEY_ARROW_UP: --sel; if (sel < 0) sel = 0; break;
case TB_KEY_ARROW_DOWN: ++sel; if (sel >= h) sel = h - 1; break;
case TB_KEY_ENTER: done = 1; break;
case TB_KEY_PGUP: tb_region(h + 1); break;
case TB_KEY_PGDN: tb_region(h - 1); break;
}
}
tb_shutdown();

printf("You picked item %d\n", sel);
return 0;
}
Loading