Skip to content

Commit

Permalink
Standardize on "color" to match what the flag has always been called
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Aug 17, 2015
1 parent 44a5c4b commit 2d05b54
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion docs/content/3.manual/v1.3/manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ sections:
will result in more compact output by instead putting each
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
terminal. You can force it to produce color even if writing to
Expand Down
2 changes: 1 addition & 1 deletion docs/content/3.manual/v1.4/manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ sections:
will result in more compact output by instead putting each
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
terminal. You can force it to produce color even if writing to
Expand Down
2 changes: 1 addition & 1 deletion jq_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
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)));
assert(jv_equal(jv_copy(expected), jv_copy(reparsed)));
jv_free(as_string);
Expand Down
2 changes: 1 addition & 1 deletion jv.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ int jv_get_refcnt(jv);
enum jv_print_flags {
JV_PRINT_PRETTY = 1,
JV_PRINT_ASCII = 2,
JV_PRINT_COLOUR = 4,
JV_PRINT_COLOR = 4,
JV_PRINT_SORTED = 8,
JV_PRINT_INVALID = 16,
JV_PRINT_REFCOUNT = 32,
Expand Down
42 changes: 21 additions & 21 deletions jv_print.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
#define COL(c) (ESC "[" c "m")
#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.
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_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("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) {
if (strout) {
Expand Down Expand Up @@ -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) {
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;
if (flags & JV_PRINT_COLOUR) {
for (unsigned i=0; i<sizeof(colour_kinds)/sizeof(colour_kinds[0]); i++) {
if (jv_get_kind(x) == colour_kinds[i]) {
colour = colours[i];
put_str(colour, F, S, flags & JV_PRINT_ISATTY);
if (flags & JV_PRINT_COLOR) {
for (unsigned i=0; i<sizeof(color_kinds)/sizeof(color_kinds[0]); i++) {
if (jv_get_kind(x) == color_kinds[i]) {
color = colors[i];
put_str(color, F, S, flags & JV_PRINT_ISATTY);
break;
}
}
Expand Down Expand Up @@ -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);
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) {
put_char('\n', 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);
if (flags & JV_PRINT_REFCOUNT)
put_refcnt(C, refcnt, F, S, flags & JV_PRINT_ISATTY);
Expand Down Expand Up @@ -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);
}
}
if (colour) put_str(COLRESET, F, S, flags & JV_PRINT_ISATTY);
if (color) put_str(COLRESET, F, S, flags & JV_PRINT_ISATTY);

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);
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);
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);
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) {
put_char('\n', 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);
if (flags & JV_PRINT_REFCOUNT)
put_refcnt(C, refcnt, F, S, flags & JV_PRINT_ISATTY);
}
}
jv_free(x);
if (colour) {
if (color) {
put_str(COLRESET, F, S, flags & JV_PRINT_ISATTY);
}
}
Expand All @@ -317,7 +317,7 @@ void jv_dump(jv x, int flags) {
/* This one is nice for use in debuggers */
void jv_show(jv x, int flags) {
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);
fflush(stderr);
}
Expand Down
16 changes: 8 additions & 8 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ enum {
PROVIDE_NULL = 4,
RAW_OUTPUT = 8,
ASCII_OUTPUT = 32,
COLOUR_OUTPUT = 64,
NO_COLOUR_OUTPUT = 128,
COLOR_OUTPUT = 64,
NO_COLOR_OUTPUT = 128,
SORTED_OUTPUT = 256,
FROM_FILE = 512,
RAW_NO_LF = 1024,
Expand Down Expand Up @@ -256,11 +256,11 @@ int main(int argc, char* argv[]) {
if (!short_opts) continue;
}
if (isoption(argv[i], 'C', "color-output", &short_opts)) {
options |= COLOUR_OUTPUT;
options |= COLOR_OUTPUT;
if (!short_opts) continue;
}
if (isoption(argv[i], 'M', "monochrome-output", &short_opts)) {
options |= NO_COLOUR_OUTPUT;
options |= NO_COLOR_OUTPUT;
if (!short_opts) continue;
}
if (isoption(argv[i], 'a', "ascii-output", &short_opts)) {
Expand Down Expand Up @@ -426,15 +426,15 @@ int main(int argc, char* argv[]) {
if (isatty(fileno(stdout))) {
dumpopts |= JV_PRINT_ISATTY;
#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 */
dumpopts |= JV_PRINT_COLOUR;
dumpopts |= JV_PRINT_COLOR;
#endif
}
if (options & SORTED_OUTPUT) dumpopts |= JV_PRINT_SORTED;
if (options & ASCII_OUTPUT) dumpopts |= JV_PRINT_ASCII;
if (options & COLOUR_OUTPUT) dumpopts |= JV_PRINT_COLOUR;
if (options & NO_COLOUR_OUTPUT) dumpopts &= ~JV_PRINT_COLOUR;
if (options & COLOR_OUTPUT) dumpopts |= JV_PRINT_COLOR;
if (options & NO_COLOR_OUTPUT) dumpopts &= ~JV_PRINT_COLOR;

if (jv_get_kind(lib_search_paths) == JV_KIND_NULL) {
// Default search path list
Expand Down

0 comments on commit 2d05b54

Please sign in to comment.