💾 Archived View for gemini.rmf-dev.com › repo › Vaati › Vgmi › files › 240f45ea5ed246ea5839a3757ede6… captured on 2023-12-28 at 15:45:54. Gemini links have been rewritten to link to archived content

View Raw

More Information

-=-=-=-=-=-=-

Go Back

0 /*

1 MIT License

2

3 Copyright (c) 2010-2020 nsf <no.smile.face@gmail.com>

4 2015-2022 Adam Saponara <as@php.net>

5

6 Permission is hereby granted, free of charge, to any person obtaining a copy

7 of this software and associated documentation files (the "Software"), to deal

8 in the Software without restriction, including without limitation the rights

9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

10 copies of the Software, and to permit persons to whom the Software is

11 furnished to do so, subject to the following conditions:

12

13 The above copyright notice and this permission notice shall be included in all

14 copies or substantial portions of the Software.

15

16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER

20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,

21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE

22 SOFTWARE.

23 */

24

25 #ifndef __TERMBOX_H

26 #define __TERMBOX_H

27

28 /* __ffi_start */

29

30 #define TB_VERSION_STR "2.1.0-dev"

31

32 #if defined(TB_LIB_OPTS) || 0 /* __tb_lib_opts */

33 /* Ensure consistent compile-time options when using as a library */

34 #undef TB_OPT_TRUECOLOR

35 #undef TB_OPT_EGC

36 #undef TB_OPT_PRINTF_BUF

37 #undef TB_OPT_READ_BUF

38 #define TB_OPT_TRUECOLOR

39 #define TB_OPT_EGC

40 #endif

41

42 /* ASCII key constants (tb_event.key) */

43 #define TB_KEY_CTRL_TILDE 0x00

44 #define TB_KEY_CTRL_2 0x00 /* clash with 'CTRL_TILDE' */

45 #define TB_KEY_CTRL_A 0x01

46 #define TB_KEY_CTRL_B 0x02

47 #define TB_KEY_CTRL_C 0x03

48 #define TB_KEY_CTRL_D 0x04

49 #define TB_KEY_CTRL_E 0x05

50 #define TB_KEY_CTRL_F 0x06

51 #define TB_KEY_CTRL_G 0x07

52 #define TB_KEY_BACKSPACE 0x08

53 #define TB_KEY_CTRL_H 0x08 /* clash with 'CTRL_BACKSPACE' */

54 #define TB_KEY_TAB 0x09

55 #define TB_KEY_CTRL_I 0x09 /* clash with 'TAB' */

56 #define TB_KEY_CTRL_J 0x0a

57 #define TB_KEY_CTRL_K 0x0b

58 #define TB_KEY_CTRL_L 0x0c

59 #define TB_KEY_ENTER 0x0d

60 #define TB_KEY_CTRL_M 0x0d /* clash with 'ENTER' */

61 #define TB_KEY_CTRL_N 0x0e

62 #define TB_KEY_CTRL_O 0x0f

63 #define TB_KEY_CTRL_P 0x10

64 #define TB_KEY_CTRL_Q 0x11

65 #define TB_KEY_CTRL_R 0x12

66 #define TB_KEY_CTRL_S 0x13

67 #define TB_KEY_CTRL_T 0x14

68 #define TB_KEY_CTRL_U 0x15

69 #define TB_KEY_CTRL_V 0x16

70 #define TB_KEY_CTRL_W 0x17

71 #define TB_KEY_CTRL_X 0x18

72 #define TB_KEY_CTRL_Y 0x19

73 #define TB_KEY_CTRL_Z 0x1a

74 #define TB_KEY_ESC 0x1b

75 #define TB_KEY_CTRL_LSQ_BRACKET 0x1b /* clash with 'ESC' */

76 #define TB_KEY_CTRL_3 0x1b /* clash with 'ESC' */

77 #define TB_KEY_CTRL_4 0x1c

