Skip to content
Myr

Consistently reset color formatting in `jv_dump_term`

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

Before, arrays would not reset colors after `[` and `,`, but objects would; it would reset colors twice before `]` and `}`; and some cases of indentation would have colors applied. Now, colors are reset immediately after any token that is colored, before any indentation. This makes the formatting consistent, for the benefit of custom `JQ_COLORS`.

authored by Thalia Archibald · committed by Nico Williams · parent 8a9a74d · Browse files · 1 file+13 added−22 removed
This commit

State

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

Diff stats

1 file+13 added−22 removed

  • other:+13 added−22 removed

1 file+13 added−22 removed

modified:src/jv_print.c+13 added-22 removed
258 unmodified lines
259 put_str("[]", F, S, flags & JV_PRINT_ISATTY);260 break;261 }262 put_str("[", F, S, flags & JV_PRINT_ISATTY);263 if (flags & JV_PRINT_PRETTY) {264 put_char('\n', F, S, flags & JV_PRINT_ISATTY);265 put_indent(indent + 1, flags, F, S, flags & JV_PRINT_ISATTY);266 }263 jv_array_foreach(x, i, elem) {264 if (i!=0) {269 if (flags & JV_PRINT_PRETTY) {270 put_str(",\n", F, S, flags & JV_PRINT_ISATTY);271 put_indent(indent + 1, flags, F, S, flags & JV_PRINT_ISATTY);272 } else {273 put_str(",", F, S, flags & JV_PRINT_ISATTY);274 }265 if (color) put_str(color, F, S, flags & JV_PRINT_ISATTY);266 put_char(',', F, S, flags & JV_PRINT_ISATTY);267 }268 if (color) put_str(COLRESET, F, S, flags & JV_PRINT_ISATTY);269 if (flags & JV_PRINT_PRETTY) {270 put_char('\n', F, S, flags & JV_PRINT_ISATTY);271 put_indent(indent + 1, flags, F, S, flags & JV_PRINT_ISATTY);272 }273 jv_dump_term(C, elem, flags, indent + 1, F, S);277 if (color) put_str(color, F, S, flags & JV_PRINT_ISATTY);274 }275 if (flags & JV_PRINT_PRETTY) {276 put_char('\n', F, S, flags & JV_PRINT_ISATTY);277 put_indent(indent, flags, F, S, flags & JV_PRINT_ISATTY);
9 unmodified lines
287 put_str("{}", F, S, flags & JV_PRINT_ISATTY);288 break;289 }290 put_char('{', F, S, flags & JV_PRINT_ISATTY);295 if (flags & JV_PRINT_PRETTY) {296 put_char('\n', F, S, flags & JV_PRINT_ISATTY);297 put_indent(indent + 1, flags, F, S, flags & JV_PRINT_ISATTY);298 }291 int first = 1;292 int i = 0;293 jv keyset = jv_null();294 while (1) {
22 unmodified lines
317 value = jv_object_iter_value(x, i);318 }319320 if (!first) {329 if (flags & JV_PRINT_PRETTY){330 put_str(",\n", F, S, flags & JV_PRINT_ISATTY);331 put_indent(indent + 1, flags, F, S, flags & JV_PRINT_ISATTY);332 } else {333 put_str(",", F, S, flags & JV_PRINT_ISATTY);334 }321 if (color) put_str(color, F, S, flags & JV_PRINT_ISATTY);322 put_char(',', F, S, flags & JV_PRINT_ISATTY);323 }324 if (color) put_str(COLRESET, F, S, flags & JV_PRINT_ISATTY);325 if (flags & JV_PRINT_PRETTY) {326 put_char('\n', F, S, flags & JV_PRINT_ISATTY);327 put_indent(indent + 1, flags, F, S, flags & JV_PRINT_ISATTY);328 }329330 first = 0;331 if (color) put_str(FIELD_COLOR, F, S, flags & JV_PRINT_ISATTY);332 jvp_dump_string(key, flags & JV_PRINT_ASCII, F, S, flags & JV_PRINT_ISATTY);
4 unmodified lines
337 put_str((flags & JV_PRINT_PRETTY) ? ": " : ":", F, S, flags & JV_PRINT_ISATTY);338 if (color) put_str(COLRESET, F, S, flags & JV_PRINT_ISATTY);339340 jv_dump_term(C, value, flags, indent + 1, F, S);349 if (color) put_str(color, F, S, flags & JV_PRINT_ISATTY);341 }342 if (flags & JV_PRINT_PRETTY) {343 put_char('\n', F, S, flags & JV_PRINT_ISATTY);344 put_indent(indent, flags, F, S, flags & JV_PRINT_ISATTY);
50 unmodified lines