]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic: do not output emojis if not on a proper terminal
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 14 Dec 2022 14:39:26 +0000 (15:39 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 15 Dec 2022 03:56:03 +0000 (12:56 +0900)
$TERM would generally be set if we're connected to a proper graphical terminal
emulator. In all other cases, in particular if $TERM is not set, we almost
certainly are not connected to something that can output emojis. In particular
the text console is unlikely to ever do it correctly.

So let's invert the check, and only write emojis if $TERM is set.

Fixes #25521.

src/basic/glyph-util.c

index de1224f04fc11c825323ae3d9f4616750732519a..2833125ed99f07efa5a244a231ca8e6f153a6546 100644 (file)
@@ -9,15 +9,15 @@ bool emoji_enabled(void) {
         static int cached_emoji_enabled = -1;
 
         if (cached_emoji_enabled < 0) {
-                int val;
-
-                val = getenv_bool("SYSTEMD_EMOJI");
-                if (val < 0)
-                        cached_emoji_enabled =
-                                is_locale_utf8() &&
-                                !STRPTR_IN_SET(getenv("TERM"), "dumb", "linux");
-                else
-                        cached_emoji_enabled = val;
+                int val = getenv_bool("SYSTEMD_EMOJI");
+                if (val >= 0)
+                        return (cached_emoji_enabled = val);
+
+                const char *term = getenv("TERM");
+                if (!term || STR_IN_SET(term, "dumb", "linux"))
+                        return (cached_emoji_enabled = false);
+
+                cached_emoji_enabled = is_locale_utf8();
         }
 
         return cached_emoji_enabled;