78 #define TB_KEY_CTRL_BACKSLASH 0x1c /* clash with 'CTRL_4' */

79 #define TB_KEY_CTRL_5 0x1d

80 #define TB_KEY_CTRL_RSQ_BRACKET 0x1d /* clash with 'CTRL_5' */

81 #define TB_KEY_CTRL_6 0x1e

82 #define TB_KEY_CTRL_7 0x1f

83 #define TB_KEY_CTRL_SLASH 0x1f /* clash with 'CTRL_7' */

84 #define TB_KEY_CTRL_UNDERSCORE 0x1f /* clash with 'CTRL_7' */

85 #define TB_KEY_SPACE 0x20

86 #define TB_KEY_BACKSPACE2 0x7f

87 #define TB_KEY_CTRL_8 0x7f /* clash with 'BACKSPACE2' */

88

89 #define tb_key_i(i) 0xffff - (i)

90 /* Terminal-dependent key constants (tb_event.key) and terminfo capabilities */

91 /* BEGIN codegen h */

92 /* Produced by ./codegen.sh on Sun, 19 Sep 2021 01:02:02 +0000 */

93 #define TB_KEY_F1 (0xffff - 0)

94 #define TB_KEY_F2 (0xffff - 1)

95 #define TB_KEY_F3 (0xffff - 2)

96 #define TB_KEY_F4 (0xffff - 3)

97 #define TB_KEY_F5 (0xffff - 4)

98 #define TB_KEY_F6 (0xffff - 5)

99 #define TB_KEY_F7 (0xffff - 6)

100 #define TB_KEY_F8 (0xffff - 7)

101 #define TB_KEY_F9 (0xffff - 8)

102 #define TB_KEY_F10 (0xffff - 9)

103 #define TB_KEY_F11 (0xffff - 10)

104 #define TB_KEY_F12 (0xffff - 11)

105 #define TB_KEY_INSERT (0xffff - 12)

106 #define TB_KEY_DELETE (0xffff - 13)

107 #define TB_KEY_HOME (0xffff - 14)

108 #define TB_KEY_END (0xffff - 15)

109 #define TB_KEY_PGUP (0xffff - 16)

110 #define TB_KEY_PGDN (0xffff - 17)

111 #define TB_KEY_ARROW_UP (0xffff - 18)

112 #define TB_KEY_ARROW_DOWN (0xffff - 19)

113 #define TB_KEY_ARROW_LEFT (0xffff - 20)

114 #define TB_KEY_ARROW_RIGHT (0xffff - 21)

115 #define TB_KEY_BACK_TAB (0xffff - 22)

116 #define TB_KEY_MOUSE_LEFT (0xffff - 23)

117 #define TB_KEY_MOUSE_RIGHT (0xffff - 24)

118 #define TB_KEY_MOUSE_MIDDLE (0xffff - 25)

119 #define TB_KEY_MOUSE_RELEASE (0xffff - 26)

120 #define TB_KEY_MOUSE_WHEEL_UP (0xffff - 27)

121 #define TB_KEY_MOUSE_WHEEL_DOWN (0xffff - 28)

122

123 #define TB_CAP_F1 0

124 #define TB_CAP_F2 1

125 #define TB_CAP_F3 2

126 #define TB_CAP_F4 3

127 #define TB_CAP_F5 4

128 #define TB_CAP_F6 5

129 #define TB_CAP_F7 6

130 #define TB_CAP_F8 7

131 #define TB_CAP_F9 8

132 #define TB_CAP_F10 9

133 #define TB_CAP_F11 10

134 #define TB_CAP_F12 11

135 #define TB_CAP_INSERT 12

136 #define TB_CAP_DELETE 13

137 #define TB_CAP_HOME 14

138 #define TB_CAP_END 15

139 #define TB_CAP_PGUP 16

140 #define TB_CAP_PGDN 17

141 #define TB_CAP_ARROW_UP 18

142 #define TB_CAP_ARROW_DOWN 19

