💾 Archived View for gemini.rmf-dev.com › repo › Vaati › tuimarket › files › d76a9705135c97d8e27edd2a… captured on 2023-04-26 at 13:29:48. Gemini links have been rewritten to link to archived content

View Raw

More Information

➡️ Next capture (2023-09-08)

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

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 #define TB_BLACK 0x0001

169 #define TB_RED 0x0002

170 #define TB_GREEN 0x0003

171 #define TB_YELLOW 0x0004

172 #define TB_BLUE 0x0005

173 #define TB_MAGENTA 0x0006

174 #define TB_CYAN 0x0007

175 #define TB_WHITE 0x0008

176 #define TB_BOLD 0x0100

177 #define TB_UNDERLINE 0x0200

178 #define TB_REVERSE 0x0400

179 #define TB_ITALIC 0x0800

180 #define TB_BLINK 0x1000

181 #define TB_DEFAULT 0x2000

182 #ifdef TB_OPT_TRUECOLOR

183 #define TB_TRUECOLOR_BOLD 0x01000000

184 #define TB_TRUECOLOR_UNDERLINE 0x02000000

185 #define TB_TRUECOLOR_REVERSE 0x04000000

186 #define TB_TRUECOLOR_ITALIC 0x08000000

187 #define TB_TRUECOLOR_BLINK 0x10000000

188 #define TB_TRUECOLOR_DEFAULT 0x20000000

189 #endif

190

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

192 #define TB_EVENT_KEY 1

193 #define TB_EVENT_RESIZE 2

194 #define TB_EVENT_MOUSE 3

195

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

197 #define TB_MOD_ALT 1

198 #define TB_MOD_CTRL 2

199 #define TB_MOD_SHIFT 4

200 #define TB_MOD_MOTION 8

201

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

203 #define TB_INPUT_CURRENT 0

204 #define TB_INPUT_ESC 1

205 #define TB_INPUT_ALT 2

206 #define TB_INPUT_MOUSE 4

207

208 /* Output modes (tb_set_output_mode) */

209 #define TB_OUTPUT_CURRENT 0

210 #define TB_OUTPUT_NORMAL 1

211 #define TB_OUTPUT_256 2

212 #define TB_OUTPUT_216 3

213 #define TB_OUTPUT_GRAYSCALE 4

214 #ifdef TB_OPT_TRUECOLOR

215 #define TB_OUTPUT_TRUECOLOR 5

216 #endif

217

218 /* Common function return values unless otherwise noted.

219 *

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

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

222 * tb_init.

223 */

224 #define TB_OK 0

225 #define TB_ERR -1

226 #define TB_ERR_NEED_MORE -2

227 #define TB_ERR_INIT_ALREADY -3

228 #define TB_ERR_INIT_OPEN -4

229 #define TB_ERR_MEM -5

230 #define TB_ERR_NO_EVENT -6

231 #define TB_ERR_NO_TERM -7

232 #define TB_ERR_NOT_INIT -8

233 #define TB_ERR_OUT_OF_BOUNDS -9

234 #define TB_ERR_READ -10

235 #define TB_ERR_RESIZE_IOCTL -11

236 #define TB_ERR_RESIZE_PIPE -12

237 #define TB_ERR_RESIZE_SIGACTION -13

238 #define TB_ERR_POLL -14

239 #define TB_ERR_TCGETATTR -15

240 #define TB_ERR_TCSETATTR -16

241 #define TB_ERR_UNSUPPORTED_TERM -17

242 #define TB_ERR_RESIZE_WRITE -18

243 #define TB_ERR_RESIZE_POLL -19

244 #define TB_ERR_RESIZE_READ -20

245 #define TB_ERR_RESIZE_SSCANF -21

246 #define TB_ERR_CAP_COLLISION -22

247

248 #define TB_ERR_SELECT TB_ERR_POLL

249 #define TB_ERR_RESIZE_SELECT TB_ERR_RESIZE_POLL

250

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

252 #define TB_FUNC_EXTRACT_PRE 0

253 #define TB_FUNC_EXTRACT_POST 1

254

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

256 * and tb_sendf()

257 */

258 #ifndef TB_OPT_PRINTF_BUF

259 #define TB_OPT_PRINTF_BUF 4096

260 #endif

261

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

263 * from the tty

264 */

265 #ifndef TB_OPT_READ_BUF

266 #define TB_OPT_READ_BUF 64

267 #endif

268

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

270 #ifdef TB_OPT_V1_COMPAT

271 #define tb_change_cell tb_set_cell

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

273 #define tb_set_clear_attributes tb_set_clear_attrs

274 #define tb_select_input_mode tb_set_input_mode

275 #define tb_select_output_mode tb_set_output_mode

276 #endif

277

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

279 #ifndef tb_malloc

280 #define tb_malloc malloc

281 #define tb_realloc realloc

282 #define tb_free free

283 #endif

284

285 #ifdef TB_OPT_TRUECOLOR

286 typedef uint32_t uintattr_t;

