Add a --unbuffered option. Closes #206
This commit is contained in:
1 parent
d235f32bc9
commit
6a401c8262
4 files changed
+14
-1
No files matched your search
@@ -114,6 +114,12 @@ sections:
|
|||||||
ASCII output with every non-ASCII character replaced with the
|
ASCII output with every non-ASCII character replaced with the
|
||||||
equivalent escape sequence.
|
equivalent escape sequence.
|
||||||
|
|
||||||
|
* `--unbuffered`
|
||||||
|
|
||||||
|
Flush the output after each JSON object is printed (useful if
|
||||||
|
you're piping a slow data source into jq and piping jq's
|
||||||
|
output elsewhere).
|
||||||
|
|
||||||
* `--sort-keys` / `-S`:
|
* `--sort-keys` / `-S`:
|
||||||
|
|
||||||
Output the fields of each object with the keys in sorted order.
|
Output the fields of each object with the keys in sorted order.
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ jv jv_object_iter_value(jv, int);
|
|||||||
|
|
||||||
int jv_get_refcnt(jv);
|
int jv_get_refcnt(jv);
|
||||||
|
|
||||||
enum { JV_PRINT_PRETTY = 1, JV_PRINT_ASCII = 2, JV_PRINT_COLOUR = 4, JV_PRINT_SORTED = 8 };
|
enum { JV_PRINT_PRETTY = 1, JV_PRINT_ASCII = 2, JV_PRINT_COLOUR = 4, JV_PRINT_SORTED = 8, JV_PRINT_UNBUFFERED = 16 };
|
||||||
void jv_dump(jv, int flags);
|
void jv_dump(jv, int flags);
|
||||||
jv jv_dump_string(jv, int flags);
|
jv jv_dump_string(jv, int flags);
|
||||||
|
|
||||||
|
|||||||
@@ -265,6 +265,9 @@ void jv_dump(jv x, int flags) {
|
|||||||
jvp_dtoa_context_init(&C);
|
jvp_dtoa_context_init(&C);
|
||||||
jv_dump_term(&C, x, flags, 0, stdout, 0);
|
jv_dump_term(&C, x, flags, 0, stdout, 0);
|
||||||
jvp_dtoa_context_free(&C);
|
jvp_dtoa_context_free(&C);
|
||||||
|
if (flags & JV_PRINT_UNBUFFERED) {
|
||||||
|
fflush(stdout);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
jv jv_dump_string(jv x, int flags) {
|
jv jv_dump_string(jv x, int flags) {
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ enum {
|
|||||||
COLOUR_OUTPUT = 64,
|
COLOUR_OUTPUT = 64,
|
||||||
NO_COLOUR_OUTPUT = 128,
|
NO_COLOUR_OUTPUT = 128,
|
||||||
SORTED_OUTPUT = 256,
|
SORTED_OUTPUT = 256,
|
||||||
|
UNBUFFERED_OUTPUT = 4096,
|
||||||
|
|
||||||
FROM_FILE = 512,
|
FROM_FILE = 512,
|
||||||
|
|
||||||
@@ -84,6 +85,7 @@ static void process(jq_state *jq, jv value, int flags) {
|
|||||||
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 & COLOUR_OUTPUT) dumpopts |= JV_PRINT_COLOUR;
|
||||||
if (options & NO_COLOUR_OUTPUT) dumpopts &= ~JV_PRINT_COLOUR;
|
if (options & NO_COLOUR_OUTPUT) dumpopts &= ~JV_PRINT_COLOUR;
|
||||||
|
if (options & UNBUFFERED_OUTPUT) dumpopts |= JV_PRINT_UNBUFFERED;
|
||||||
jv_dump(result, dumpopts);
|
jv_dump(result, dumpopts);
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
@@ -166,6 +168,8 @@ int main(int argc, char* argv[]) {
|
|||||||
options |= NO_COLOUR_OUTPUT;
|
options |= NO_COLOUR_OUTPUT;
|
||||||
} else if (isoption(argv[i], 'a', "ascii-output")) {
|
} else if (isoption(argv[i], 'a', "ascii-output")) {
|
||||||
options |= ASCII_OUTPUT;
|
options |= ASCII_OUTPUT;
|
||||||
|
} else if (isoption(argv[i], 0, "unbuffered")) {
|
||||||
|
options |= UNBUFFERED_OUTPUT;
|
||||||
} else if (isoption(argv[i], 'S', "sort-keys")) {
|
} else if (isoption(argv[i], 'S', "sort-keys")) {
|
||||||
options |= SORTED_OUTPUT;
|
options |= SORTED_OUTPUT;
|
||||||
} else if (isoption(argv[i], 'R', "raw-input")) {
|
} else if (isoption(argv[i], 'R', "raw-input")) {
|
||||||
|
|||||||
Reference in new issue
Block a user