-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Colorize zpool status output #9340
Conversation
947f126
to
51e98a4
Compare
Looks like I'm seeing some test failures:
This is coming from ncurses:
Maybe we need https://unix.stackexchange.com/questions/213726/ssh-from-screen-leads-to-unknown-terminal-error I'm looking into it. |
Live demo from the 2018 OZDS hackathon, where this project won first place 🥇 : https://youtu.be/zN_tGxCpTBU?t=430 When do we get 🔥 emoji support? :-) |
Would it be possible to auto-detect if the terminal supports color and turn this on by default, like |
@ahrens one issue is that people screen scrape the zpool status output with awk. Each color escape code counts as a field in awk, so if we turned on color by default it's probably going to mess up the column counting in a bunch of scripts. I decided to pass on the emojis for now, since I didn't know of a good way to detect if they're supported in the terminal. And they're a little too silly :-) |
Generally, things like git use |
And --color[=yes|auto|no (default yes if --color supplied without a parameter)], defaulting to |
@lundman thanks for the suggestion about |
tty colors are a human factors disaster. theee is no way for the dev to know the contrast of the terminal’s colors. so the dev says “I think good things should be green” without realizing that some folks use green as the background, rendering it unreadable. the typical egregious colors are blue/black, but the real problem is you have no idea what the users preferences are. also cut-n-paste often picks up the background and foreground colors... spreading the ugliness. personally, I use different color backgrounds to differentiate being logged into different machines, workflows, or tasks. but the most telling story is recently a colleague did this in a product, when we went onsite with a customer, the customer’s preferences rendered more than 50% of the text unreadable. thus the product had to be changed to allow the customer to choose color combinations (of which there are thousands to choose from) for each and every possible rendering. human factors disaster compounded. just say no to colors by default |
lib/libzfs/libzfs_util.c
Outdated
#include <term.h> | ||
/* | ||
* For some reason, term.h #defines 'lines' (in lower case) as a macro. | ||
* Since we also have a variable named 'lines', undefine the macro here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though this works, I think we should go ahead and rename the our local lines
variable to avoid the conflict entirely. Then drop this block. According to the curses documentation, curs_terminfo(3X)
.
· If use_env(FALSE) has been called, values for lines and columns specified
in terminfo are used.
Which would be handy if we decide it's desirable to use more of the libraries functionality.
lib/libzfs/libzfs_util.c
Outdated
* If it's not supported, then silently don't use it. | ||
*/ | ||
if (setupterm(NULL, fileno(stdout), (int *)0) == 0 && | ||
tigetnum("colors") >= 16) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe && isatty(stdout)
for good measure.
lib/libzfs/libzfs_util.c
Outdated
color_start(color); | ||
|
||
va_start(aptr, format); | ||
vsprintf(buf, format, aptr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use vsnprintf()
here to avoid any overflow and make sure it's null-terminated.
man/man8/zpool.8
Outdated
Use ANSI color in | ||
.Nm zpool status | ||
output. | ||
.El |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move this up after ZFS_ABORT
to keep the environment variables alphabetically ordered. Moving
ZFS_VDEV_DEVID_OPT_OUT` up wouldn't be a bad thing either.
e404bf3
to
a9ebd98
Compare
It sounds like there's no consensus on colors on/off by default, so we'll keep them off unless you @behlendorf I implemented all your changes in my latest push. I'm still getting test failures in buildbot though, so I've added some instrumentation printfs. Please don't pull this in until I can get all the tests passing. |
93905e2
to
ca77753
Compare
tests/zfs-tests/tests/functional/cli_root/zpool/zpool_colors.ksh
Outdated
Show resolved
Hide resolved
tests/zfs-tests/tests/functional/cli_root/zpool/zpool_colors.ksh
Outdated
Show resolved
Hide resolved
tests/zfs-tests/tests/functional/cli_root/zpool/zpool_colors.ksh
Outdated
Show resolved
Hide resolved
tests/zfs-tests/tests/functional/cli_root/zpool/zpool_colors.ksh
Outdated
Show resolved
Hide resolved
tests/zfs-tests/tests/functional/cli_root/zpool/zpool_colors.ksh
Outdated
Show resolved
Hide resolved
385ddd9
to
e74fa97
Compare
@behlendorf my latest push fixes all your comments |
@lundman @freqlabs would you mind double checking this PR to ensure it does make sense for your respective platforms. We can f course tweak it latter if needed. By default, the colors are disabled so you will need to set the |
Looks to be standard porting, Yeah, should be fine to port over. |
tests/zfs-tests/tests/functional/cli_root/zpool/zpool_colors.ksh
Outdated
Show resolved
Hide resolved
@lundman @freqlabs thanks, I'll implement your changes. |
Codecov Report
@@ Coverage Diff @@
## master #9340 +/- ##
========================================
- Coverage 80% 79% -<1%
========================================
Files 385 385
Lines 121302 121467 +165
========================================
+ Hits 96526 96561 +35
- Misses 24776 24906 +130
Continue to review full report at Codecov.
|
tests/zfs-tests/tests/functional/cli_root/zpool/zpool_colors.ksh
Outdated
Show resolved
Hide resolved
tests/zfs-tests/tests/functional/cli_root/zpool/zpool_colors.ksh
Outdated
Show resolved
Hide resolved
If the ZFS_COLOR env variable is set, then use ANSI color output in zpool status: - Column headers are bold - Degraded or offline pools/vdevs are yellow - Non-zero error counters and faulted vdevs/pools are red - The 'status:' and 'action:' sections are yellow if they're displaying a warning. This also includes a new 'faketty' function in libtest.shlib that is compatible with FreeBSD (code provided by @freqlabs). Signed-off-by: Tony Hutter <[email protected]>
@behlendorf as a side note - we can probably remove |
Good call, will do. |
Motivation and Context
Add colored
zpool status
output so admins can quickly spot a unhealthy vdev/pool.Description
If the
ZFS_COLOR
env variable is set, then use ANSI color output inzpool status
:Screenshots:
How Has This Been Tested?
Manually tested. Added test case to look for bold, yellow and red text.
Types of changes
Checklist:
Signed-off-by
.