Skip to content

Commit 206fffd

Browse files
committed
adjust whitespace and comments
1 parent 9154e1d commit 206fffd

1 file changed

Lines changed: 78 additions & 76 deletions

File tree

termbox2.h

Lines changed: 78 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -66,30 +66,32 @@ extern "C" {
6666

6767
/* The following compile-time options are supported:
6868
*
69-
* TB_OPT_ATTR_W: Integer width of `fg` and `bg` attributes. Valid values
70-
* (assuming system support) are 16, 32, and 64. (See
71-
* `uintattr_t`). 32 or 64 enables output mode
72-
* `TB_OUTPUT_TRUECOLOR`. 64 enables additional style
73-
* attributes. (See `tb_set_output_mode`.) Larger values
74-
* consume more memory in exchange for more features.
75-
* Defaults to 16.
69+
* `TB_OPT_ATTR_W`: Integer width of `fg` and `bg` attributes. Valid values
70+
* (assuming system support) are 16, 32, and 64. (See
71+
* `uintattr_t`). 32 or 64 enables output mode
72+
* `TB_OUTPUT_TRUECOLOR`. 64 enables additional style
73+
* attributes. (See `tb_set_output_mode`.) Larger values
74+
* consume more memory in exchange for more features.
75+
* Defaults to 16.
7676
*
77-
* TB_OPT_EGC: If set, enable extended grapheme cluster support
78-
* (`tb_extend_cell`, `tb_set_cell_ex`). Consumes more
79-
* memory. Defaults off.
77+
* `TB_OPT_EGC`: If set, enable extended grapheme cluster support
78+
* (`tb_extend_cell`, `tb_set_cell_ex`). Consumes more
79+
* memory. Defaults off.
8080
*
81-
* TB_OPT_PRINTF_BUF: Write buffer size for printf operations. Represents the
82-
* largest string that can be sent in one call to
83-
* `tb_print*` and `tb_send*` functions. Defaults to 4096.
81+
* `TB_OPT_PRINTF_BUF`: Write buffer size for printf operations. Represents the
82+
* largest string that can be sent in one call to
83+
* `tb_print*` and `tb_send*` functions. Defaults to 4096.
8484
*
85-
* TB_OPT_READ_BUF: Read buffer size for tty reads. Defaults to 64.
85+
* `TB_OPT_READ_BUF`: Read buffer size for tty reads. Defaults to 64.
8686
*
87-
* TB_OPT_LIBC_WCHAR: If set, use libc's `wcwidth(3)`, `iswprint(3)`, etc
88-
* instead of the built-in Unicode-aware versions. Note,
89-
* libc's are locale-dependent and the caller must
90-
* `setlocale(3)` `LC_CTYPE` to UTF-8. Defaults to built-in.
87+
* `TB_OPT_LIBC_WCHAR`: If set, use libc's `wcwidth(3)`, `iswprint(3)`, etc
88+
* instead of the built-in Unicode-aware versions. Note,
89+
* libc's are locale-dependent and the caller must
90+
* `setlocale(3)` `LC_CTYPE` to UTF-8. Defaults to
91+
* built-in.
9192
*
92-
* TB_OPT_TRUECOLOR: Deprecated. Sets TB_OPT_ATTR_W to 32 if not already set.
93+
* `TB_OPT_TRUECOLOR`: Deprecated. Sets TB_OPT_ATTR_W to 32 if not already
94+
* set.
9395
*/
9496

9597
#if defined(TB_LIB_OPTS) || 0 // __tb_lib_opts
@@ -362,21 +364,19 @@ extern "C" {
362364
#define TB_FUNC_EXTRACT_PRE 0
363365
#define TB_FUNC_EXTRACT_POST 1
364366

365-
/* Define this to set the size of the buffer used in `tb_printf`
366-
* and `tb_sendf`
367+
/* Define this to set the size of the buffer used in `tb_printf` and
368+
* `tb_sendf`.
367369
*/
368370
#ifndef TB_OPT_PRINTF_BUF
369371
#define TB_OPT_PRINTF_BUF 4096
370372
#endif
371373

372-
/* Define this to set the size of the read buffer used when reading
373-
* from the tty
374-
*/
374+
/* Define this to set the size of the buffer used when reading from the tty. */
375375
#ifndef TB_OPT_READ_BUF
376376
#define TB_OPT_READ_BUF 64
377377
#endif
378378

379-
/* Define this for limited back compat with termbox v1 */
379+
/* Define this for limited back compat with termbox v1. */
380380
#ifdef TB_OPT_V1_COMPAT
381381
#define tb_change_cell tb_set_cell
382382
#define tb_put_cell(x, y, c) tb_set_cell((x), (y), (c)->ch, (c)->fg, (c)->bg)
@@ -385,7 +385,7 @@ extern "C" {
385385
#define tb_select_output_mode tb_set_output_mode
386386
#endif
387387

388-
/* Define these to swap in a different allocator */
388+
/* Define these to swap in a different allocator. */
389389
#ifndef tb_malloc
390390
#define tb_malloc malloc
391391
#define tb_realloc realloc
@@ -420,8 +420,8 @@ typedef uint16_t uintattr_t;
420420
* them to the tty. So, e.g., if the caller sets `x=0,y=0` to a
421421
* `W==2` codepoint, the caller's next set should be at `x=2,y=0`.
422422
* Anything set at `x=1,y=0` will be ignored. If there are not
423-
* enough columns remaining on the line to render `W` cells, spaces
424-
* are sent instead.
423+
* enough columns remaining on the line to render `W` cells,
424+
* spaces are sent instead.
425425
*
426426
* See `tb_present` for implementation.
427427
*/
@@ -442,8 +442,8 @@ struct tb_cell {
442442
*
443443
* when `TB_EVENT_KEY`: `key` xor `ch` (one will be zero) and `mod`. Note
444444
* there is overlap between `TB_MOD_CTRL` and
445-
* `TB_KEY_CTRL_*`. `TB_MOD_CTRL` and `TB_MOD_SHIFT` are
446-
* only set as modifiers to `TB_KEY_ARROW_*`.
445+
* `TB_KEY_CTRL_*`. `TB_MOD_CTRL` and `TB_MOD_SHIFT`
446+
* are only set as modifiers to `TB_KEY_ARROW_*`.
447447
*
448448
* when `TB_EVENT_RESIZE`: `w` and `h`
449449
*
@@ -461,8 +461,9 @@ struct tb_event {
461461
};
462462

463463
/* Initialize the termbox library. This function should be called before any
464-
* other functions. `tb_init` is equivalent to `tb_init_file("/dev/tty")`. After
465-
* successful initialization, the library must be finalized using `tb_shutdown`.
464+
* other functions. `tb_init` is equivalent to `tb_init_file("/dev/tty")`.
465+
* After successful initialization, the library must be finalized using
466+
* `tb_shutdown`.
466467
*/
467468
int tb_init(void);
468469
int tb_init_file(const char *path);
@@ -507,8 +508,8 @@ int tb_hide_cursor(void);
507508
*
508509
* `tb_extend_cell` is a shortcut for appending 1 codepoint to `tb_cell.ech`.
509510
*
510-
* Non-printable (`iswprint(3)`) codepoints are replaced with `U+FFFD` at render
511-
* time.
511+
* Non-printable (`iswprint(3)`) codepoints are replaced with `U+FFFD` at
512+
* render time.
512513
*/
513514
int tb_set_cell(int x, int y, uint32_t ch, uintattr_t fg, uintattr_t bg);
514515
int tb_set_cell_ex(int x, int y, uint32_t *ch, size_t nch, uintattr_t fg,
@@ -522,8 +523,8 @@ int tb_extend_cell(int x, int y, uint32_t ch);
522523
* cell memory results in undefined behavior.
523524
*
524525
* Callers may use pointer math to access cells relative to the requested one.
525-
* The cell grid memory layout is a contiguous array indexable by the expression
526-
* `(y * width) + x`.
526+
* The cell grid memory layout is a contiguous array indexable by the
527+
* expression `(y * width) + x`.
527528
*
528529
* If `back` is non-zero, return cell from the internal back buffer. Otherwise,
529530
* return cell from the front buffer. Note the front buffer is updated on each
@@ -545,12 +546,12 @@ int tb_get_cell(int x, int y, int back, struct tb_cell **cell);
545546
* sequence, the next keyboard event is returned with a `TB_MOD_ALT`
546547
* modifier.
547548
*
548-
* You can also apply `TB_INPUT_MOUSE` via bitwise OR operation to either of the
549-
* modes (e.g., `TB_INPUT_ESC | TB_INPUT_MOUSE`) to receive `TB_EVENT_MOUSE`
550-
* events. If none of the main two modes were set, but the mouse mode was,
551-
* `TB_INPUT_ESC` is used. If for some reason you've decided to use
552-
* `TB_INPUT_ESC | TB_INPUT_ALT`, it will behave as if only `TB_INPUT_ESC` was
553-
* selected.
549+
* You can also apply `TB_INPUT_MOUSE` via bitwise OR operation to either of
550+
* the modes (e.g., `TB_INPUT_ESC | TB_INPUT_MOUSE`) to receive
551+
* `TB_EVENT_MOUSE` events. If none of the main two modes were set, but the
552+
* mouse mode was, `TB_INPUT_ESC` is used. If for some reason you've decided to
553+
* use `TB_INPUT_ESC | TB_INPUT_ALT`, it will behave as if only `TB_INPUT_ESC`
554+
* was selected.
554555
*
555556
* If mode is `TB_INPUT_CURRENT`, return the current input mode.
556557
*
@@ -623,7 +624,8 @@ int tb_set_input_mode(int mode);
623624
* All `TB_*` style attributes except `TB_BRIGHT` may be bitwise OR'd as in
624625
* `TB_OUTPUT_NORMAL`.
625626
*
626-
* Note `TB_HI_BLACK` must be used for black, as 0x000000 represents default.
627+
* Note `TB_HI_BLACK` must be used for black, as 0x000000 represents
628+
* default.
627629
*
628630
* To use the terminal default color (i.e., to not send an escape code), pass
629631
* `TB_DEFAULT`. For convenience, the value 0 is interpreted as `TB_DEFAULT` in
@@ -633,10 +635,10 @@ int tb_set_input_mode(int mode);
633635
* between, for example, `TB_OUTPUT_NORMAL`'s `TB_RED` and
634636
* `TB_OUTPUT_TRUECOLOR`'s 0xff0000 must be performed by the caller. Also note
635637
* that cells previously rendered in one mode may persist unchanged until the
636-
* front buffer is cleared (such as after a resize event) at which point it will
637-
* be re-interpreted and flushed according to the current mode. Callers may
638-
* invoke `tb_invalidate` if it is desirable to immediately re-interpret and
639-
* flush the entire screen according to the current mode.
638+
* front buffer is cleared (such as after a resize event) at which point it
639+
* will be re-interpreted and flushed according to the current mode. Callers
640+
* may invoke `tb_invalidate` if it is desirable to immediately re-interpret
641+
* and flush the entire screen according to the current mode.
640642
*
641643
* Note, not all terminals support all output modes, especially beyond
642644
* `TB_OUTPUT_NORMAL`. There is also no very reliable way to determine color
@@ -743,18 +745,18 @@ int tb_wcwidth(uint32_t ch);
743745
*
744746
* The following will be removed in version 3.x (ABI version 3):
745747
*
746-
* TB_256_BLACK (use TB_HI_BLACK)
747-
* TB_OPT_TRUECOLOR (use TB_OPT_ATTR_W)
748-
* TB_TRUECOLOR_BOLD (use TB_BOLD)
749-
* TB_TRUECOLOR_UNDERLINE (use TB_UNDERLINE)
750-
* TB_TRUECOLOR_REVERSE (use TB_REVERSE)
751-
* TB_TRUECOLOR_ITALIC (use TB_ITALIC)
752-
* TB_TRUECOLOR_BLINK (use TB_BLINK)
753-
* TB_TRUECOLOR_BLACK (use TB_HI_BLACK)
754-
* tb_cell_buffer
755-
* tb_set_func
756-
* TB_FUNC_EXTRACT_PRE
757-
* TB_FUNC_EXTRACT_POST
748+
* `TB_256_BLACK` (use `TB_HI_BLACK`)
749+
* `TB_OPT_TRUECOLOR` (use `TB_OPT_ATTR_W`)
750+
* `TB_TRUECOLOR_BOLD` (use `TB_BOLD`)
751+
* `TB_TRUECOLOR_UNDERLINE` (use `TB_UNDERLINE`)
752+
* `TB_TRUECOLOR_REVERSE` (use `TB_REVERSE`)
753+
* `TB_TRUECOLOR_ITALIC` (use `TB_ITALIC`)
754+
* `TB_TRUECOLOR_BLINK` (use `TB_BLINK`)
755+
* `TB_TRUECOLOR_BLACK` (use `TB_HI_BLACK`)
756+
* `tb_cell_buffer`
757+
* `tb_set_func`
758+
* `TB_FUNC_EXTRACT_PRE`
759+
* `TB_FUNC_EXTRACT_POST`
758760
*/
759761

760762
#ifdef __cplusplus
@@ -765,29 +767,29 @@ int tb_wcwidth(uint32_t ch);
765767

766768
#ifdef TB_IMPL
767769

768-
#define if_err_return(rv, expr) \
770+
#define if_err_return(rv, expr) \
769771
if (((rv) = (expr)) != TB_OK) return (rv)
770-
#define if_err_break(rv, expr) \
772+
#define if_err_break(rv, expr) \
771773
if (((rv) = (expr)) != TB_OK) break
772-
#define if_ok_return(rv, expr) \
774+
#define if_ok_return(rv, expr) \
773775
if (((rv) = (expr)) == TB_OK) return (rv)
774-
#define if_ok_or_need_more_return(rv, expr) \
776+
#define if_ok_or_need_more_return(rv, expr) \
775777
if (((rv) = (expr)) == TB_OK || (rv) == TB_ERR_NEED_MORE) return (rv)
776778

777-
#define send_literal(rv, a) \
779+
#define send_literal(rv, a) \
778780
if_err_return((rv), bytebuf_nputs(&global.out, (a), sizeof(a) - 1))
779781

780-
#define send_num(rv, nbuf, n) \
781-
if_err_return((rv), \
782+
#define send_num(rv, nbuf, n) \
783+
if_err_return((rv), \
782784
bytebuf_nputs(&global.out, (nbuf), convert_num((n), (nbuf))))
783785

784-
#define snprintf_or_return(rv, str, sz, fmt, ...) \
785-
do { \
786-
(rv) = snprintf((str), (sz), (fmt), __VA_ARGS__); \
787-
if ((rv) < 0 || (rv) >= (int)(sz)) return TB_ERR; \
786+
#define snprintf_or_return(rv, str, sz, fmt, ...) \
787+
do { \
788+
(rv) = snprintf((str), (sz), (fmt), __VA_ARGS__); \
789+
if ((rv) < 0 || (rv) >= (int)(sz)) return TB_ERR; \
788790
} while (0)
789791

790-
#define if_not_init_return() \
792+
#define if_not_init_return() \
791793
if (!global.initialized) return TB_ERR_NOT_INIT
792794

793795
struct bytebuf {
@@ -2456,8 +2458,8 @@ int tb_present(void) {
24562458
// When wcwidth>1, we need to advance the cursor by more
24572459
// than 1, thereby skipping some cells. Set these skipped
24582460
// cells to an invalid codepoint in the front buffer, so
2459-
// that if this cell is later replaced by a wcwidth==1 char,
2460-
// we'll get a cell_cmp diff for the skipped cells and
2461+
// that if this cell is later replaced by a wcwidth==1
2462+
// char we'll get a cell_cmp diff for the skipped cells and
24612463
// properly re-render.
24622464
for (i = 1; i < w; i++) {
24632465
struct tb_cell *front_wide;
@@ -3339,9 +3341,9 @@ static int parse_terminfo_caps(void) {
33393341
const int bytes_per_int = magic_number == 01036 ? 4 // 32-bit
33403342
: 2; // 16-bit
33413343

3342-
// > Between the boolean section and the number section, a null byte will be
3343-
// > inserted, if necessary, to ensure that the number section begins on an
3344-
// > even byte
3344+
// > Between the boolean section and the number section, a null byte will
3345+
// > be inserted, if necessary, to ensure that the number section begins on
3346+
// > an even byte
33453347
const int align_offset = (nbytes_names + nbytes_bools) % 2 != 0 ? 1 : 0;
33463348

33473349
const int pos_str_offsets =

0 commit comments

Comments
 (0)