From: Zbigniew Jędrzejewski-Szmek Date: Tue, 14 Dec 2021 11:25:10 +0000 (+0100) Subject: hostnamectl: add a chassis symbol in status output X-Git-Tag: v250-rc3~47 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=285a6908eb08f32b51e5ca9eae8a9317179d33c4;p=thirdparty%2Fsystemd.git hostnamectl: add a chassis symbol in status output The idea is to be able to distinguish whether we're in a VM/container or something more substantial at a glance. Chassis: laptop 💻 Chassis: tablet 具 Chassis: vm 🖴 Chassis: server 🖳 Chassis: handset 🕻 Chassis: watch ⌚ Chassis: desktop 🖥 Chassis: container ☐ --- diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c index b525aaa642f..58af5f186c6 100644 --- a/src/hostname/hostnamectl.c +++ b/src/hostname/hostnamectl.c @@ -53,6 +53,26 @@ typedef struct StatusInfo { const char *hardware_model; } StatusInfo; +static const char* chassis_string_to_glyph(const char *chassis) { + if (streq_ptr(chassis, "laptop")) + return "\U0001F4BB"; /* Personal Computer */ + if (streq_ptr(chassis, "desktop")) + return "\U0001F5A5"; /* Desktop Computer */ + if (streq_ptr(chassis, "server")) + return "\U0001F5B3"; /* Old Personal Computer */ + if (streq_ptr(chassis, "tablet")) + return "\u5177"; /* Ideograph tool, implement; draw up, write, looks vaguely tabletty */ + if (streq_ptr(chassis, "watch")) + return "\u231A"; /* Watch */ + if (streq_ptr(chassis, "handset")) + return "\U0001F57B"; /* Left Hand Telephone Receiver */ + if (streq_ptr(chassis, "vm")) + return "\U0001F5B4"; /* Hard disk */ + if (streq_ptr(chassis, "container")) + return "\u2610"; /* Ballot Box */ + return NULL; +} + static int print_status_info(StatusInfo *i) { _cleanup_(table_unrefp) Table *table = NULL; sd_id128_t mid = {}, bid = {}; @@ -108,9 +128,15 @@ static int print_status_info(StatusInfo *i) { } if (!isempty(i->chassis)) { + /* Possibly add a pretty symbol. Let's not bother with non-unicode fallbacks, because this is + * just a prettification and we can't really express this with ASCII anyway. */ + const char *v = chassis_string_to_glyph(i->chassis); + if (v) + v = strjoina(i->chassis, " ", v); + r = table_add_many(table, TABLE_STRING, "Chassis:", - TABLE_STRING, i->chassis); + TABLE_STRING, v ?: i->chassis); if (r < 0) return table_log_add_error(r); }