143 #define TB_CAP_ARROW_LEFT 20

144 #define TB_CAP_ARROW_RIGHT 21

145 #define TB_CAP_BACK_TAB 22

146 #define TB_CAP__COUNT_KEYS 23

147 #define TB_CAP_ENTER_CA 23

148 #define TB_CAP_EXIT_CA 24

149 #define TB_CAP_SHOW_CURSOR 25

150 #define TB_CAP_HIDE_CURSOR 26

151 #define TB_CAP_CLEAR_SCREEN 27

152 #define TB_CAP_SGR0 28

153 #define TB_CAP_UNDERLINE 29

154 #define TB_CAP_BOLD 30

155 #define TB_CAP_BLINK 31

156 #define TB_CAP_ITALIC 32

157 #define TB_CAP_REVERSE 33

158 #define TB_CAP_ENTER_KEYPAD 34

159 #define TB_CAP_EXIT_KEYPAD 35

160 #define TB_CAP__COUNT 36

161 /* END codegen h */

162

163 /* Some hard-coded caps */

164 #define TB_HARDCAP_ENTER_MOUSE "\x1b[?1000h\x1b[?1002h\x1b[?1015h\x1b[?1006h"

165 #define TB_HARDCAP_EXIT_MOUSE "\x1b[?1006l\x1b[?1015l\x1b[?1002l\x1b[?1000l"

166

167 /* Colors (numeric) and attributes (bitwise) (tb_cell.fg, tb_cell.bg) */

168 #if __has_include(<stb_image.h>)

169 #define TB_BLACK 0x0010

170 #define TB_RED 0x0009

171 #define TB_GREEN 0x0002

172 #define TB_YELLOW 0x000B

173 #define TB_BLUE 0x000C

174 #define TB_MAGENTA 0x000D

175 #define TB_CYAN 0x000E

176 #define TB_WHITE 0x000F

177 #else

178 #define TB_BLACK 0x0001

179 #define TB_RED 0x0002

180 #define TB_GREEN 0x0003

181 #define TB_YELLOW 0x0004

182 #define TB_BLUE 0x0005

183 #define TB_MAGENTA 0x0006

184 #define TB_CYAN 0x0007

185 #define TB_WHITE 0x0008

186 #endif

187 #define TB_BOLD 0x0100

188 #define TB_UNDERLINE 0x0200

189 #define TB_REVERSE 0x0400

190 #define TB_ITALIC 0x0800

191 #define TB_BLINK 0x1000

192 #define TB_DEFAULT 0x2000

193 #ifdef TB_OPT_TRUECOLOR

194 #define TB_TRUECOLOR_BOLD 0x01000000

195 #define TB_TRUECOLOR_UNDERLINE 0x02000000

196 #define TB_TRUECOLOR_REVERSE 0x04000000

197 #define TB_TRUECOLOR_ITALIC 0x08000000

198 #define TB_TRUECOLOR_BLINK 0x10000000

199 #define TB_TRUECOLOR_DEFAULT 0x20000000

200 #endif

201

202 /* Event types (tb_event.type) */

203 #define TB_EVENT_KEY 1

204 #define TB_EVENT_RESIZE 2

205 #define TB_EVENT_MOUSE 3

206

207 /* Key modifiers (bitwise) (tb_event.mod) */

208 #define TB_MOD_ALT 1

209 #define TB_MOD_CTRL 2

210 #define TB_MOD_SHIFT 4

211 #define TB_MOD_MOTION 8

212

213 /* Input modes (bitwise) (tb_set_input_mode) */

214 #define TB_INPUT_CURRENT 0

215 #define TB_INPUT_ESC 1

216 #define TB_INPUT_ALT 2

217 #define TB_INPUT_MOUSE 4

218

219 /* Output modes (tb_set_output_mode) */

220 #define TB_OUTPUT_CURRENT 0

221 #define TB_OUTPUT_NORMAL 1

222 #define TB_OUTPUT_256 2

