#pragma once #include #ifdef __cplusplus extern "C" { #endif /*** 1. Controlling the screen. */ /* Names for some foreground/background colors. */ #define TB_BLACK 232 #define TB_WHITE 255 /* Some attributes of screen cells that can be combined with colors using * bitwise-OR. */ #define TB_BOLD 0x0100 #define TB_UNDERLINE 0x0200 #define TB_REVERSE 0x0400 /* Initialize screen and keyboard. */ int tb_init(void); /* Possible error codes returned by tb_init() */ #define TB_EUNSUPPORTED_TERMINAL -1 #define TB_EFAILED_TO_OPEN_TTY -2 /* Termbox uses unix pipes in order to deliver a message from a signal handler * (SIGWINCH) to the main event reading loop. */ #define TB_EPIPE_TRAP_ERROR -3 /* Restore terminal mode. */ void tb_shutdown(void); int tb_is_active(void); /* Size of the screen. Return negative values before tb_init() or after * tb_shutdown() */ int tb_width(void); int tb_height(void); /* Clear the screen using either TB_DEFAULT or the color/attributes set by * tb_set_clear_attributes(). */ void tb_clear(void); void tb_set_clear_attributes(uint16_t fg, uint16_t bg); /* Move the cursor. Upper-left character is (0, 0). */ void tb_set_cursor(int cx, int cy); /* Modify the screen at the cursor. */ void tb_print(uint32_t ch, uint16_t fg, uint16_t bg); /*** 2. Controlling keyboard events. */ struct tb_event { uint8_t type; /* fields for type TB_EVENT_KEY. At most one of 'key' and 'ch' will be set at * any time. */ uint16_t key; uint32_t ch; /* fields for type TB_EVENT_RESIZE */ int32_t w; int32_t h; /* fields for type TB_EVENT_MOUSE */ int32_t x; int32_t y; }; /* Possible values for tb_event.type. */ #define TB_EVENT_KEY 1 #define TB_EVENT_RESIZE 2 #define TB_EVENT_MOUSE 3 /* Possible values for tb_event.key. */ #define TB_KEY_F1 (0xFFFF-0) #define TB_KEY_F2 (0xFFFF-1) #define TB_KEY_F3 (0xFFFF-2) #define TB_KEY_F4 (0xFFFF-3) #define TB_KEY_F5 (0xFFFF-4) #define TB_KEY_F6 (0xFFFF-5) #define TB_KEY_F7 (0xFFFF-6) #define TB_KEY_F8 (0xFFFF-7) #define TB_KEY_F9 (0xFFFF-8) #define TB_KEY_F10 (0xFFFF-9) #define TB_KEY_F11 (0xFFFF-10) #define TB_KEY_F12 (0xFFFF-11) #define TB_KEY_INSERT (0xFFFF-12) #define TB_KEY_DELETE (0xFFFF-13) #define TB_KEY_HOME (0xFFFF-14) #define TB_KEY_END (0xFFFF-15) #define TB_KEY_PGUP (0xFFFF-16) #define TB_KEY_PGDN (0xFFFF-17) #define TB_KEY_ARROW_UP (0xFFFF-18) #define TB_KEY_ARROW_DOWN (0xFFFF-19) #define TB_KEY_ARROW_LEFT (0xFFFF-20) #define TB_KEY_ARROW_RIGHT (0xFFFF-21) #define TB_KEY_MOUSE_LEFT (0xFFFF-22) #define TB_KEY_MOUSE_RIGHT (0xFFFF-23) #define TB_KEY_MOUSE_MIDDLE (0xFFFF-24) #define TB_KEY_MOUSE_RELEASE (0xFFFF-25) #define TB_KEY_MOUSE_WHEEL_UP (0xFFFF-26) #define TB_KEY_MOUSE_WHEEL_DOWN (0xFFFF-27) #define TB_KEY_START_PASTE (0xFFFF-28) #define TB_KEY_END_PASTE (0xFFFF-29) #define TB_KEY_CTRL_ARROW_UP (0xFFFF-30) #define TB_KEY_CTRL_ARROW_DOWN (0xFFFF-31) #define TB_KEY_CTRL_ARROW_LEFT (0xFFFF-32) #define TB_KEY_CTRL_ARROW_RIGHT (0xFFFF-33) #define TB_KEY_SHIFT_TAB (0xFFFF-34) /* Names for some of the possible values for tb_event.ch. */ /* These are all ASCII code points below SPACE character and a BACKSPACE key. */ #define TB_KEY_CTRL_TILDE 0x00 #define TB_KEY_CTRL_2 0x00 /* clash with 'CTRL_TILDE' */ #define TB_KEY_CTRL_A 0x01 #define TB_KEY_CTRL_B 0x02 #define TB_KEY_CTRL_C