summaryrefslogtreecommitdiff
path: root/src/udev/udevadm-info.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-04-04 16:00:25 +0200
committerLennart Poettering <lennart@poettering.net>2022-04-04 18:25:16 +0200
commit13005c8f2c7f0169728fef804f164c3574b8e0f7 (patch)
tree3620c08b2e3cfdb3fa5cfab3284e726e5a6996f3 /src/udev/udevadm-info.c
parenta0e902598c9f5fbce55653f679e0ce91bc3369b7 (diff)
downloadsystemd-13005c8f2c7f0169728fef804f164c3574b8e0f7.tar.gz
udevadm: add a dash of color to "udevadm info"
Let's make it easier to discern the "header" of device records from the "body", i.e. non-property data from property data, by using some conservative coloring.
Diffstat (limited to 'src/udev/udevadm-info.c')
-rw-r--r--src/udev/udevadm-info.c41
1 files changed, 27 insertions, 14 deletions
diff --git a/src/udev/udevadm-info.c b/src/udev/udevadm-info.c
index 721c5665b3..73dbbcaa33 100644
--- a/src/udev/udevadm-info.c
+++ b/src/udev/udevadm-info.c
@@ -22,9 +22,10 @@
#include "static-destruct.h"
#include "string-table.h"
#include "string-util.h"
+#include "terminal-util.h"
#include "udev-util.h"
-#include "udevadm-util.h"
#include "udevadm.h"
+#include "udevadm-util.h"
typedef enum ActionType {
ACTION_QUERY,
@@ -184,47 +185,59 @@ static int print_record(sd_device *device) {
* uevents, not for those synthesized from database entries.
*
* We don't show sysattrs here, because they can be expensive and potentially issue expensive driver
- * IO. */
+ * IO.
+ *
+ * Coloring: let's be conservative with coloring. Let's use it to group related fields. Right now:
+ *
+ * • white for fields that give the device a name
+ * • green for fields that categorize the device into subsystem/devtype and similar
+ * • cyan for fields about associated device nodes/symlinks/network interfaces and such
+ * • magenta for block device diskseq
+ * • yellow for driver info
+ * • no color for regular properties */
assert_se(sd_device_get_devpath(device, &str) >= 0);
- printf("P: %s\n", str);
+ printf("P: %s%s%s\n", ansi_highlight_white(), str, ansi_normal());
if (sd_device_get_sysname(device, &str) >= 0)
- printf("M: %s\n", str);
+ printf("M: %s%s%s\n", ansi_highlight_white(), str, ansi_normal());
if (sd_device_get_sysnum(device, &str) >= 0)
- printf("R: %s\n", str);
+ printf("R: %s%s%s\n", ansi_highlight_white(), str, ansi_normal());
if (sd_device_get_subsystem(device, &subsys) >= 0)
- printf("U: %s\n", subsys);
+ printf("U: %s%s%s\n", ansi_highlight_green(), subsys, ansi_normal());
if (sd_device_get_devtype(device, &str) >= 0)
- printf("T: %s\n", str);
+ printf("T: %s%s%s\n", ansi_highlight_green(), str, ansi_normal());
if (sd_device_get_devnum(device, &devnum) >= 0)
- printf("D: %c %u:%u\n", streq_ptr(subsys, "block") ? 'b' : 'c', major(devnum), minor(devnum));
+ printf("D: %s%c %u:%u%s\n",
+ ansi_highlight_cyan(),
+ streq_ptr(subsys, "block") ? 'b' : 'c', major(devnum), minor(devnum),
+ ansi_normal());
if (sd_device_get_ifindex(device, &ifi) >= 0)
- printf("I: %i\n", ifi);
+ printf("I: %s%i%s\n", ansi_highlight_cyan(), ifi, ansi_normal());
if (sd_device_get_devname(device, &str) >= 0) {
assert_se(val = path_startswith(str, "/dev/"));
- printf("N: %s\n", val);
+ printf("N: %s%s%s\n", ansi_highlight_cyan(), val, ansi_normal());
if (device_get_devlink_priority(device, &i) >= 0)
- printf("L: %i\n", i);
+ printf("L: %s%i%s\n", ansi_highlight_cyan(), i, ansi_normal());
FOREACH_DEVICE_DEVLINK(device, str) {
assert_se(val = path_startswith(str, "/dev/"));
- printf("S: %s\n", val);
+ printf("S: %s%s%s\n", ansi_highlight_cyan(), val, ansi_normal());
}
}
if (sd_device_get_diskseq(device, &q) >= 0)
- printf("Q: %" PRIu64 "\n", q);
+ printf("Q: %s%" PRIu64 "%s\n", ansi_highlight_magenta(), q, ansi_normal());
if (sd_device_get_driver(device, &str) >= 0)
- printf("V: %s\n", str);
+ printf("V: %s%s%s\n", ansi_highlight_yellow4(), str, ansi_normal());
FOREACH_DEVICE_PROPERTY(device, str, val)
printf("E: %s=%s\n", str, val);