223 #define TB_OUTPUT_216 3

224 #define TB_OUTPUT_GRAYSCALE 4

225 #ifdef TB_OPT_TRUECOLOR

226 #define TB_OUTPUT_TRUECOLOR 5

227 #endif

228

229 /* Common function return values unless otherwise noted.

230 *

231 * Library behavior is undefined after receiving TB_ERR_MEM. Callers may

232 * attempt reinitializing by freeing memory, invoking tb_shutdown, then

233 * tb_init.

234 */

235 #define TB_OK 0

236 #define TB_ERR -1

237 #define TB_ERR_NEED_MORE -2

238 #define TB_ERR_INIT_ALREADY -3

239 #define TB_ERR_INIT_OPEN -4

240 #define TB_ERR_MEM -5

241 #define TB_ERR_NO_EVENT -6

242 #define TB_ERR_NO_TERM -7

243 #define TB_ERR_NOT_INIT -8

244 #define TB_ERR_OUT_OF_BOUNDS -9

245 #define TB_ERR_READ -10

246 #define TB_ERR_RESIZE_IOCTL -11

247 #define TB_ERR_RESIZE_PIPE -12

248 #define TB_ERR_RESIZE_SIGACTION -13

249 #define TB_ERR_POLL -14

250 #define TB_ERR_TCGETATTR -15

251 #define TB_ERR_TCSETATTR -16

252 #define TB_ERR_UNSUPPORTED_TERM -17

253 #define TB_ERR_RESIZE_WRITE -18

254 #define TB_ERR_RESIZE_POLL -19

255 #define TB_ERR_RESIZE_READ -20

256 #define TB_ERR_RESIZE_SSCANF -21

257 #define TB_ERR_CAP_COLLISION -22

258

259 #define TB_ERR_SELECT TB_ERR_POLL

260 #define TB_ERR_RESIZE_SELECT TB_ERR_RESIZE_POLL

261

262 /* Function types to be used with tb_set_func() */

263 #define TB_FUNC_EXTRACT_PRE 0

264 #define TB_FUNC_EXTRACT_POST 1

265

266 /* Define this to set the size of the buffer used in tb_printf()

267 * and tb_sendf()

268 */

269 #ifndef TB_OPT_PRINTF_BUF

270 #define TB_OPT_PRINTF_BUF 4096

271 #endif

272

273 /* Define this to set the size of the read buffer used when reading

274 * from the tty

275 */

276 #ifndef TB_OPT_READ_BUF

277 #define TB_OPT_READ_BUF 64

278 #endif

279

280 /* Define this for limited back compat with termbox v1 */

281 #ifdef TB_OPT_V1_COMPAT

282 #define tb_change_cell tb_set_cell

283 #define tb_put_cell(x, y, c) tb_set_cell((x), (y), (c)->ch, (c)->fg, (c)->bg)

284 #define tb_set_clear_attributes tb_set_clear_attrs

285 #define tb_select_input_mode tb_set_input_mode

286 #define tb_select_output_mode tb_set_output_mode

287 #endif

288

289 /* Define these to swap in a different allocator */

290 #ifndef tb_malloc

291 #define tb_malloc malloc

292 #define tb_realloc realloc

293 #define tb_free free

294 #endif

295

296 #ifdef TB_OPT_TRUECOLOR

297 typedef uint32_t uintattr_t;

298 #else

299 typedef uint16_t uintattr_t;

300 #endif

301

