[READ-ONLY] Mirror of https://github.com/bombshell-dev/tty. Platform independent 2D layout engine for terminal applications based on Clay
5

Configure Feed

Select the types of activity you want to include in your feed.

ref(wcwidth): generate clang-format friendly code

Nate Moore (May 28, 2026, 2:52 AM EDT) 6c5cba49 51fdc1ae

+56 -32
+28 -16
src/wcwidth.c
··· 1 1 /* wcwidth.c - Unicode character width lookup 2 - * Unicode 16.0 — generated by tasks/gen-wcwidth.ts on 2026-05-28 2 + * Unicode 16.0 - generated by tasks/gen-wcwidth.ts on 2026-05-28 3 3 * 4 4 * Only zero-width (combining marks + default ignorable) and double-width 5 5 * (wide/fullwidth) codepoints are stored. Everything else defaults to 6 - * width 1. Control characters (U+0000–U+001F, U+007F–U+009F) are handled 6 + * width 1. Control characters (U+0000-U+001F, U+007F-U+009F) are handled 7 7 * by the fast-path checks in wcwidth() and are not in the tables. 8 8 * 9 9 * Sources: 10 - * extracted/DerivedGeneralCategory.txt Mn/Me categories → width 0 11 - * DerivedCoreProperties.txt Default_Ignorable_Code_Point → width 0 12 - * EastAsianWidth.txt W/F properties → width 2 10 + * DerivedGeneralCategory.txt: Mn/Me categories -> width 0 11 + * DerivedCoreProperties.txt: Default_Ignorable_Code_Point -> width 0 12 + * EastAsianWidth.txt: W/F properties -> width 2 13 13 * 14 14 * Combining (width 0) and wide (width 2) ranges are merged into a single 15 15 * sorted table so wcwidth() needs only one binary search for any codepoint. 16 16 * 17 17 * BMP coarse filter (bmp_filter): 18 18 * 64-byte bitmap, 1 bit per 128-codepoint BMP block. A 0-bit means no 19 - * special codepoints in that block — return width 1 without searching. 19 + * special codepoints in that block - return width 1 without searching. 20 20 * 21 21 * Packed encoding (special_small_ranges): 22 22 * Each uint32_t entry packs one Unicode range as 23 - * bits 31–11 start codepoint (fits in 21 bits; Unicode max is U+10FFFF) 24 - * bits 10–1 count of additional codepoints beyond start (max 1023) 23 + * bits 31-11 start codepoint (fits in 21 bits; Unicode max is U+10FFFF) 24 + * bits 10-1 count of additional codepoints beyond start (max 1023) 25 25 * bit 0 0 = width 0 (combining), 1 = width 2 (wide) 26 26 * Array is sorted by start so binary search operates on raw uint32_t values. 27 27 * ··· 30 30 */ 31 31 32 32 #include <stdint.h> 33 + 34 + /* clang-format off */ 33 35 34 36 static const uint32_t bmp_filter[16] = { 35 37 0xfffffa40, 0x0bf7c047, 0xee40f8c3, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, ··· 111 113 }; 112 114 #define SPECIAL_LARGE_COUNT 7 113 115 116 + /* clang-format on */ 117 + 114 118 static int codepoint_in_special(uint32_t codepoint) { 115 119 if (codepoint <= 0xffff) { 116 120 uint32_t block = codepoint >> 7; 117 - if (!((bmp_filter[block >> 5] >> (block & 31u)) & 1u)) return 1; 121 + if (!((bmp_filter[block >> 5] >> (block & 31u)) & 1u)) 122 + return 1; 118 123 } 119 124 int left = 0, right = SPECIAL_SMALL_COUNT - 1; 120 125 while (left <= right) { 121 126 int mid = (left + right) / 2; 122 127 uint32_t entry = special_small_ranges[mid]; 123 128 uint32_t start = entry >> 11; 124 - if (codepoint < start) right = mid - 1; 125 - else if (codepoint > start + ((entry >> 1) & 0x3FF)) left = mid + 1; 126 - else return (entry & 1) ? 2 : 0; 129 + if (codepoint < start) 130 + right = mid - 1; 131 + else if (codepoint > start + ((entry >> 1) & 0x3FF)) 132 + left = mid + 1; 133 + else 134 + return (entry & 1) ? 2 : 0; 127 135 } 128 - left = 0; right = SPECIAL_LARGE_COUNT - 1; 136 + left = 0; 137 + right = SPECIAL_LARGE_COUNT - 1; 129 138 while (left <= right) { 130 139 int mid = (left + right) / 2; 131 - if (codepoint < special_large_starts[mid]) right = mid - 1; 132 - else if (codepoint > special_large_starts[mid] + special_large_counts[mid]) left = mid + 1; 133 - else return special_large_widths[mid]; 140 + if (codepoint < special_large_starts[mid]) 141 + right = mid - 1; 142 + else if (codepoint > special_large_starts[mid] + special_large_counts[mid]) 143 + left = mid + 1; 144 + else 145 + return special_large_widths[mid]; 134 146 } 135 147 return 1; 136 148 }
+28 -16
tasks/gen-wcwidth.ts
··· 311 311 312 312 const output = `\ 313 313 /* wcwidth.c - Unicode character width lookup 314 - * Unicode 16.0 — generated by tasks/gen-wcwidth.ts on ${date} 314 + * Unicode 16.0 - generated by tasks/gen-wcwidth.ts on ${date} 315 315 * 316 316 * Only zero-width (combining marks + default ignorable) and double-width 317 317 * (wide/fullwidth) codepoints are stored. Everything else defaults to 318 - * width 1. Control characters (U+0000–U+001F, U+007F–U+009F) are handled 318 + * width 1. Control characters (U+0000-U+001F, U+007F-U+009F) are handled 319 319 * by the fast-path checks in wcwidth() and are not in the tables. 320 320 * 321 321 * Sources: 322 - * extracted/DerivedGeneralCategory.txt Mn/Me categories → width 0 323 - * DerivedCoreProperties.txt Default_Ignorable_Code_Point → width 0 324 - * EastAsianWidth.txt W/F properties → width 2 322 + * DerivedGeneralCategory.txt: Mn/Me categories -> width 0 323 + * DerivedCoreProperties.txt: Default_Ignorable_Code_Point -> width 0 324 + * EastAsianWidth.txt: W/F properties -> width 2 325 325 * 326 326 * Combining (width 0) and wide (width 2) ranges are merged into a single 327 327 * sorted table so wcwidth() needs only one binary search for any codepoint. 328 328 * 329 329 * BMP coarse filter (bmp_filter): 330 330 * 64-byte bitmap, 1 bit per 128-codepoint BMP block. A 0-bit means no 331 - * special codepoints in that block — return width 1 without searching. 331 + * special codepoints in that block - return width 1 without searching. 332 332 * 333 333 * Packed encoding (special_small_ranges): 334 334 * Each uint32_t entry packs one Unicode range as 335 - * bits 31–11 start codepoint (fits in 21 bits; Unicode max is U+10FFFF) 336 - * bits 10–1 count of additional codepoints beyond start (max 1023) 335 + * bits 31-11 start codepoint (fits in 21 bits; Unicode max is U+10FFFF) 336 + * bits 10-1 count of additional codepoints beyond start (max 1023) 337 337 * bit 0 0 = width 0 (combining), 1 = width 2 (wide) 338 338 * Array is sorted by start so binary search operates on raw uint32_t values. 339 339 * ··· 343 343 344 344 #include <stdint.h> 345 345 346 + /* clang-format off */ 347 + 346 348 static const uint32_t bmp_filter[16] = { 347 349 ${formatUint32Array(Array.from(bmpFilter))} 348 350 }; ··· 363 365 }; 364 366 #define SPECIAL_LARGE_COUNT ${largeRanges.length} 365 367 368 + /* clang-format on */ 369 + 366 370 static int codepoint_in_special(uint32_t codepoint) { 367 371 if (codepoint <= 0xffff) { 368 372 uint32_t block = codepoint >> 7; 369 - if (!((bmp_filter[block >> 5] >> (block & 31u)) & 1u)) return 1; 373 + if (!((bmp_filter[block >> 5] >> (block & 31u)) & 1u)) 374 + return 1; 370 375 } 371 376 int left = 0, right = SPECIAL_SMALL_COUNT - 1; 372 377 while (left <= right) { 373 378 int mid = (left + right) / 2; 374 379 uint32_t entry = special_small_ranges[mid]; 375 380 uint32_t start = entry >> 11; 376 - if (codepoint < start) right = mid - 1; 377 - else if (codepoint > start + ((entry >> 1) & 0x3FF)) left = mid + 1; 378 - else return (entry & 1) ? 2 : 0; 381 + if (codepoint < start) 382 + right = mid - 1; 383 + else if (codepoint > start + ((entry >> 1) & 0x3FF)) 384 + left = mid + 1; 385 + else 386 + return (entry & 1) ? 2 : 0; 379 387 } 380 - left = 0; right = SPECIAL_LARGE_COUNT - 1; 388 + left = 0; 389 + right = SPECIAL_LARGE_COUNT - 1; 381 390 while (left <= right) { 382 391 int mid = (left + right) / 2; 383 - if (codepoint < special_large_starts[mid]) right = mid - 1; 384 - else if (codepoint > special_large_starts[mid] + special_large_counts[mid]) left = mid + 1; 385 - else return special_large_widths[mid]; 392 + if (codepoint < special_large_starts[mid]) 393 + right = mid - 1; 394 + else if (codepoint > special_large_starts[mid] + special_large_counts[mid]) 395 + left = mid + 1; 396 + else 397 + return special_large_widths[mid]; 386 398 } 387 399 return 1; 388 400 }