From 0a7ceb61519c2cfbf9362ab3d0579f2c005ba69b Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20Va=C5=A1ek?= Date: Thu, 19 Aug 2021 11:21:55 +0200 Subject: [PATCH] kjournalprint: add options for turning output colorization on and off --- doc/man/kjournalprint.8in | 12 +++++++++--- doc/man_kjournalprint.rst | 12 +++++++++--- src/utils/kjournalprint/main.c | 23 ++++++++++++++++------- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/doc/man/kjournalprint.8in b/doc/man/kjournalprint.8in index c9272869a7..de7defd144 100644 --- a/doc/man/kjournalprint.8in +++ b/doc/man/kjournalprint.8in @@ -49,9 +49,6 @@ Start at a specific SOA serial. \fB\-d\fP, \fB\-\-debug\fP Debug mode brief output. .TP -\fB\-n\fP, \fB\-\-no\-color\fP -Removes changes coloring. -.TP \fB\-z\fP, \fB\-\-zone\-list\fP Instead of reading the journal, display the list of zones in the DB. (\fIzone_name\fP not needed) @@ -59,6 +56,15 @@ Instead of reading the journal, display the list of zones in the DB. \fB\-c\fP, \fB\-\-check\fP Enable additional journal semantic checks during printing. .TP +\fB\-x\fP, \fB\-\-mono\fP +Don\(aqt generate colorized output. +.TP +\fB\-n\fP, \fB\-\-no\-color\fP +An alias for \fB\-x\fP\&. Use of this option is deprecated, it will be removed in the future. +.TP +\fB\-X\fP, \fB\-\-color\fP +Force colorized output. +.TP \fB\-h\fP, \fB\-\-help\fP Print the program help. .TP diff --git a/doc/man_kjournalprint.rst b/doc/man_kjournalprint.rst index 6574431e36..eb2161e4d7 100644 --- a/doc/man_kjournalprint.rst +++ b/doc/man_kjournalprint.rst @@ -26,9 +26,6 @@ Options **-d**, **--debug** Debug mode brief output. -**-n**, **--no-color** - Removes changes coloring. - **-z**, **--zone-list** Instead of reading the journal, display the list of zones in the DB. (*zone_name* not needed) @@ -36,6 +33,15 @@ Options **-c**, **--check** Enable additional journal semantic checks during printing. +**-x**, **--mono** + Don't generate colorized output. + +**-n**, **--no-color** + An alias for **-x**. Use of this option is deprecated, it will be removed in the future. + +**-X**, **--color** + Force colorized output. + **-h**, **--help** Print the program help. diff --git a/src/utils/kjournalprint/main.c b/src/utils/kjournalprint/main.c index 10dbcf431e..378e08fee7 100644 --- a/src/utils/kjournalprint/main.c +++ b/src/utils/kjournalprint/main.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "libknot/libknot.h" #include "knot/journal/journal_basic.h" @@ -38,11 +39,13 @@ static void print_help(void) "Parameters:\n" " -l, --limit Read only newest changes.\n" " -s, --serial Start with a specific SOA serial.\n" - " -n, --no-color Get output without terminal coloring.\n" " -z, --zone-list Instead of reading the journal, display the list\n" " of zones in the DB ( not needed).\n" " -c, --check Additional journal semantic checks.\n" " -d, --debug Debug mode output.\n" + " -x, --mono Get output without coloring.\n" + " -n, --no-color An alias for -x, deprecated.\n" + " -X, --color Force output coloring.\n" " -h, --help Print the program help.\n" " -V, --version Print the program version.\n", PROGRAM_NAME); @@ -295,7 +298,7 @@ int main(int argc, char *argv[]) print_params_t params = { .debug = false, - .color = true, + .color = isatty(STDOUT_FILENO), .check = false, .limit = -1, .from_serial = false, @@ -304,17 +307,19 @@ int main(int argc, char *argv[]) struct option opts[] = { { "limit", required_argument, NULL, 'l' }, { "serial", required_argument, NULL, 's' }, - { "no-color", no_argument, NULL, 'n' }, { "zone-list", no_argument, NULL, 'z' }, { "check", no_argument, NULL, 'c' }, { "debug", no_argument, NULL, 'd' }, + { "mono", no_argument, NULL, 'x' }, + { "no-color", no_argument, NULL, 'n' }, + { "color", no_argument, NULL, 'X' }, { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'V' }, { NULL } }; int opt = 0; - while ((opt = getopt_long(argc, argv, "l:s:nzcdhV", opts, NULL)) != -1) { + while ((opt = getopt_long(argc, argv, "l:s:zcdxnXhV", opts, NULL)) != -1) { switch (opt) { case 'l': if (str_to_int(optarg, ¶ms.limit, 0, INT_MAX) != KNOT_EOK) { @@ -329,9 +334,6 @@ int main(int argc, char *argv[]) } params.from_serial = true; break; - case 'n': - params.color = false; - break; case 'z': justlist = true; break; @@ -341,6 +343,13 @@ int main(int argc, char *argv[]) case 'd': params.debug = true; break; + case 'n': + case 'x': + params.color = false; + break; + case 'X': + params.color = true; + break; case 'h': print_help(); return EXIT_SUCCESS; -- 2.47.3