302 /* The terminal screen is represented as 2d array of cells. The structure is

303 * optimized for dealing with single-width (wcwidth()==1) Unicode code points,

304 * however some support for grapheme clusters (e.g., combining diacritical

305 * marks) and wide code points (e.g., Hiragana) is provided through ech, nech,

306 * cech via tb_set_cell_ex(). ech is only valid when nech>0, otherwise ch is

307 * used.

308 *

309 * For non-single-width code points, given N=wcwidth(ch)/wcswidth(ech):

310 *

311 * when N==0: termbox forces a single-width cell. Callers should avoid this

312 * if aiming to render text accurately.

313 *

314 * when N>1: termbox zeroes out the following N-1 cells and skips sending

315 * them to the tty. So, e.g., if the caller sets x=0,y=0 to an N==2

316 * code point, the caller's next set should be at x=2,y=0. Anything

317 * set at x=1,y=0 will be ignored. If there are not enough columns

318 * remaining on the line to render N width, spaces are sent

319 * instead.

320 *

321 * See tb_present() for implementation.

322 */

323 struct tb_cell {

324 uint32_t ch; /* a Unicode character */

325 uintattr_t fg; /* bitwise foreground attributes */

326 uintattr_t bg; /* bitwise background attributes */

327 #ifdef TB_OPT_EGC

328 uint32_t *ech; /* a grapheme cluster of Unicode code points */

329 size_t nech; /* length in bytes of ech, 0 means use ch instead of ech */

330 size_t cech; /* capacity in bytes of ech */

331 #endif

332 };

333

334 /* An incoming event from the tty.

335 *

336 * Given the event type, the following fields are relevant:

337 *

338 * when TB_EVENT_KEY: (key XOR ch, one will be zero), mod. Note there is

339 * overlap between TB_MOD_CTRL and TB_KEY_CTRL_*.

340 * TB_MOD_CTRL and TB_MOD_SHIFT are only set as

341 * modifiers to TB_KEY_ARROW_*.

342 *

343 * when TB_EVENT_RESIZE: w, h

344 *

345 * when TB_EVENT_MOUSE: key (TB_KEY_MOUSE_*), x, y

346 */

347 struct tb_event {

348 uint8_t type; /* one of TB_EVENT_* constants */

349 uint8_t mod; /* bitwise TB_MOD_* constants */

350 uint16_t key; /* one of TB_KEY_* constants */

351 uint32_t ch; /* a Unicode code point */

352 int32_t w; /* resize width */

353 int32_t h; /* resize height */

354 int32_t x; /* mouse x */

355 int32_t y; /* mouse y */

356 };

357

358 /* Initializes the termbox library. This function should be called before any

359 * other functions. tb_init() is equivalent to tb_init_file("/dev/tty"). After

360 * successful initialization, the library must be finalized using the

361 * tb_shutdown() function.

362 */

363 int tb_init(void);

364 int tb_init_file(const char *path);

365 int tb_init_fd(int ttyfd);

366 int tb_init_rwfd(int rfd, int wfd);

367 int tb_shutdown(void);

368

369 /* Returns the size of the internal back buffer (which is the same as terminal's

370 * window size in rows and columns). The internal buffer can be resized after

371 * tb_clear() or tb_present() function calls. Both dimensions have an

372 * unspecified negative value when called before tb_init() or after

373 * tb_shutdown().

374 */

375 int tb_width(void);

376 int tb_height(void);

377

378 /* Clears the internal back buffer using TB_DEFAULT color or the

379 * color/attributes set by tb_set_clear_attrs() function.

380 */

381 int tb_clear(void);

382 int tb_set_clear_attrs(uintattr_t fg, uintattr_t bg);

383

384 /* Synchronizes the internal back buffer with the terminal by writing to tty. */

385 int tb_present(void);

386

387 /* Sets the position of the cursor. Upper-left character is (0, 0). */

388 int tb_set_cursor(int cx, int cy);

389 int tb_hide_cursor(void);

390

391 /* Set cell contents in the internal back buffer at the specified position.

392 *

393 * Use tb_set_cell_ex() for rendering grapheme clusters (e.g., combining

394 * diacritical marks).

395 *

396 * Function tb_set_cell(x, y, ch, fg, bg) is equivalent to

397 * tb_set_cell_ex(x, y, &ch, 1, fg, bg).

398 *

399 * Function tb_extend_cell() is a shortcut for appending 1 code point to

400 * cell->ech.

401 */

