Skip to content
Myr

Standardize on "color" to match what the flag has always been called

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Tolnay · committed by David Tolnay · parent 44a5c4b · Browse files · 6 files+33 added−33 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+33 added−33 removed

  • other:+33 added−33 removed

6 files+33 added−33 removed

modified:docs/content/3.manual/v1.3/manual.yml+1 added-1 removed
105 unmodified lines
106 By default, jq pretty-prints JSON output. Using this option107 will result in more compact output by instead putting each108 JSON object on a single line.109110 * `--colour-output` / `-C` and `--monochrome-output` / `-M`:110 * `--color-output` / `-C` and `--monochrome-output` / `-M`:111112 By default, jq outputs colored JSON if writing to a113 terminal. You can force it to produce color even if writing to114 a pipe or a file using `-C`, and disable color with `-M`.
1156 unmodified lines
modified:docs/content/3.manual/v1.4/manual.yml+1 added-1 removed
126 unmodified lines
127 By default, jq pretty-prints JSON output. Using this option128 will result in more compact output by instead putting each129 JSON object on a single line.130131 * `--colour-output` / `-C` and `--monochrome-output` / `-M`:131 * `--color-output` / `-C` and `--monochrome-output` / `-M`:132133 By default, jq outputs colored JSON if writing to a134 terminal. You can force it to produce color even if writing to135 a pipe or a file using `-C`, and disable color with `-M`.
1537 unmodified lines
modified:jq_test.c+1 added-1 removed
155 unmodified lines
156 jv_dump(jv_copy(actual), 0);157 printf(" for test at line number %u: %s\n", lineno, prog);158 pass = 0;159 }160 jv as_string = jv_dump_string(jv_copy(expected), rand() & ~(JV_PRINT_COLOUR|JV_PRINT_REFCOUNT));160 jv as_string = jv_dump_string(jv_copy(expected), rand() & ~(JV_PRINT_COLOR|JV_PRINT_REFCOUNT));161 jv reparsed = jv_parse_sized(jv_string_value(as_string), jv_string_length_bytes(jv_copy(as_string)));162 assert(jv_equal(jv_copy(expected), jv_copy(reparsed)));163 jv_free(as_string);164 jv_free(reparsed);
182 unmodified lines
modified:jv_print.c+21 added-21 removed
15 unmodified lines
16#define ESC "\033"17#define COL(c) (ESC "[" c "m")18#define COLRESET (ESC "[0m")1920// Colour table. See https://en.wikipedia.org/wiki/ANSI_escape_code#Colors20// Color table. See https://en.wikipedia.org/wiki/ANSI_escape_code#Colors21// for how to choose these.22static const jv_kind colour_kinds[] =22static const jv_kind color_kinds[] =23 {JV_KIND_NULL, JV_KIND_FALSE, JV_KIND_TRUE, JV_KIND_NUMBER,24 JV_KIND_STRING, JV_KIND_ARRAY, JV_KIND_OBJECT};25static const char* const colours[] =25static const char* const colors[] =26 {COL("1;30"), COL("0;39"), COL("0;39"), COL("0;39"),27 COL("0;32"), COL("1;39"), COL("1;39")};28#define FIELD_COLOUR COL("34;1")28#define FIELD_COLOR COL("34;1")2930static void put_buf(const char *s, int len, FILE *fout, jv *strout, int is_tty) {31 if (strout) {32 *strout = jv_string_append_buf(*strout, s, len);
105 unmodified lines
138}139140static void jv_dump_term(struct dtoa_context* C, jv x, int flags, int indent, FILE* F, jv* S) {141 char buf[JVP_DTOA_FMT_MAX_LEN];142 const char* colour = 0;142 const char* color = 0;143 double refcnt = (flags & JV_PRINT_REFCOUNT) ? jv_get_refcnt(x) - 1 : -1;144 if (flags & JV_PRINT_COLOUR) {145 for (unsigned i=0; i<sizeof(colour_kinds)/sizeof(colour_kinds[0]); i++) {146 if (jv_get_kind(x) == colour_kinds[i]) {147 colour = colours[i];148 put_str(colour, F, S, flags & JV_PRINT_ISATTY);144 if (flags & JV_PRINT_COLOR) {145 for (unsigned i=0; i<sizeof(color_kinds)/sizeof(color_kinds[0]); i++) {146 if (jv_get_kind(x) == color_kinds[i]) {147 color = colors[i];148 put_str(color, F, S, flags & JV_PRINT_ISATTY);149 break;150 }151 }152 }
59 unmodified lines
212 put_str(",", F, S, flags & JV_PRINT_ISATTY);213 }214 }215 jv_dump_term(C, elem, flags, indent + 1, F, S);216 if (colour) put_str(colour, F, S, flags & JV_PRINT_ISATTY);216 if (color) put_str(color, F, S, flags & JV_PRINT_ISATTY);217 }218 if (flags & JV_PRINT_PRETTY) {219 put_char('\n', F, S, flags & JV_PRINT_ISATTY);220 put_indent(indent, flags, F, S, flags & JV_PRINT_ISATTY);221 }222 if (colour) put_str(colour, F, S, flags & JV_PRINT_ISATTY);222 if (color) put_str(color, F, S, flags & JV_PRINT_ISATTY);223 put_char(']', F, S, flags & JV_PRINT_ISATTY);224 if (flags & JV_PRINT_REFCOUNT)225 put_refcnt(C, refcnt, F, S, flags & JV_PRINT_ISATTY);226 break;
44 unmodified lines
271 } else {272 put_str(",", F, S, flags & JV_PRINT_ISATTY);273 }274 }275 if (colour) put_str(COLRESET, F, S, flags & JV_PRINT_ISATTY);275 if (color) put_str(COLRESET, F, S, flags & JV_PRINT_ISATTY);276277 first = 0;278 if (colour) put_str(FIELD_COLOUR, F, S, flags & JV_PRINT_ISATTY);278 if (color) put_str(FIELD_COLOR, F, S, flags & JV_PRINT_ISATTY);279 jvp_dump_string(key, flags & JV_PRINT_ASCII, F, S, flags & JV_PRINT_ISATTY);280 jv_free(key);281 if (colour) put_str(COLRESET, F, S, flags & JV_PRINT_ISATTY);281 if (color) put_str(COLRESET, F, S, flags & JV_PRINT_ISATTY);282283 if (colour) put_str(colour, F, S, flags & JV_PRINT_ISATTY);283 if (color) put_str(color, F, S, flags & JV_PRINT_ISATTY);284 put_str((flags & JV_PRINT_PRETTY) ? ": " : ":", F, S, flags & JV_PRINT_ISATTY);285 if (colour) put_str(COLRESET, F, S, flags & JV_PRINT_ISATTY);285 if (color) put_str(COLRESET, F, S, flags & JV_PRINT_ISATTY);286287 jv_dump_term(C, value, flags, indent + 1, F, S);288 if (colour) put_str(colour, F, S, flags & JV_PRINT_ISATTY);288 if (color) put_str(color, F, S, flags & JV_PRINT_ISATTY);289 }290 if (flags & JV_PRINT_PRETTY) {291 put_char('\n', F, S, flags & JV_PRINT_ISATTY);292 put_indent(indent, flags, F, S, flags & JV_PRINT_ISATTY);293 }294 if (colour) put_str(colour, F, S, flags & JV_PRINT_ISATTY);294 if (color) put_str(color, F, S, flags & JV_PRINT_ISATTY);295 put_char('}', F, S, flags & JV_PRINT_ISATTY);296 if (flags & JV_PRINT_REFCOUNT)297 put_refcnt(C, refcnt, F, S, flags & JV_PRINT_ISATTY);298 }299 }300 jv_free(x);301 if (colour) {301 if (color) {302 put_str(COLRESET, F, S, flags & JV_PRINT_ISATTY);303 }304}305
10 unmodified lines
316317/* This one is nice for use in debuggers */318void jv_show(jv x, int flags) {319 if (flags == -1)320 flags = JV_PRINT_PRETTY | JV_PRINT_COLOUR | JV_PRINT_INDENT_FLAGS(2);320 flags = JV_PRINT_PRETTY | JV_PRINT_COLOR | JV_PRINT_INDENT_FLAGS(2);321 jv_dumpf(jv_copy(x), stderr, flags | JV_PRINT_INVALID);322 fflush(stderr);323}324
24 unmodified lines
modified:jv.h+1 added-1 removed
161 unmodified lines
162163enum jv_print_flags {164 JV_PRINT_PRETTY = 1,165 JV_PRINT_ASCII = 2,166 JV_PRINT_COLOUR = 4,166 JV_PRINT_COLOR = 4,167 JV_PRINT_SORTED = 8,168 JV_PRINT_INVALID = 16,169 JV_PRINT_REFCOUNT = 32,170 JV_PRINT_TAB = 64,
70 unmodified lines
modified:main.c+8 added-8 removed
102 unmodified lines
103 RAW_INPUT = 2,104 PROVIDE_NULL = 4,105 RAW_OUTPUT = 8,106 ASCII_OUTPUT = 32,107 COLOUR_OUTPUT = 64,108 NO_COLOUR_OUTPUT = 128,107 COLOR_OUTPUT = 64,108 NO_COLOR_OUTPUT = 128,109 SORTED_OUTPUT = 256,110 FROM_FILE = 512,111 RAW_NO_LF = 1024,112 UNBUFFERED_OUTPUT = 2048,
142 unmodified lines
255 dumpopts &= ~(JV_PRINT_TAB | JV_PRINT_INDENT_FLAGS(7));256 if (!short_opts) continue;257 }258 if (isoption(argv[i], 'C', "color-output", &short_opts)) {259 options |= COLOUR_OUTPUT;259 options |= COLOR_OUTPUT;260 if (!short_opts) continue;261 }262 if (isoption(argv[i], 'M', "monochrome-output", &short_opts)) {263 options |= NO_COLOUR_OUTPUT;263 options |= NO_COLOR_OUTPUT;264 if (!short_opts) continue;265 }266 if (isoption(argv[i], 'a', "ascii-output", &short_opts)) {267 options |= ASCII_OUTPUT;
157 unmodified lines
425426 if (isatty(fileno(stdout))) {427 dumpopts |= JV_PRINT_ISATTY;428#ifndef WIN32429 /* Disable colour by default on Windows builds as Windows429 /* Disable color by default on Windows builds as Windows430 terminals tend not to display it correctly */431 dumpopts |= JV_PRINT_COLOUR;431 dumpopts |= JV_PRINT_COLOR;432#endif433 }434 if (options & SORTED_OUTPUT) dumpopts |= JV_PRINT_SORTED;435 if (options & ASCII_OUTPUT) dumpopts |= JV_PRINT_ASCII;436 if (options & COLOUR_OUTPUT) dumpopts |= JV_PRINT_COLOUR;437 if (options & NO_COLOUR_OUTPUT) dumpopts &= ~JV_PRINT_COLOUR;436 if (options & COLOR_OUTPUT) dumpopts |= JV_PRINT_COLOR;437 if (options & NO_COLOR_OUTPUT) dumpopts &= ~JV_PRINT_COLOR;438439 if (jv_get_kind(lib_search_paths) == JV_KIND_NULL) {440 // Default search path list441 lib_search_paths = JV_ARRAY(jv_string("~/.jq"),
125 unmodified lines