diff options
| author | user <user@clank> | 2026-08-17 14:22:38 +0200 |
|---|---|---|
| committer | user <user@clank> | 2026-08-17 14:22:38 +0200 |
| commit | ec91ccffe631ae34b111bf6161fd0e3c487f684c (patch) | |
| tree | 4a9fdbb720d9bf03edd5f538d1d87afd2bf51bfb /src/screen.c | |
| parent | sl0ppty: clang-format, and a hook that runs it on what you staged (diff) | |
| download | slosh-ec91ccffe631ae34b111bf6161fd0e3c487f684c.tar.gz slosh-ec91ccffe631ae34b111bf6161fd0e3c487f684c.tar.xz slosh-ec91ccffe631ae34b111bf6161fd0e3c487f684c.zip | |
sl0ppty: clang-format the tree
The bumpy one. `make fmt` over every `.c` and `.h` outside `vendor/`: 32 files,
1,843 lines rewritten, no behaviour changed. Nothing here is worth reading -- the
next commit adds it to `.git-blame-ignore-revs` so `git blame` walks past it.
Two thirds of it is alignment the formatter now owns: trailing comments in a
struct, continuation lines under a signature. The rest is the hand-packed tables
opening up to one entry per line -- `ACTIONS`, `NAMED_KEYS`, `ACTION_HELP`. That
is a real loss of density and a real gain in diffs: adding an action was a reflow
of the block and is now one line. Anything worth keeping packed can be fenced with
`// clang-format off`; nothing was, on the grounds that a table is the thing a
formatter is for.
**One change is not formatting.** `src/config.h` had three trailing comments glued
onto one field:
uint16_t hover_delay_ms; /* how long the pointer must rest to arm a guide */
/* how long an announcement stays up */ /* rows per wheel notch */
-- `toast_ms`'s and `scroll_lines`' comments, landed on their neighbour by an
earlier edit, documenting the wrong things ever since. It is in this commit
because it is what caught it: clang-format could not settle on that line, wrapping
it one way and then re-indenting the wrap on a second pass, so `make fmt` was not
idempotent. The comments are back where they belong and it is.
Verified after the reformat, not before: `make clean && make all` is
warning-free, `make retest` is 1801 checks green, and `make fmt` twice in a row
changes nothing the second time. A formatter that alters behaviour would be worse
than none, so the gate was the whole suite rather than a reading of the diff.
Diffstat (limited to 'src/screen.c')
| -rw-r--r-- | src/screen.c | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/src/screen.c b/src/screen.c index aa0faa3..4642634 100644 --- a/src/screen.c +++ b/src/screen.c @@ -135,16 +135,22 @@ static size_t decode_utf8(const char *txt, size_t len, uint32_t *cps, if (l == 0 || i + l > len) break; uint32_t cp; switch (l) { - case 1: cp = (unsigned char)txt[i]; break; - case 2: cp = ((uint32_t)((unsigned char)txt[i] & 0x1f) << 6) | - ((unsigned char)txt[i + 1] & 0x3f); break; - case 3: cp = ((uint32_t)((unsigned char)txt[i] & 0x0f) << 12) | - ((uint32_t)((unsigned char)txt[i + 1] & 0x3f) << 6) | - ((unsigned char)txt[i + 2] & 0x3f); break; - default: cp = ((uint32_t)((unsigned char)txt[i] & 0x07) << 18) | - ((uint32_t)((unsigned char)txt[i + 1] & 0x3f) << 12) | - ((uint32_t)((unsigned char)txt[i + 2] & 0x3f) << 6) | - ((unsigned char)txt[i + 3] & 0x3f); break; + case 1: cp = (unsigned char)txt[i]; break; + case 2: + cp = ((uint32_t)((unsigned char)txt[i] & 0x1f) << 6) | + ((unsigned char)txt[i + 1] & 0x3f); + break; + case 3: + cp = ((uint32_t)((unsigned char)txt[i] & 0x0f) << 12) | + ((uint32_t)((unsigned char)txt[i + 1] & 0x3f) << 6) | + ((unsigned char)txt[i + 2] & 0x3f); + break; + default: + cp = ((uint32_t)((unsigned char)txt[i] & 0x07) << 18) | + ((uint32_t)((unsigned char)txt[i + 1] & 0x3f) << 12) | + ((uint32_t)((unsigned char)txt[i + 2] & 0x3f) << 6) | + ((unsigned char)txt[i + 3] & 0x3f); + break; } cps[n++] = cp; i += l; @@ -182,8 +188,8 @@ uint16_t screen_cells(const char *txt) { size_t len = strlen(txt), at = 0; while (at < len) { size_t used = 0; - size_t n = decode_utf8(txt + at, len - at, cps, sizeof cps / sizeof *cps, - &used); + size_t n = + decode_utf8(txt + at, len - at, cps, sizeof cps / sizeof *cps, &used); if (!n) break; for (size_t i = 0; i < n;) { uint8_t w = 1; @@ -231,7 +237,6 @@ void screen_put_utf8(screen_t *s, uint16_t x, uint16_t y, const char *txt, c->attrs = attrs; } - uint16_t screen_text(screen_t *s, uint16_t x, uint16_t y, const char *txt, color_t fg, color_t bg, uint16_t attrs) { uint16_t n = 0; @@ -276,7 +281,8 @@ static void emit_sgr(screen_t *s, const cell_t *c) { } static bool style_eq(const cell_t *a, const cell_t *b) { - return a->attrs == b->attrs && color_eq(a->fg, b->fg) && color_eq(a->bg, b->bg); + return a->attrs == b->attrs && color_eq(a->fg, b->fg) && + color_eq(a->bg, b->bg); } void screen_render(screen_t *s) { @@ -319,8 +325,10 @@ void screen_render(screen_t *s) { style = *c; have_style = true; } - if (c->len) out_bytes(s, c->text, c->len); - else out_str(s, " "); + if (c->len) + out_bytes(s, c->text, c->len); + else + out_str(s, " "); *p = *c; cx += c->width ? c->width : 1; @@ -399,9 +407,9 @@ static void dump_style_runs(screen_t *s, json_t *j) { uint16_t bit; const char *name; } names[] = { - {ATTR_BOLD, "bold"}, {ATTR_DIM, "dim"}, - {ATTR_ITALIC, "italic"}, {ATTR_UNDERLINE, "underline"}, - {ATTR_BLINK, "blink"}, {ATTR_INVERSE, "inverse"}, + {ATTR_BOLD, "bold"}, {ATTR_DIM, "dim"}, + {ATTR_ITALIC, "italic"}, {ATTR_UNDERLINE, "underline"}, + {ATTR_BLINK, "blink"}, {ATTR_INVERSE, "inverse"}, {ATTR_INVISIBLE, "invisible"}, {ATTR_STRIKE, "strike"}, }; for (size_t i = 0; i < sizeof names / sizeof *names; i++) |