402 int tb_set_cell(int x, int y, uint32_t ch, uintattr_t fg, uintattr_t bg);

403 int tb_set_cell_ex(int x, int y, uint32_t *ch, size_t nch, uintattr_t fg,

404 uintattr_t bg);

405 int tb_extend_cell(int x, int y, uint32_t ch);

406

407 /* Sets the input mode. Termbox has two input modes:

408 *

409 * 1. TB_INPUT_ESC

410 * When escape (\x1b) is in the buffer and there's no match for an escape

411 * sequence, a key event for TB_KEY_ESC is returned.

412 *

413 * 2. TB_INPUT_ALT

414 * When escape (\x1b) is in the buffer and there's no match for an escape

415 * sequence, the next keyboard event is returned with a TB_MOD_ALT modifier.

416 *

417 * You can also apply TB_INPUT_MOUSE via bitwise OR operation to either of the

418 * modes (e.g., TB_INPUT_ESC | TB_INPUT_MOUSE) to receive TB_EVENT_MOUSE events.

419 * If none of the main two modes were set, but the mouse mode was, TB_INPUT_ESC

420 * mode is used. If for some reason you've decided to use

421 * (TB_INPUT_ESC | TB_INPUT_ALT) combination, it will behave as if only

422 * TB_INPUT_ESC was selected.

423 *

424 * If mode is TB_INPUT_CURRENT, the function returns the current input mode.

425 *

426 * The default input mode is TB_INPUT_ESC.

427 */

428 int tb_set_input_mode(int mode);

429

430 /* Sets the termbox output mode. Termbox has multiple output modes:

431 *

432 * 1. TB_OUTPUT_NORMAL => [0..8]

433 *

434 * This mode provides 8 different colors:

435 * TB_BLACK, TB_RED, TB_GREEN, TB_YELLOW,

436 * TB_BLUE, TB_MAGENTA, TB_CYAN, TB_WHITE

437 *

438 * Plus TB_DEFAULT which skips sending a color code (i.e., uses the

439 * terminal's default color).

440 *

441 * Colors (including TB_DEFAULT) may be bitwise OR'd with attributes:

442 * TB_BOLD, TB_UNDERLINE, TB_REVERSE, TB_ITALIC, TB_BLINK

443 *

444 * The value 0 is interpreted as TB_DEFAULT.

445 *

446 * Some notes: TB_REVERSE can be applied as either fg or bg attributes for

447 * the same effect. TB_BOLD, TB_UNDERLINE, TB_ITALIC, TB_BLINK apply as fg

448 * attributes only, and are ignored as bg attributes.

449 *

450 * Example usage:

451 * tb_set_cell(x, y, '@', TB_BLACK | TB_BOLD, TB_RED);

452 *

453 * 2. TB_OUTPUT_256 => [0..255]

454 *

455 * In this mode you get 256 distinct colors:

456 * 0x00 - 0x07: the 8 colors as in TB_OUTPUT_NORMAL

457 * 0x08 - 0x0f: bright versions of the above

458 * 0x10 - 0xe7: 216 different colors

459 * 0xe8 - 0xff: 24 different shades of grey

460 *

461 * Attributes may be bitwise OR'd as in TB_OUTPUT_NORMAL.

462 *

463 * In this mode 0x00 represents TB_BLACK, so TB_DEFAULT must be used for

464 * default colors.

465 *

466 * 3. TB_OUTPUT_216 => [0..216]

467 *

468 * This mode supports the 3rd range of TB_OUTPUT_256 only, but you don't

469 * need to provide an offset.

470 *

471 * The value 0 is interpreted as TB_DEFAULT.

472 *

473 * 4. TB_OUTPUT_GRAYSCALE => [0..24]

474 *

475 * This mode supports the 4th range of TB_OUTPUT_256 only, but you don't

476 * need to provide an offset.

477 *

478 * The value 0 is interpreted as TB_DEFAULT.

479 *

480 * 5. TB_OUTPUT_TRUECOLOR => [0x000000..0xffffff]

481 *

482 * This mode provides 24-bit color on supported terminals. The format is

483 * 0xRRGGBB. Colors may be bitwise OR'd with `TB_TRUECOLOR_*` attributes.

484 *

485 * In this mode 0x000000 represents black, so TB_TRUECOLOR_DEFAULT must be

486 * used for default colors.

487 *

488 * If mode is TB_OUTPUT_CURRENT, the function returns the current output mode.

489 *

490 * The default output mode is TB_OUTPUT_NORMAL.

491 *

492 * To use the terminal default color (i.e., to not send an escape code), pass

493 * TB_DEFAULT (or TB_TRUECOLOR_DEFAULT in TB_OUTPUT_TRUECOLOR mode). For

494 * convenience, the value 0 is interpreted as TB_DEFAULT in TB_OUTPUT_NORMAL,

495 * TB_OUTPUT_216, and TB_OUTPUT_GRAYSCALE.

496 *

497 * Note, not all terminals support all output modes, especially beyond

498 * TB_OUTPUT_NORMAL. There is also no very reliable way to determine color

499 * support dynamically. If portability is desired, callers are recommended to

500 * use TB_OUTPUT_NORMAL or make output mode end-user configurable.

501 */

