btui/test.c

42 lines
1.2 KiB
C
Raw Normal View History

2020-04-18 15:09:33 -07:00
#include <stdio.h>
#include "btui.h"
int main(void)
{
2020-04-18 16:03:53 -07:00
btui_t *bt = btui_enable();
if (!bt) return 1;
2020-04-18 15:09:33 -07:00
int done = 0;
int x = 0, y = 0;
int i = 0;
while (!done) {
2020-04-18 16:03:53 -07:00
btui_move_cursor(bt, 0, bt->height-1);
btui_printf(bt, "Update %d, size = %dx%d", i++, bt->width, bt->height);
btui_flush(bt);
2020-04-18 15:09:33 -07:00
2020-04-18 16:03:53 -07:00
int key = btui_getkey(bt, NULL, NULL);
2020-04-18 15:09:33 -07:00
switch (key) {
case 'q': case KEY_CTRL_C: done = 1; break;
case -1: break;
case KEY_ARROW_DOWN:
btui_scroll(bt, 1, bt->height-1, +1);
break;
case KEY_ARROW_UP:
btui_scroll(bt, 1, bt->height-1, -1);
break;
2020-04-18 15:09:33 -07:00
default: {
char buf[256] = {0};
btui_keyname(key, buf);
2020-04-18 16:03:53 -07:00
btui_move_cursor(bt, x, y++);
//btui_set_attributes(bt, BTUI_FG_YELLOW | BTUI_BOLD);
btui_set_fg_hex(bt, 0xacff40);
btui_printf(bt, "Pressed: %s", buf);
2020-04-18 16:03:53 -07:00
btui_set_attributes(bt, BTUI_NORMAL);
fflush(bt->out);
2020-04-18 15:09:33 -07:00
break;
}
}
}
2020-04-18 16:03:53 -07:00
btui_disable(bt);
2020-04-18 15:09:33 -07:00
return 0;
}