287 #else

288 typedef uint16_t uintattr_t;

289 #endif

290

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

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

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

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

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

296 * used.

297 *

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

299 *

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

301 * if aiming to render text accurately.

302 *

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

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

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

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

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

308 * instead.

309 *

310 * See tb_present() for implementation.

311 */

312 struct tb_cell {

313 uint32_t ch; /* a Unicode character */

314 uintattr_t fg; /* bitwise foreground attributes */

315 uintattr_t bg; /* bitwise background attributes */

316 #ifdef TB_OPT_EGC

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

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

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

320 #endif

321 };

322

323 /* An incoming event from the tty.

324 *

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

326 *

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

328 * overlap between TB_MOD_CTRL and TB_KEY_CTRL_*.

329 * TB_MOD_CTRL and TB_MOD_SHIFT are only set as

330 * modifiers to TB_KEY_ARROW_*.

331 *

332 * when TB_EVENT_RESIZE: w, h

333 *

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

335 */

336 struct tb_event {

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

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

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

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

341 int32_t w; /* resize width */

342 int32_t h; /* resize height */

343 int32_t x; /* mouse x */

344 int32_t y; /* mouse y */

345 };

346

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

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

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

350 * tb_shutdown() function.

351 */

352 int tb_init(void);

353 int tb_init_file(const char *path);

354 int tb_init_fd(int ttyfd);

355 int tb_init_rwfd(int rfd, int wfd);

356 int tb_shutdown(void);

357

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

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

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

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

362 * tb_shutdown().

363 */

364 int tb_width(void);

365 int tb_height(void);

366

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

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

369 */

370 int tb_clear(void);

371 int tb_set_clear_attrs(uintattr_t fg, uintattr_t bg);

372

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

374 int tb_present(void);

375

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

377 int tb_set_cursor(int cx, int cy);

378 int tb_hide_cursor(void);

379

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

381 *

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

383 * diacritical marks).

384 *

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

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

387 *

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

389 * cell->ech.

390 */

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

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

393 uintattr_t bg);

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

395

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

397 *

398 * 1. TB_INPUT_ESC

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

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

401 *

402 * 2. TB_INPUT_ALT

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

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

405 *

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

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

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

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

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

411 * TB_INPUT_ESC was selected.

412 *

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

414 *

415 * The default input mode is TB_INPUT_ESC.

416 */

417 int tb_set_input_mode(int mode);

418

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

420 *

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

422 *

423 * This mode provides 8 different colors:

424 * TB_BLACK, TB_RED, TB_GREEN, TB_YELLOW,

425 * TB_BLUE, TB_MAGENTA, TB_CYAN, TB_WHITE

426 *

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

428 * terminal's default color).

429 *

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

431 * TB_BOLD, TB_UNDERLINE, TB_REVERSE, TB_ITALIC, TB_BLINK

432 *

433 * The value 0 is interpreted as TB_DEFAULT.

434 *

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

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

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

438 *

439 * Example usage:

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

441 *

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

443 *

444 * In this mode you get 256 distinct colors:

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

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

447 * 0x10 - 0xe7: 216 different colors

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

449 *

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

451 *

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

453 * default colors.

454 *

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

456 *

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

458 * need to provide an offset.

459 *

460 * The value 0 is interpreted as TB_DEFAULT.

461 *

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

463 *

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

465 * need to provide an offset.

466 *

467 * The value 0 is interpreted as TB_DEFAULT.

468 *

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

470 *

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

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

473 *

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

475 * used for default colors.

476 *

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

478 *

479 * The default output mode is TB_OUTPUT_NORMAL.

480 *

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

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

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

484 * TB_OUTPUT_216, and TB_OUTPUT_GRAYSCALE.

485 *

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

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

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

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

490 */

491 int tb_set_output_mode(int mode);

492

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

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

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

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

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

498 * and call tb_peek_event() again.

499 */

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

501

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

503 int tb_poll_event(struct tb_event *event);

504

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

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

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

508

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

510 * string.

511 */

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

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

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

515 const char *str);

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

517 const char *fmt, ...);

518

519 /* Send raw bytes to terminal. */

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

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

522

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

524 * compatible function pointer, or NULL to clear.

525 *

526 * TB_FUNC_EXTRACT_PRE:

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

528 * escape sequences from the input buffer.

529 *

530 * TB_FUNC_EXTRACT_POST:

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

532 * extract any escape sequences from the input buffer.

533 */

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

535

536 /* Utility functions. */

537 int tb_utf8_char_length(char c);

538 int tb_utf8_char_to_unicode(uint32_t *out, const char *c);

539 int tb_utf8_unicode_to_char(char *out, uint32_t c);

540 int tb_last_errno(void);

541 const char *tb_strerror(int err);

542 struct tb_cell *tb_cell_buffer(void);

543 int tb_has_truecolor(void);

544 int tb_has_egc(void);

545 const char *tb_version(void);

546

547 #endif /* __TERMBOX_H */

548