502 int tb_set_output_mode(int mode);

503

504 /* Wait for an event up to timeout_ms milliseconds and fill the event structure

505 * with it. If no event is available within the timeout period, TB_ERR_NO_EVENT

506 * is returned. On a resize event, the underlying select(2) call may be

507 * interrupted, yielding a return code of TB_ERR_POLL. In this case, you may

508 * check errno via tb_last_errno(). If it's EINTR, you can safely ignore that

509 * and call tb_peek_event() again.

510 */

511 int tb_peek_event(struct tb_event *event, int timeout_ms);

512

513 /* Same as tb_peek_event except no timeout. */

514 int tb_poll_event(struct tb_event *event);

515

516 /* Internal termbox FDs that can be used with poll() / select(). Must call

517 * tb_poll_event() / tb_peek_event() if activity is detected. */

518 int tb_get_fds(int *ttyfd, int *resizefd);

519

520 /* Print and printf functions. Specify param out_w to determine width of printed

521 * string.

522 */

523 int tb_print(int x, int y, uintattr_t fg, uintattr_t bg, const char *str);

524 int tb_printf(int x, int y, uintattr_t fg, uintattr_t bg, const char *fmt, ...);

525 int tb_print_ex(int x, int y, uintattr_t fg, uintattr_t bg, size_t *out_w,

526 const char *str);

527 int tb_printf_ex(int x, int y, uintattr_t fg, uintattr_t bg, size_t *out_w,

528 const char *fmt, ...);

529

530 /* Send raw bytes to terminal. */

531 int tb_send(const char *buf, size_t nbuf);

532 int tb_sendf(const char *fmt, ...);

533

534 /* Set custom functions. fn_type is one of TB_FUNC_* constants, fn is a

535 * compatible function pointer, or NULL to clear.

536 *

537 * TB_FUNC_EXTRACT_PRE:

538 * If specified, invoke this function BEFORE termbox tries to extract any

539 * escape sequences from the input buffer.

540 *

541 * TB_FUNC_EXTRACT_POST:

542 * If specified, invoke this function AFTER termbox tries (and fails) to

543 * extract any escape sequences from the input buffer.

544 */

545 int tb_set_func(int fn_type, int (*fn)(struct tb_event *, size_t *));

546

547 /* Utility functions. */

548 int tb_last_errno(void);

549 const char *tb_strerror(int err);

550 struct tb_cell *tb_cell_buffer(void);

551 int tb_has_truecolor(void);

552 int tb_has_egc(void);

553 const char *tb_version(void);

554 int tb_refresh();

555

556 #endif /* __TERMBOX_H */

557