From 564e6a3d2376e39b837e707b740e2034a433c23b Mon Sep 17 00:00:00 2001 From: Tino Reichardt Date: Mon, 13 Mar 2023 23:23:04 +0100 Subject: [PATCH] Add more ANSI colors to libzfs Signed-off-by: Ethan Coe-Renner Signed-off-by: Tino Reichardt --- include/libzutil.h | 6 ++++++ lib/libzfs/libzfs_diff.c | 6 +++--- lib/libzfs/libzfs_util.c | 13 ++++++++----- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/include/libzutil.h b/include/libzutil.h index 948ac08cd7..465e463f0c 100644 --- a/include/libzutil.h +++ b/include/libzutil.h @@ -169,10 +169,16 @@ struct zfs_cmd; /* * List of colors to use */ +#define ANSI_BLACK "\033[0;30m" #define ANSI_RED "\033[0;31m" #define ANSI_GREEN "\033[0;32m" #define ANSI_YELLOW "\033[0;33m" #define ANSI_BLUE "\033[0;34m" +#define ANSI_BOLD_BLUE "\033[1;34m" /* light blue */ +#define ANSI_MAGENTA "\033[0;35m" +#define ANSI_CYAN "\033[0;36m" +#define ANSI_GRAY "\033[0;37m" + #define ANSI_RESET "\033[0m" #define ANSI_BOLD "\033[1m" diff --git a/lib/libzfs/libzfs_diff.c b/lib/libzfs/libzfs_diff.c index 1330e7c305..da2b26ef99 100644 --- a/lib/libzfs/libzfs_diff.c +++ b/lib/libzfs/libzfs_diff.c @@ -55,10 +55,10 @@ #define ZDIFF_REMOVED '-' #define ZDIFF_RENAMED "R" -#define ZDIFF_ADDED_COLOR ANSI_GREEN +#define ZDIFF_ADDED_COLOR ANSI_GREEN #define ZDIFF_MODIFIED_COLOR ANSI_YELLOW -#define ZDIFF_REMOVED_COLOR ANSI_RED -#define ZDIFF_RENAMED_COLOR ANSI_BLUE +#define ZDIFF_REMOVED_COLOR ANSI_RED +#define ZDIFF_RENAMED_COLOR ANSI_BOLD_BLUE /* * Given a {dsname, object id}, get the object path diff --git a/lib/libzfs/libzfs_util.c b/lib/libzfs/libzfs_util.c index 2507bfecdc..ad5343a080 100644 --- a/lib/libzfs/libzfs_util.c +++ b/lib/libzfs/libzfs_util.c @@ -2011,10 +2011,11 @@ use_color(void) } /* - * color_start() and color_end() are used for when you want to colorize a block - * of text. For example: + * The functions color_start() and color_end() are used for when you want + * to colorize a block of text. * - * color_start(ANSI_RED_FG) + * For example: + * color_start(ANSI_RED) * printf("hello"); * printf("world"); * color_end(); @@ -2022,7 +2023,7 @@ use_color(void) void color_start(const char *color) { - if (use_color()) { + if (color && use_color()) { fputs(color, stdout); fflush(stdout); } @@ -2038,7 +2039,9 @@ color_end(void) } -/* printf() with a color. If color is NULL, then do a normal printf. */ +/* + * printf() with a color. If color is NULL, then do a normal printf. + */ int printf_color(const char *color, const char *format, ...) {