diff --git a/cmd/zfs/zfs_main.c b/cmd/zfs/zfs_main.c index f918036cb9b7..d65b01579037 100644 --- a/cmd/zfs/zfs_main.c +++ b/cmd/zfs/zfs_main.c @@ -3556,8 +3556,21 @@ print_dataset(zfs_handle_t *zhp, list_cbdata_t *cb) right_justify = B_FALSE; } - if (pl->pl_prop == ZFS_PROP_AVAILABLE) - color_start(zfs_list_avail_color(zhp)); + /* + * zfs_list_avail_color() needs ZFS_PROP_AVAILABLE + USED + * - so we need another for() search for the USED part + * - when no colors wanted, we can skip the whole thing + */ + if (use_color() && pl->pl_prop == ZFS_PROP_AVAILABLE) { + zprop_list_t *pl2 = cb->cb_proplist; + for (; pl2 != NULL; pl2 = pl2->pl_next) { + if (pl2->pl_prop == ZFS_PROP_USED) { + color_start(zfs_list_avail_color(zhp)); + /* found it, no need for more loops */ + break; + } + } + } /* * If this is being called in scripted mode, or if this is the diff --git a/include/libzutil.h b/include/libzutil.h index 465e463f0c1f..237ff976ba62 100644 --- a/include/libzutil.h +++ b/include/libzutil.h @@ -182,6 +182,7 @@ struct zfs_cmd; #define ANSI_RESET "\033[0m" #define ANSI_BOLD "\033[1m" +_LIBZUTIL_H int use_color(void); _LIBZUTIL_H void color_start(const char *color); _LIBZUTIL_H void color_end(void); _LIBZUTIL_H int printf_color(const char *color, const char *format, ...); diff --git a/lib/libzfs/libzfs.abi b/lib/libzfs/libzfs.abi index 99e1b8cdf695..2b61710f5592 100644 --- a/lib/libzfs/libzfs.abi +++ b/lib/libzfs/libzfs.abi @@ -259,6 +259,7 @@ + @@ -5338,6 +5339,9 @@ + + + diff --git a/lib/libzfs/libzfs_util.c b/lib/libzfs/libzfs_util.c index 60695f8a63f4..393971ddf13c 100644 --- a/lib/libzfs/libzfs_util.c +++ b/lib/libzfs/libzfs_util.c @@ -1965,7 +1965,7 @@ zfs_version_print(void) * Return 1 if the user requested ANSI color output, and our terminal supports * it. Return 0 for no color. */ -static int +int use_color(void) { static int use_color = -1;