Standardize on "color" to match what the flag has always been called
This commit is contained in:
1 parent
44a5c4b0b1
commit
2d05b5475c
6 files changed
+33
-33
No files matched your search
@@ -107,7 +107,7 @@ sections:
|
|||||||
will result in more compact output by instead putting each
|
will result in more compact output by instead putting each
|
||||||
JSON object on a single line.
|
JSON object on a single line.
|
||||||
|
|
||||||
* `--colour-output` / `-C` and `--monochrome-output` / `-M`:
|
* `--color-output` / `-C` and `--monochrome-output` / `-M`:
|
||||||
|
|
||||||
By default, jq outputs colored JSON if writing to a
|
By default, jq outputs colored JSON if writing to a
|
||||||
terminal. You can force it to produce color even if writing to
|
terminal. You can force it to produce color even if writing to
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ sections:
|
|||||||
will result in more compact output by instead putting each
|
will result in more compact output by instead putting each
|
||||||
JSON object on a single line.
|
JSON object on a single line.
|
||||||
|
|
||||||
* `--colour-output` / `-C` and `--monochrome-output` / `-M`:
|
* `--color-output` / `-C` and `--monochrome-output` / `-M`:
|
||||||
|
|
||||||
By default, jq outputs colored JSON if writing to a
|
By default, jq outputs colored JSON if writing to a
|
||||||
terminal. You can force it to produce color even if writing to
|
terminal. You can force it to produce color even if writing to
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ static void run_jq_tests(jv lib_dirs, int verbose, FILE *testdata) {
|
|||||||
printf(" for test at line number %u: %s\n", lineno, prog);
|
printf(" for test at line number %u: %s\n", lineno, prog);
|
||||||
pass = 0;
|
pass = 0;
|
||||||
}
|
}
|
||||||
jv as_string = jv_dump_string(jv_copy(expected), rand() & ~(JV_PRINT_COLOUR|JV_PRINT_REFCOUNT));
|
jv as_string = jv_dump_string(jv_copy(expected), rand() & ~(JV_PRINT_COLOR|JV_PRINT_REFCOUNT));
|
||||||
jv reparsed = jv_parse_sized(jv_string_value(as_string), jv_string_length_bytes(jv_copy(as_string)));
|
jv reparsed = jv_parse_sized(jv_string_value(as_string), jv_string_length_bytes(jv_copy(as_string)));
|
||||||
assert(jv_equal(jv_copy(expected), jv_copy(reparsed)));
|
assert(jv_equal(jv_copy(expected), jv_copy(reparsed)));
|
||||||
jv_free(as_string);
|
jv_free(as_string);
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ int jv_get_refcnt(jv);
|
|||||||
enum jv_print_flags {
|
enum jv_print_flags {
|
||||||
JV_PRINT_PRETTY = 1,
|
JV_PRINT_PRETTY = 1,
|
||||||
JV_PRINT_ASCII = 2,
|
JV_PRINT_ASCII = 2,
|
||||||
JV_PRINT_COLOUR = 4,
|
JV_PRINT_COLOR = 4,
|
||||||
JV_PRINT_SORTED = 8,
|
JV_PRINT_SORTED = 8,
|
||||||
JV_PRINT_INVALID = 16,
|
JV_PRINT_INVALID = 16,
|
||||||
JV_PRINT_REFCOUNT = 32,
|
JV_PRINT_REFCOUNT = 32,
|
||||||
|
|||||||
+21
-21
@@ -17,15 +17,15 @@
|
|||||||
#define COL(c) (ESC "[" c "m")
|
#define COL(c) (ESC "[" c "m")
|
||||||
#define COLRESET (ESC "[0m")
|
#define COLRESET (ESC "[0m")
|
||||||
|
|
||||||
// Colour table. See https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
|
// Color table. See https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
|
||||||
// for how to choose these.
|
// for how to choose these.
|
||||||
static const jv_kind colour_kinds[] =
|
static const jv_kind color_kinds[] =
|
||||||
{JV_KIND_NULL, JV_KIND_FALSE, JV_KIND_TRUE, JV_KIND_NUMBER,
|
{JV_KIND_NULL, JV_KIND_FALSE, JV_KIND_TRUE, JV_KIND_NUMBER,
|
||||||
JV_KIND_STRING, JV_KIND_ARRAY, JV_KIND_OBJECT};
|
JV_KIND_STRING, JV_KIND_ARRAY, JV_KIND_OBJECT};
|
||||||
static const char* const colours[] =
|
static const char* const colors[] =
|
||||||
{COL("1;30"), COL("0;39"), COL("0;39"), COL("0;39"),
|
{COL("1;30"), COL("0;39"), COL("0;39"), COL("0;39"),
|
||||||
COL("0;32"), COL("1;39"), COL("1;39")};
|
COL("0;32"), COL("1;39"), COL("1;39")};
|
||||||
#define FIELD_COLOUR COL("34;1")
|
#define FIELD_COLOR COL("34;1")
|
||||||
|
|
||||||
static void put_buf(const char *s, int len, FILE *fout, jv *strout, int is_tty) {
|
static void put_buf(const char *s, int len, FILE *fout, jv *strout, int is_tty) {
|
||||||
if (strout) {
|
if (strout) {
|
||||||
@@ -139,13 +139,13 @@ static void put_refcnt(struct dtoa_context* C, int refcnt, FILE *F, jv* S, int T
|
|||||||
|
|
||||||
static void jv_dump_term(struct dtoa_context* C, jv x, int flags, int indent, FILE* F, jv* S) {
|
static void jv_dump_term(struct dtoa_context* C, jv x, int flags, int indent, FILE* F, jv* S) {
|
||||||
char buf[JVP_DTOA_FMT_MAX_LEN];
|
char buf[JVP_DTOA_FMT_MAX_LEN];
|
||||||
const char* colour = 0;
|
const char* color = 0;
|
||||||
double refcnt = (flags & JV_PRINT_REFCOUNT) ? jv_get_refcnt(x) - 1 : -1;
|
double refcnt = (flags & JV_PRINT_REFCOUNT) ? jv_get_refcnt(x) - 1 : -1;
|
||||||
if (flags & JV_PRINT_COLOUR) {
|
if (flags & JV_PRINT_COLOR) {
|
||||||
for (unsigned i=0; i<sizeof(colour_kinds)/sizeof(colour_kinds[0]); i++) {
|
for (unsigned i=0; i<sizeof(color_kinds)/sizeof(color_kinds[0]); i++) {
|
||||||
if (jv_get_kind(x) == colour_kinds[i]) {
|
if (jv_get_kind(x) == color_kinds[i]) {
|
||||||
colour = colours[i];
|
color = colors[i];
|
||||||
put_str(colour, F, S, flags & JV_PRINT_ISATTY);
|
put_str(color, F, S, flags & JV_PRINT_ISATTY);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -213,13 +213,13 @@ static void jv_dump_term(struct dtoa_context* C, jv x, int flags, int indent, FI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
jv_dump_term(C, elem, flags, indent + 1, F, S);
|
jv_dump_term(C, elem, flags, indent + 1, F, S);
|
||||||
if (colour) put_str(colour, F, S, flags & JV_PRINT_ISATTY);
|
if (color) put_str(color, F, S, flags & JV_PRINT_ISATTY);
|
||||||
}
|
}
|
||||||
if (flags & JV_PRINT_PRETTY) {
|
if (flags & JV_PRINT_PRETTY) {
|
||||||
put_char('\n', F, S, flags & JV_PRINT_ISATTY);
|
put_char('\n', F, S, flags & JV_PRINT_ISATTY);
|
||||||
put_indent(indent, flags, F, S, flags & JV_PRINT_ISATTY);
|
put_indent(indent, flags, F, S, flags & JV_PRINT_ISATTY);
|
||||||
}
|
}
|
||||||
if (colour) put_str(colour, F, S, flags & JV_PRINT_ISATTY);
|
if (color) put_str(color, F, S, flags & JV_PRINT_ISATTY);
|
||||||
put_char(']', F, S, flags & JV_PRINT_ISATTY);
|
put_char(']', F, S, flags & JV_PRINT_ISATTY);
|
||||||
if (flags & JV_PRINT_REFCOUNT)
|
if (flags & JV_PRINT_REFCOUNT)
|
||||||
put_refcnt(C, refcnt, F, S, flags & JV_PRINT_ISATTY);
|
put_refcnt(C, refcnt, F, S, flags & JV_PRINT_ISATTY);
|
||||||
@@ -272,33 +272,33 @@ static void jv_dump_term(struct dtoa_context* C, jv x, int flags, int indent, FI
|
|||||||
put_str(",", F, S, flags & JV_PRINT_ISATTY);
|
put_str(",", F, S, flags & JV_PRINT_ISATTY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (colour) put_str(COLRESET, F, S, flags & JV_PRINT_ISATTY);
|
if (color) put_str(COLRESET, F, S, flags & JV_PRINT_ISATTY);
|
||||||
|
|
||||||
first = 0;
|
first = 0;
|
||||||
if (colour) put_str(FIELD_COLOUR, F, S, flags & JV_PRINT_ISATTY);
|
if (color) put_str(FIELD_COLOR, F, S, flags & JV_PRINT_ISATTY);
|
||||||
jvp_dump_string(key, flags & JV_PRINT_ASCII, F, S, flags & JV_PRINT_ISATTY);
|
jvp_dump_string(key, flags & JV_PRINT_ASCII, F, S, flags & JV_PRINT_ISATTY);
|
||||||
jv_free(key);
|
jv_free(key);
|
||||||
if (colour) put_str(COLRESET, F, S, flags & JV_PRINT_ISATTY);
|
if (color) put_str(COLRESET, F, S, flags & JV_PRINT_ISATTY);
|
||||||
|
|
||||||
if (colour) put_str(colour, F, S, flags & JV_PRINT_ISATTY);
|
if (color) put_str(color, F, S, flags & JV_PRINT_ISATTY);
|
||||||
put_str((flags & JV_PRINT_PRETTY) ? ": " : ":", F, S, flags & JV_PRINT_ISATTY);
|
put_str((flags & JV_PRINT_PRETTY) ? ": " : ":", F, S, flags & JV_PRINT_ISATTY);
|
||||||
if (colour) put_str(COLRESET, F, S, flags & JV_PRINT_ISATTY);
|
if (color) put_str(COLRESET, F, S, flags & JV_PRINT_ISATTY);
|
||||||
|
|
||||||
jv_dump_term(C, value, flags, indent + 1, F, S);
|
jv_dump_term(C, value, flags, indent + 1, F, S);
|
||||||
if (colour) put_str(colour, F, S, flags & JV_PRINT_ISATTY);
|
if (color) put_str(color, F, S, flags & JV_PRINT_ISATTY);
|
||||||
}
|
}
|
||||||
if (flags & JV_PRINT_PRETTY) {
|
if (flags & JV_PRINT_PRETTY) {
|
||||||
put_char('\n', F, S, flags & JV_PRINT_ISATTY);
|
put_char('\n', F, S, flags & JV_PRINT_ISATTY);
|
||||||
put_indent(indent, flags, F, S, flags & JV_PRINT_ISATTY);
|
put_indent(indent, flags, F, S, flags & JV_PRINT_ISATTY);
|
||||||
}
|
}
|
||||||
if (colour) put_str(colour, F, S, flags & JV_PRINT_ISATTY);
|
if (color) put_str(color, F, S, flags & JV_PRINT_ISATTY);
|
||||||
put_char('}', F, S, flags & JV_PRINT_ISATTY);
|
put_char('}', F, S, flags & JV_PRINT_ISATTY);
|
||||||
if (flags & JV_PRINT_REFCOUNT)
|
if (flags & JV_PRINT_REFCOUNT)
|
||||||
put_refcnt(C, refcnt, F, S, flags & JV_PRINT_ISATTY);
|
put_refcnt(C, refcnt, F, S, flags & JV_PRINT_ISATTY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
jv_free(x);
|
jv_free(x);
|
||||||
if (colour) {
|
if (color) {
|
||||||
put_str(COLRESET, F, S, flags & JV_PRINT_ISATTY);
|
put_str(COLRESET, F, S, flags & JV_PRINT_ISATTY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -317,7 +317,7 @@ void jv_dump(jv x, int flags) {
|
|||||||
/* This one is nice for use in debuggers */
|
/* This one is nice for use in debuggers */
|
||||||
void jv_show(jv x, int flags) {
|
void jv_show(jv x, int flags) {
|
||||||
if (flags == -1)
|
if (flags == -1)
|
||||||
flags = JV_PRINT_PRETTY | JV_PRINT_COLOUR | JV_PRINT_INDENT_FLAGS(2);
|
flags = JV_PRINT_PRETTY | JV_PRINT_COLOR | JV_PRINT_INDENT_FLAGS(2);
|
||||||
jv_dumpf(jv_copy(x), stderr, flags | JV_PRINT_INVALID);
|
jv_dumpf(jv_copy(x), stderr, flags | JV_PRINT_INVALID);
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,8 +104,8 @@ enum {
|
|||||||
PROVIDE_NULL = 4,
|
PROVIDE_NULL = 4,
|
||||||
RAW_OUTPUT = 8,
|
RAW_OUTPUT = 8,
|
||||||
ASCII_OUTPUT = 32,
|
ASCII_OUTPUT = 32,
|
||||||
COLOUR_OUTPUT = 64,
|
COLOR_OUTPUT = 64,
|
||||||
NO_COLOUR_OUTPUT = 128,
|
NO_COLOR_OUTPUT = 128,
|
||||||
SORTED_OUTPUT = 256,
|
SORTED_OUTPUT = 256,
|
||||||
FROM_FILE = 512,
|
FROM_FILE = 512,
|
||||||
RAW_NO_LF = 1024,
|
RAW_NO_LF = 1024,
|
||||||
@@ -256,11 +256,11 @@ int main(int argc, char* argv[]) {
|
|||||||
if (!short_opts) continue;
|
if (!short_opts) continue;
|
||||||
}
|
}
|
||||||
if (isoption(argv[i], 'C', "color-output", &short_opts)) {
|
if (isoption(argv[i], 'C', "color-output", &short_opts)) {
|
||||||
options |= COLOUR_OUTPUT;
|
options |= COLOR_OUTPUT;
|
||||||
if (!short_opts) continue;
|
if (!short_opts) continue;
|
||||||
}
|
}
|
||||||
if (isoption(argv[i], 'M', "monochrome-output", &short_opts)) {
|
if (isoption(argv[i], 'M', "monochrome-output", &short_opts)) {
|
||||||
options |= NO_COLOUR_OUTPUT;
|
options |= NO_COLOR_OUTPUT;
|
||||||
if (!short_opts) continue;
|
if (!short_opts) continue;
|
||||||
}
|
}
|
||||||
if (isoption(argv[i], 'a', "ascii-output", &short_opts)) {
|
if (isoption(argv[i], 'a', "ascii-output", &short_opts)) {
|
||||||
@@ -426,15 +426,15 @@ int main(int argc, char* argv[]) {
|
|||||||
if (isatty(fileno(stdout))) {
|
if (isatty(fileno(stdout))) {
|
||||||
dumpopts |= JV_PRINT_ISATTY;
|
dumpopts |= JV_PRINT_ISATTY;
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
/* Disable colour by default on Windows builds as Windows
|
/* Disable color by default on Windows builds as Windows
|
||||||
terminals tend not to display it correctly */
|
terminals tend not to display it correctly */
|
||||||
dumpopts |= JV_PRINT_COLOUR;
|
dumpopts |= JV_PRINT_COLOR;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (options & SORTED_OUTPUT) dumpopts |= JV_PRINT_SORTED;
|
if (options & SORTED_OUTPUT) dumpopts |= JV_PRINT_SORTED;
|
||||||
if (options & ASCII_OUTPUT) dumpopts |= JV_PRINT_ASCII;
|
if (options & ASCII_OUTPUT) dumpopts |= JV_PRINT_ASCII;
|
||||||
if (options & COLOUR_OUTPUT) dumpopts |= JV_PRINT_COLOUR;
|
if (options & COLOR_OUTPUT) dumpopts |= JV_PRINT_COLOR;
|
||||||
if (options & NO_COLOUR_OUTPUT) dumpopts &= ~JV_PRINT_COLOUR;
|
if (options & NO_COLOR_OUTPUT) dumpopts &= ~JV_PRINT_COLOR;
|
||||||
|
|
||||||
if (jv_get_kind(lib_search_paths) == JV_KIND_NULL) {
|
if (jv_get_kind(lib_search_paths) == JV_KIND_NULL) {
|
||||||
// Default search path list
|
// Default search path list
|
||||||
|
|||||||
Reference in new issue
Block a user