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.

ensure style tags properly reset to prevent color bleed

+34 -14
+31 -11
src/cli/cprintf.c
··· 17 17 * <rpad=N> ... </rpad> - left-pad (right-align) contents to N visible columns 18 18 * <let name=style1+style2+...> - define a named style variable 19 19 * <$name> to apply a previously defined style variable 20 - * </tagname> or </> to reset 20 + * </tagname> or </> to reset (pops one level) 21 + * <reset/> to reset all styles (clears entire stack) 22 + * << and >> to emit literal < and > 21 23 * 22 24 */ 23 25 ··· 45 47 OP_STYLE_PUSH, 46 48 OP_STYLE_FLUSH, 47 49 OP_STYLE_RESET, 50 + OP_STYLE_RESET_ALL, 48 51 OP_PAD_BEGIN, 49 52 OP_RPAD_BEGIN, 50 53 OP_PAD_END, ··· 367 370 return 1; 368 371 } 369 372 373 + if (tag_eq(tag, len, "reset/")) { 374 + emit_op(p, OP_STYLE_RESET_ALL, 0); 375 + return 1; 376 + } 377 + 370 378 emit_op(p, OP_STYLE_PUSH, 0); 371 379 372 380 if (match_attr(p, tag, len)) { emit_op(p, OP_STYLE_FLUSH, 0); return 1; } ··· 493 501 return fs; 494 502 } 495 503 496 - static const char *scan_percent_escape(program_t *p, const char *ptr, const char **lit) { 504 + static const char *scan_escape( 505 + program_t *p, const char *ptr, 506 + const char **lit, const char *emit, size_t elen 507 + ) { 497 508 flush_lit(p, *lit, ptr); 498 - uint32_t off = add_literal(p, "%%", 2); 509 + uint32_t off = add_literal(p, emit, elen); 499 510 emit_op(p, OP_EMIT_LIT, off); 500 511 *lit = ptr + 2; 501 512 return *lit; ··· 508 519 const char *lit = ptr; 509 520 510 521 while (*ptr) { 511 - if (*ptr == '<') 512 - ptr = scan_tag(p, ptr, &lit, &vars); 513 - else if (*ptr == '%' && ptr[1] && ptr[1] != '%') 514 - ptr = scan_fmt(p, ptr, &lit); 515 - else if (*ptr == '%' && ptr[1] == '%') 516 - ptr = scan_percent_escape(p, ptr, &lit); 522 + if (*ptr == '<' && ptr[1] == '<') ptr = scan_escape(p, ptr, &lit, "<", 1); 523 + else if (*ptr == '>' && ptr[1] == '>') ptr = scan_escape(p, ptr, &lit, ">", 1); 524 + else if (*ptr == '%' && ptr[1] == '%') ptr = scan_escape(p, ptr, &lit, "%%", 2); 525 + else if (*ptr == '<') ptr = scan_tag(p, ptr, &lit, &vars); 526 + else if (*ptr == '%' && ptr[1] && ptr[1] != '%') ptr = scan_fmt(p, ptr, &lit); 517 527 else ptr++; 518 528 } 519 529 ··· 561 571 [OP_SET_UL] = &&op_set_ul, 562 572 [OP_STYLE_PUSH] = &&op_style_push, 563 573 [OP_STYLE_FLUSH] = &&op_style_flush, 564 - [OP_STYLE_RESET] = &&op_style_reset, 565 - [OP_PAD_BEGIN] = &&op_pad_begin, 574 + [OP_STYLE_RESET] = &&op_style_reset, 575 + [OP_STYLE_RESET_ALL] = &&op_style_reset_all, 576 + [OP_PAD_BEGIN] = &&op_pad_begin, 566 577 [OP_RPAD_BEGIN] = &&op_rpad_begin, 567 578 [OP_PAD_END] = &&op_pad_end, 568 579 [OP_EMIT_SPACES] = &&op_emit_spaces, ··· 737 748 NEXT(); 738 749 } 739 750 751 + op_style_reset_all: { 752 + regs.fg = COL_NONE; regs.bg = COL_NONE; 753 + regs.fg_rgb = 0; regs.bg_rgb = 0; 754 + regs.bold = 0; regs.dim = 0; regs.ul = 0; 755 + regs.style_depth = 0; 756 + if (!io_no_color) { OUT_CSTR("\x1b[0m"); } 757 + NEXT(); 758 + } 759 + 740 760 op_style_flush: { 741 761 if (!io_no_color) { 742 762 char esc[128];
+3 -3
src/main.c
··· 292 292 293 293 if (help->count > 0) { 294 294 cprintf("<bold_red>Ant</> is a tiny JavaScript runtime and package manager (%s)\n\n", ANT_VERSION); 295 - cprintf("<bold>Usage: ant <yellow>[module.js]</yellow> <cyan>[...flags]\n</>"); 296 - cprintf("<bold><space=7/>ant <command><space=3/><cyan>[...args]</>\n\n"); 297 - printf("If no module file is specified, ant starts in REPL mode.\n\n"); 295 + cprintf("<bold>Usage: ant <yellow>[module.js]</yellow> <cyan>[...flags]</><reset/>\n"); 296 + cprintf("<bold><space=7/>ant <<command>><space=3/><cyan>[...args]</><reset/>\n\n"); 297 + printf("If no module file is specified, Ant starts in REPL mode.\n\n"); 298 298 print_subcommands(); 299 299 cprintf("<bold>Flags:</>\n"); 300 300 print_flags_help(stdout, argtable);