Respect NO_COLOR environment variable to disable color output
This PR implements `NO_COLOR` support. The `NO_COLOR` environment variable is recognized by various command line tools to disable their color output in terminal. See https://no-color.org for the list of commands and example implementation in C. When `--color-output` (`-C`) is used, the color output is enabled regardless of the environment variable (as described in https://no-color.org). This PR resolves #2297.
It would be nice to control the coloring via an environment variable. My use case is that I have `jq` running inside [wasm-terminal](https://github.com/wasmerio/wasmer-js) and would like to suppress its ansi_coloring when wasm-terminal detects that jq's input is being piped to another program (WASI's `isatty` is not supported in the browser).

I know that I can disable coloring via the  `-M` flag but it would mean I have to add a special case in wasm-terminal as opposed to `NO_COLOR` which is supported by an increasing number of CLI programs.

See https://no-color.org/
[Feature] support no_color env to disable ansi_color output
diff --git a/src/main.c b/src/main.c
index 97f3844401..3c5133d700 100644
--- a/src/main.c
+++ b/src/main.c
@@ -588,6 +588,11 @@ int main(int argc, char* argv[]) {
         dumpopts |= JV_PRINT_COLOR;
     }
 #endif
+    if (dumpopts & JV_PRINT_COLOR) {
+      char *no_color = getenv("NO_COLOR");
+      if (no_color != NULL && no_color[0] != '\0')
+        dumpopts &= ~JV_PRINT_COLOR;
+    }
   }
 #endif
   if (options & SORTED_OUTPUT) dumpopts |= JV_PRINT_SORTED;

diff --git a/tests/shtest b/tests/shtest
index 0a0ddcf7cc..d681ab45ad 100755
--- a/tests/shtest
+++ b/tests/shtest
@@ -414,4 +414,28 @@ JQ_COLORS="0123456789123:0123456789123:0123456789123:0123456789123:0123456789123
 cmp $d/color $d/expect
 cmp $d/warning $d/expect_warning
 
+# Check $NO_COLOR
+if command -v script >/dev/null 2>&1; then
+  unset NO_COLOR
+  if script -qc echo /dev/null >/dev/null 2>&1; then
+    faketty() { script -qec "$*" /dev/null; }
+  else # macOS
+    faketty() { script -q /dev/null "$@" /dev/null |
+      sed 's/^\x5E\x44\x08\x08//'; }
+  fi
+
+  faketty $JQ -n . > $d/color
+  printf '\033[1;30mnull\033[0m\r\n' > $d/expect
+  cmp $d/color $d/expect
+  NO_COLOR= faketty $JQ -n . > $d/color
+  printf '\033[1;30mnull\033[0m\r\n' > $d/expect
+  cmp $d/color $d/expect
+  NO_COLOR=1 faketty $JQ -n . > $d/color
+  printf 'null\r\n' > $d/expect
+  cmp $d/color $d/expect
+  NO_COLOR=1 faketty $JQ -Cn . > $d/color
+  printf '\033[1;30mnull\033[0m\r\n' > $d/expect
+  cmp $d/color $d/expect
+fi
+
 exit 0

{"tests/shtest": {"run": "PASS", "test": "FAIL", "fix": "PASS"}}
{"test_options": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "regset": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "callback_each_match": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "tests/utf8test": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "names": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test_utf8": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "simple": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "tests/base64test": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "echo": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "tests/mantest": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "testc": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test_syntax": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test_back": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "bug_fix": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "tests/jqtest": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "scan": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "tests/onigtest": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "encode": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "callout": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "listcap": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "tests/optionaltest": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "user_property": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "tests/manonigtest": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "test_regset": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "testcu": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "count": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "syntax": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "sql": {"run": "PASS", "test": "PASS", "fix": "PASS"}}
{"tests/shtest": {"run": "PASS", "test": "FAIL", "fix": "PASS"}}
{"passed_count": 29, "failed_count": 0, "skipped_count": 0, "passed_tests": ["regset", "callback_each_match", "names", "test_utf8", "testc", "test_syntax", "sql", "bug_fix", "scan", "tests/onigtest", "encode", "listcap", "tests/optionaltest", "tests/manonigtest", "test_regset", "testcu", "count", "syntax", "test_options", "tests/utf8test", "simple", "tests/base64test", "tests/mantest", "test_back", "tests/jqtest", "tests/shtest", "callout", "user_property", "echo"], "failed_tests": [], "skipped_tests": []}
{"passed_count": 28, "failed_count": 1, "skipped_count": 0, "passed_tests": ["regset", "callback_each_match", "names", "test_utf8", "testc", "test_syntax", "sql", "bug_fix", "scan", "tests/onigtest", "encode", "listcap", "tests/optionaltest", "tests/manonigtest", "test_regset", "testcu", "count", "syntax", "test_options", "tests/utf8test", "simple", "tests/base64test", "tests/mantest", "test_back", "tests/jqtest", "callout", "user_property", "echo"], "failed_tests": ["tests/shtest"], "skipped_tests": []}
{"passed_count": 29, "failed_count": 0, "skipped_count": 0, "passed_tests": ["regset", "callback_each_match", "names", "test_utf8", "testc", "test_syntax", "sql", "bug_fix", "scan", "tests/onigtest", "encode", "listcap", "tests/optionaltest", "tests/manonigtest", "test_regset", "testcu", "count", "syntax", "test_options", "tests/utf8test", "simple", "tests/base64test", "tests/mantest", "test_back", "tests/jqtest", "tests/shtest", "callout", "user_property", "echo"], "failed_tests": [], "skipped_tests": []}