Skip to content

Commit 7080749

Browse files
committed
update termbox
1 parent a92840b commit 7080749

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

termbox2.h

+24-19
Original file line numberDiff line numberDiff line change
@@ -1778,11 +1778,11 @@ int tb_extend_cell(int x, int y, uint32_t ch) {
17781778
if_err_return(rv, cellbuf_get(&global.back, x, y, &cell));
17791779
if (cell->nech > 0) { // append to ech
17801780
nech = cell->nech + 1;
1781-
if_err_return(rv, cell_reserve_ech(cell, nech));
1781+
if_err_return(rv, cell_reserve_ech(cell, nech + 1));
17821782
cell->ech[nech - 1] = ch;
17831783
} else { // make new ech
17841784
nech = 2;
1785-
if_err_return(rv, cell_reserve_ech(cell, nech));
1785+
if_err_return(rv, cell_reserve_ech(cell, nech + 1));
17861786
cell->ech[0] = cell->ch;
17871787
cell->ech[1] = ch;
17881788
}
@@ -1869,7 +1869,7 @@ int tb_print(int x, int y, uintattr_t fg, uintattr_t bg, const char *str) {
18691869

18701870
int tb_print_ex(int x, int y, uintattr_t fg, uintattr_t bg, size_t *out_w,
18711871
const char *str) {
1872-
int rv, w, ix;
1872+
int rv, w, ix, x_prev;
18731873
uint32_t uni;
18741874

18751875
if_not_init_return();
@@ -1879,6 +1879,7 @@ int tb_print_ex(int x, int y, uintattr_t fg, uintattr_t bg, size_t *out_w,
18791879
}
18801880

18811881
ix = x;
1882+
x_prev = x;
18821883
if (out_w) *out_w = 0;
18831884

18841885
while (*str) {
@@ -1895,6 +1896,7 @@ int tb_print_ex(int x, int y, uintattr_t fg, uintattr_t bg, size_t *out_w,
18951896

18961897
if (uni == '\n') { // TODO: \r, \t, \v, \f, etc?
18971898
x = ix;
1899+
x_prev = x;
18981900
y += 1;
18991901
continue;
19001902
} else if (!iswprint((wint_t)uni)) {
@@ -1905,17 +1907,17 @@ int tb_print_ex(int x, int y, uintattr_t fg, uintattr_t bg, size_t *out_w,
19051907
if (w < 0) {
19061908
return TB_ERR; // shouldn't happen if iswprint
19071909
} else if (w == 0) { // combining character
1908-
if (cellbuf_in_bounds(&global.back, x - 1, y)) {
1909-
if_err_return(rv, tb_extend_cell(x - 1, y, uni));
1910+
if (cellbuf_in_bounds(&global.back, x_prev, y)) {
1911+
if_err_return(rv, tb_extend_cell(x_prev, y, uni));
19101912
}
19111913
} else {
19121914
if (cellbuf_in_bounds(&global.back, x, y)) {
19131915
if_err_return(rv, tb_set_cell(x, y, uni, fg, bg));
19141916
}
1917+
x_prev = x;
1918+
x += w;
1919+
if (out_w) *out_w += w;
19151920
}
1916-
1917-
x += w;
1918-
if (out_w) *out_w += w;
19191921
}
19201922

19211923
return TB_OK;
@@ -2220,8 +2222,8 @@ static int cap_trie_add(const char *cap, uint16_t key, uint8_t mod) {
22202222
if (!next) {
22212223
// We need to add a new child to node
22222224
node->nchildren += 1;
2223-
node->children =
2224-
tb_realloc(node->children, sizeof(*node) * node->nchildren);
2225+
node->children = (struct cap_trie_t *)tb_realloc(node->children,
2226+
sizeof(*node) * node->nchildren);
22252227
if (!node->children) {
22262228
return TB_ERR_MEM;
22272229
}
@@ -2361,7 +2363,7 @@ static int update_term_size_via_esc(void) {
23612363
#define TB_RESIZE_FALLBACK_MS 1000
23622364
#endif
23632365

2364-
char *move_and_report = "\x1b[9999;9999H\x1b[6n";
2366+
char move_and_report[] = "\x1b[9999;9999H\x1b[6n";
23652367
ssize_t write_rv =
23662368
write(global.wfd, move_and_report, strlen(move_and_report));
23672369
if (write_rv != (ssize_t)strlen(move_and_report)) {
@@ -2430,7 +2432,10 @@ static int tb_deinit(void) {
24302432
}
24312433
}
24322434

2433-
sigaction(SIGWINCH, &(struct sigaction){.sa_handler = SIG_DFL}, NULL);
2435+
struct sigaction sa;
2436+
memset(&sa, 0, sizeof(sa));
2437+
sa.sa_handler = SIG_DFL;
2438+
sigaction(SIGWINCH, &sa, NULL);
24342439
if (global.resize_pipefd[0] >= 0) close(global.resize_pipefd[0]);
24352440
if (global.resize_pipefd[1] >= 0) close(global.resize_pipefd[1]);
24362441

@@ -2537,7 +2542,7 @@ static int read_terminfo_path(const char *path) {
25372542
}
25382543

25392544
size_t fsize = st.st_size;
2540-
char *data = tb_malloc(fsize);
2545+
char *data = (char *)tb_malloc(fsize);
25412546
if (!data) {
25422547
fclose(fp);
25432548
return TB_ERR;
@@ -2848,7 +2853,7 @@ static int extract_esc_cap(struct tb_event *event) {
28482853
static int extract_esc_mouse(struct tb_event *event) {
28492854
struct bytebuf_t *in = &global.in;
28502855

2851-
enum type { TYPE_VT200 = 0, TYPE_1006, TYPE_1015, TYPE_MAX };
2856+
enum { TYPE_VT200 = 0, TYPE_1006, TYPE_1015, TYPE_MAX };
28522857

28532858
const char *cmp[TYPE_MAX] = {//
28542859
// X10 mouse encoding, the simplest one
@@ -2860,7 +2865,7 @@ static int extract_esc_mouse(struct tb_event *event) {
28602865
// urxvt: \x1b [ Cb ; Cx ; Cy M
28612866
[TYPE_1015] = "\x1b["};
28622867

2863-
enum type type = 0;
2868+
int type = 0;
28642869
int ret = TB_ERR;
28652870

28662871
// Unrolled at compile-time (probably)
@@ -3319,7 +3324,7 @@ static int cell_set(struct tb_cell *cell, uint32_t *ch, size_t nch,
33193324
} else {
33203325
int rv;
33213326
if_err_return(rv, cell_reserve_ech(cell, nch + 1));
3322-
memcpy(cell->ech, ch, sizeof(ch) * nch);
3327+
memcpy(cell->ech, ch, sizeof(*ch) * nch);
33233328
cell->ech[nch] = '\0';
33243329
cell->nech = nch;
33253330
}
@@ -3358,7 +3363,7 @@ static int cell_free(struct tb_cell *cell) {
33583363
}
33593364

33603365
static int cellbuf_init(struct cellbuf_t *c, int w, int h) {
3361-
c->cells = tb_malloc(sizeof(struct tb_cell) * w * h);
3366+
c->cells = (struct tb_cell *)tb_malloc(sizeof(struct tb_cell) * w * h);
33623367
if (!c->cells) {
33633368
return TB_ERR_MEM;
33643369
}
@@ -3491,9 +3496,9 @@ static int bytebuf_reserve(struct bytebuf_t *b, size_t sz) {
34913496
}
34923497
char *newbuf;
34933498
if (b->buf) {
3494-
newbuf = tb_realloc(b->buf, newcap);
3499+
newbuf = (char *)tb_realloc(b->buf, newcap);
34953500
} else {
3496-
newbuf = tb_malloc(newcap);
3501+
newbuf = (char *)tb_malloc(newcap);
34973502
}
34983503
if (!newbuf) {
34993504
return TB_ERR_MEM;

0 commit comments

Comments
 (0)