MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

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

support style combination with `+` syntax in cprintf tags

+25 -6
+24 -5
src/cli/cprintf.c
··· 13 13 * <bg_red> <bg_green> ... <bg_#RGB> <bg_#RRGGBB> 14 14 * <bold> <dim> <ul> (underline) 15 15 * <bold_red> <dim_cyan> etc - combine styles with underscores 16 + * <bold+red> <dim+cyan+bg_blue> etc - combine styles with + 16 17 * <#RRGGBB> or <#RGB> for arbitrary 24-bit foreground colors 17 18 * <pad=N> ... </pad> - right-pad contents to N visible columns 18 19 * <br/> - emit a newline, <br=N/> - emit N newlines ··· 367 368 } 368 369 369 370 static int compile_var_ref(program_t *p, var_table_t *vars, const char *tag, int len) { 371 + const char *name = tag + 1; 370 372 int nlen = len - 1; 373 + 374 + const char *plus = memchr(name, '+', nlen); 375 + int var_nlen = plus ? (int)(plus - name) : nlen; 376 + 371 377 for (int i = 0; i < vars->count; i++) { 372 - if (nlen == vars->vars[i].nlen && memcmp(tag + 1, vars->vars[i].name, nlen) == 0) { 373 - emit_op(p, OP_STYLE_PUSH, 0); 374 - if (!compile_plus_segs(p, vars->vars[i].value, vars->vars[i].vlen)) return 0; 375 - emit_op(p, OP_STYLE_FLUSH, 0); 376 - return 1; 378 + cprintf_var_t *v = &vars->vars[i]; 379 + if (var_nlen != v->nlen || memcmp(name, v->name, var_nlen) != 0) continue; 380 + 381 + emit_op(p, OP_STYLE_PUSH, 0); 382 + if (!compile_plus_segs(p, v->value, v->vlen)) return 0; 383 + 384 + if (plus) { 385 + const char *rest = plus + 1; 386 + int rlen = nlen - var_nlen - 1; 387 + if (rlen > 0 && !compile_plus_segs(p, rest, rlen)) return 0; 377 388 } 389 + 390 + emit_op(p, OP_STYLE_FLUSH, 0); 391 + return 1; 378 392 } 393 + 379 394 return 0; 380 395 } 381 396 ··· 431 446 if (tag_prefix(tag, len, "bg_#")) { 432 447 if (!compile_hex_bg(p, tag + 3, len - 3)) return 0; 433 448 emit_op(p, OP_STYLE_FLUSH, 0); return 1; 449 + } 450 + 451 + if (memchr(tag, '+', len)) { 452 + if (compile_plus_segs(p, tag, len)) { emit_op(p, OP_STYLE_FLUSH, 0); return 1; } 434 453 } 435 454 436 455 const char *seg = tag;
+1 -1
src/main.c
··· 304 304 if (help->count > 0) { 305 305 cprintf( 306 306 "<let h=bold, arg=cyan/>" 307 - "<bold_red>Ant</> is a tiny JavaScript runtime and package manager (%s)<br=2/>" 307 + "<$h+red>Ant</> is a tiny JavaScript runtime and package manager (%s)<br=2/>" 308 308 "<$h>Usage: ant <yellow>[module.js]</yellow> <$arg>[...flags]</><reset/><br/>" 309 309 "<$h><gap=7/>ant <<command>><gap=3/><$arg>[...args]</><reset/><br=2/>" 310 310 "If no module file is specified, Ant starts in REPL mode.<br=2/>",