mirror of
https://github.com/systemd/systemd.git
synced 2024-10-30 14:55:37 +03:00
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 ☐
This commit is contained in:
parent
020d41ce4f
commit
285a6908eb
@ -53,6 +53,26 @@ typedef struct StatusInfo {
|
|||||||
const char *hardware_model;
|
const char *hardware_model;
|
||||||
} StatusInfo;
|
} 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) {
|
static int print_status_info(StatusInfo *i) {
|
||||||
_cleanup_(table_unrefp) Table *table = NULL;
|
_cleanup_(table_unrefp) Table *table = NULL;
|
||||||
sd_id128_t mid = {}, bid = {};
|
sd_id128_t mid = {}, bid = {};
|
||||||
@ -108,9 +128,15 @@ static int print_status_info(StatusInfo *i) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!isempty(i->chassis)) {
|
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,
|
r = table_add_many(table,
|
||||||
TABLE_STRING, "Chassis:",
|
TABLE_STRING, "Chassis:",
|
||||||
TABLE_STRING, i->chassis);
|
TABLE_STRING, v ?: i->chassis);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return table_log_add_error(r);
|
return table_log_add_error(r);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user