]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic/glyph-util: introduce optional_glyph() to wrap emoji_enabled()
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 9 Mar 2025 09:43:25 +0000 (10:43 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 15 Mar 2025 13:40:52 +0000 (14:40 +0100)
src/basic/glyph-util.c
src/basic/glyph-util.h
src/systemctl/systemctl.c

index dd16dad9b670b92274a4b45ac05d59653631937b..2380f60606c881071e3a5c4c83c9ba8827c9bc4e 100644 (file)
@@ -35,6 +35,7 @@ const char* glyph_full(Glyph code, bool force_utf) {
         static const char* const draw_table[2][_GLYPH_MAX] = {
                 /* ASCII fallback */
                 [false] = {
+                        [GLYPH_SPACE]                   = " ",
                         [GLYPH_TREE_VERTICAL]           = "| ",
                         [GLYPH_TREE_BRANCH]             = "|-",
                         [GLYPH_TREE_RIGHT]              = "`-",
@@ -87,6 +88,9 @@ const char* glyph_full(Glyph code, bool force_utf) {
 
                 /* UTF-8 */
                 [true] = {
+                        /* This exists to allow more consistent handling of optional whitespace */
+                        [GLYPH_SPACE]                   = " ",
+
                         /* The following are multiple glyphs in both ASCII and in UNICODE */
                         [GLYPH_TREE_VERTICAL]           = u8"│ ",
                         [GLYPH_TREE_BRANCH]             = u8"├─",
index cb2fc78b07de3abee16fe92b683738fa005393fd..730f26956002ce0b18ae7cde029bb50be04419b3 100644 (file)
@@ -7,6 +7,7 @@
 #include "macro.h"
 
 typedef enum Glyph {
+        GLYPH_SPACE,
         GLYPH_TREE_VERTICAL,
         GLYPH_TREE_BRANCH,
         GLYPH_TREE_RIGHT,
@@ -70,6 +71,10 @@ static inline const char* glyph(Glyph code) {
         return glyph_full(code, false);
 }
 
+static inline const char* optional_glyph(Glyph code) {
+        return emoji_enabled() ? glyph(code) : "";
+}
+
 static inline const char* glyph_check_mark(bool b) {
         return b ? glyph(GLYPH_CHECK_MARK) : glyph(GLYPH_CROSS_MARK);
 }
index 51b4af47437a43d2c7886f60ee6764b54593474d..840b1b3584590d5583e8a03680356afa0bde36b1 100644 (file)
@@ -1274,8 +1274,8 @@ static int run(int argc, char *argv[]) {
                          "%s%s/proc/ is not mounted. This is not a supported mode of operation. Please fix\n"
                          "your invocation environment to mount /proc/ and /sys/ properly. Proceeding anyway.\n"
                          "Your mileage may vary.",
-                         emoji_enabled() ? glyph(GLYPH_WARNING_SIGN) : "",
-                         emoji_enabled() ? " " : "");
+                         optional_glyph(GLYPH_WARNING_SIGN),
+                         optional_glyph(GLYPH_SPACE));
 
         if (arg_action != ACTION_SYSTEMCTL && running_in_chroot() > 0) {
                 if (!arg_quiet)