Blame SOURCES/0138-locale-util-add-logic-to-output-smiley-emojis-at-var.patch

a3e2b5
From bc00d9db41a87b7a4b92c46f277e62ad58768420 Mon Sep 17 00:00:00 2001
a3e2b5
From: Lennart Poettering <lennart@poettering.net>
a3e2b5
Date: Tue, 6 Nov 2018 17:59:58 +0100
a3e2b5
Subject: [PATCH] locale-util: add logic to output smiley emojis at various
a3e2b5
 happiness levels
a3e2b5
a3e2b5
(cherry picked from commit 5f1b0cc6d064f7847982e7b680cab3d080aef52e)
a3e2b5
a3e2b5
Conflicts:
a3e2b5
	doc/ENVIRONMENT.md
a3e2b5
	src/basic/locale-util.c
a3e2b5
	src/basic/locale-util.h
a3e2b5
	src/test/test-locale-util.c
a3e2b5
a3e2b5
Related: #1689832
a3e2b5
---
a3e2b5
 doc/ENVIRONMENT.md          |  5 +++
a3e2b5
 src/basic/locale-util.c     | 81 ++++++++++++++++++++++++++++---------
a3e2b5
 src/basic/locale-util.h     | 12 ++++++
a3e2b5
 src/test/test-locale-util.c | 12 +++++-
a3e2b5
 4 files changed, 90 insertions(+), 20 deletions(-)
a3e2b5
a3e2b5
diff --git a/doc/ENVIRONMENT.md b/doc/ENVIRONMENT.md
a3e2b5
index 85d26fe28c..1e648be640 100644
a3e2b5
--- a/doc/ENVIRONMENT.md
a3e2b5
+++ b/doc/ENVIRONMENT.md
a3e2b5
@@ -37,6 +37,11 @@ All tools:
a3e2b5
   useful for debugging, in order to test generators and other code against
a3e2b5
   specific kernel command lines.
a3e2b5
 
a3e2b5
+* `$SYSTEMD_EMOJI=0` — if set, tools such as "systemd-analyze security" will
a3e2b5
+  not output graphical smiley emojis, but ASCII alternatives instead. Note that
a3e2b5
+  this only controls use of Unicode emoji glyphs, and has no effect on other
a3e2b5
+  Unicode glyphs.
a3e2b5
+
a3e2b5
 systemctl:
a3e2b5
 
a3e2b5
 * `$SYSTEMCTL_FORCE_BUS=1` — if set, do not connect to PID1's private D-Bus
a3e2b5
diff --git a/src/basic/locale-util.c b/src/basic/locale-util.c
a3e2b5
index 3ad352f22f..7cd143ea6f 100644
a3e2b5
--- a/src/basic/locale-util.c
a3e2b5
+++ b/src/basic/locale-util.c
a3e2b5
@@ -16,6 +16,7 @@
a3e2b5
 
a3e2b5
 #include "def.h"
a3e2b5
 #include "dirent-util.h"
a3e2b5
+#include "env-util.h"
a3e2b5
 #include "fd-util.h"
a3e2b5
 #include "hashmap.h"
a3e2b5
 #include "locale-util.h"
a3e2b5
@@ -347,6 +348,24 @@ bool keymap_is_valid(const char *name) {
a3e2b5
         return true;
a3e2b5
 }
a3e2b5
 
a3e2b5
+static bool emoji_enabled(void) {
a3e2b5
+        static int cached_emoji_enabled = -1;
a3e2b5
+
a3e2b5
+        if (cached_emoji_enabled < 0) {
a3e2b5
+                int val;
a3e2b5
+
a3e2b5
+                val = getenv_bool("SYSTEMD_EMOJI");
a3e2b5
+                if (val < 0)
a3e2b5
+                        cached_emoji_enabled =
a3e2b5
+                                is_locale_utf8() &&
a3e2b5
+                                !STRPTR_IN_SET(getenv("TERM"), "dumb", "linux");
a3e2b5
+                else
a3e2b5
+                        cached_emoji_enabled = val;
a3e2b5
+        }
a3e2b5
+
a3e2b5
+        return cached_emoji_enabled;
a3e2b5
+}
a3e2b5
+
a3e2b5
 const char *special_glyph(SpecialGlyph code) {
a3e2b5
 
a3e2b5
         /* A list of a number of interesting unicode glyphs we can use to decorate our output. It's probably wise to be
a3e2b5
@@ -359,32 +378,56 @@ const char *special_glyph(SpecialGlyph code) {
a3e2b5
         static const char* const draw_table[2][_SPECIAL_GLYPH_MAX] = {
a3e2b5
                 /* ASCII fallback */
a3e2b5
                 [false] = {
a3e2b5
-                        [TREE_VERTICAL]      = "| ",
a3e2b5
-                        [TREE_BRANCH]        = "|-",
a3e2b5
-                        [TREE_RIGHT]         = "`-",
a3e2b5
-                        [TREE_SPACE]         = "  ",
a3e2b5
-                        [TRIANGULAR_BULLET]  = ">",
a3e2b5
-                        [BLACK_CIRCLE]       = "*",
a3e2b5
-                        [ARROW]              = "->",
a3e2b5
-                        [MDASH]              = "-",
a3e2b5
-                        [ELLIPSIS]           = "..."
a3e2b5
+                        [TREE_VERTICAL]           = "| ",
a3e2b5
+                        [TREE_BRANCH]             = "|-",
a3e2b5
+                        [TREE_RIGHT]              = "`-",
a3e2b5
+                        [TREE_SPACE]              = "  ",
a3e2b5
+                        [TRIANGULAR_BULLET]       = ">",
a3e2b5
+                        [BLACK_CIRCLE]            = "*",
a3e2b5
+                        [BULLET]                  = "*",
a3e2b5
+                        [ARROW]                   = "->",
a3e2b5
+                        [MDASH]                   = "-",
a3e2b5
+                        [ELLIPSIS]                = "...",
a3e2b5
+                        [MU]                      = "u",
a3e2b5
+                        [CHECK_MARK]              = "+",
a3e2b5
+                        [CROSS_MARK]              = "-",
a3e2b5
+                        [ECSTATIC_SMILEY]         = ":-]",
a3e2b5
+                        [HAPPY_SMILEY]            = ":-}",
a3e2b5
+                        [SLIGHTLY_HAPPY_SMILEY]   = ":-)",
a3e2b5
+                        [NEUTRAL_SMILEY]          = ":-|",
a3e2b5
+                        [SLIGHTLY_UNHAPPY_SMILEY] = ":-(",
a3e2b5
+                        [UNHAPPY_SMILEY]          = ":-{️",
a3e2b5
+                        [DEPRESSED_SMILEY]        = ":-[",
a3e2b5
                 },
a3e2b5
 
a3e2b5
                 /* UTF-8 */
a3e2b5
                 [true] = {
a3e2b5
-                        [TREE_VERTICAL]      = "\342\224\202 ",            /* │  */
a3e2b5
-                        [TREE_BRANCH]        = "\342\224\234\342\224\200", /* ├─ */
a3e2b5
-                        [TREE_RIGHT]         = "\342\224\224\342\224\200", /* └─ */
a3e2b5
-                        [TREE_SPACE]         = "  ",                       /*    */
a3e2b5
-                        [TRIANGULAR_BULLET]  = "\342\200\243",             /* ‣ */
a3e2b5
-                        [BLACK_CIRCLE]       = "\342\227\217",             /* ● */
a3e2b5
-                        [ARROW]              = "\342\206\222",             /* → */
a3e2b5
-                        [MDASH]              = "\342\200\223",             /* – */
a3e2b5
-                        [ELLIPSIS]           = "\342\200\246",             /* … */
a3e2b5
+                        [TREE_VERTICAL]           = "\342\224\202 ",            /* │  */
a3e2b5
+                        [TREE_BRANCH]             = "\342\224\234\342\224\200", /* ├─ */
a3e2b5
+                        [TREE_RIGHT]              = "\342\224\224\342\224\200", /* └─ */
a3e2b5
+                        [TREE_SPACE]              = "  ",                       /*    */
a3e2b5
+                        [TRIANGULAR_BULLET]       = "\342\200\243",             /* ‣ */
a3e2b5
+                        [BLACK_CIRCLE]            = "\342\227\217",             /* ● */
a3e2b5
+                        [BULLET]                  = "\342\200\242",             /* • */
a3e2b5
+                        [ARROW]                   = "\342\206\222",             /* → */
a3e2b5
+                        [MDASH]                   = "\342\200\223",             /* – */
a3e2b5
+                        [ELLIPSIS]                = "\342\200\246",             /* … */
a3e2b5
+                        [MU]                      = "\316\274",                 /* μ */
a3e2b5
+                        [CHECK_MARK]              = "\342\234\223",             /* ✓ */
a3e2b5
+                        [CROSS_MARK]              = "\342\234\227",             /* ✗ */
a3e2b5
+                        [ECSTATIC_SMILEY]         = "\360\237\230\207",         /* 😇 */
a3e2b5
+                        [HAPPY_SMILEY]            = "\360\237\230\200",         /* 😀 */
a3e2b5
+                        [SLIGHTLY_HAPPY_SMILEY]   = "\360\237\231\202",         /* 🙂 */
a3e2b5
+                        [NEUTRAL_SMILEY]          = "\360\237\230\220",         /* 😐 */
a3e2b5
+                        [SLIGHTLY_UNHAPPY_SMILEY] = "\360\237\231\201",         /* 🙁 */
a3e2b5
+                        [UNHAPPY_SMILEY]          = "\360\237\230\250",         /* 😨️️ */
a3e2b5
+                        [DEPRESSED_SMILEY]        = "\360\237\244\242",         /* 🤢 */
a3e2b5
                 },
a3e2b5
         };
a3e2b5
 
a3e2b5
-        return draw_table[is_locale_utf8()][code];
a3e2b5
+        assert(code < _SPECIAL_GLYPH_MAX);
a3e2b5
+
a3e2b5
+        return draw_table[code >= _SPECIAL_GLYPH_FIRST_SMILEY ? emoji_enabled() : is_locale_utf8()][code];
a3e2b5
 }
a3e2b5
 
a3e2b5
 static const char * const locale_variable_table[_VARIABLE_LC_MAX] = {
a3e2b5
diff --git a/src/basic/locale-util.h b/src/basic/locale-util.h
a3e2b5
index 775fe8bc72..368675f286 100644
a3e2b5
--- a/src/basic/locale-util.h
a3e2b5
+++ b/src/basic/locale-util.h
a3e2b5
@@ -45,9 +45,21 @@ typedef enum {
a3e2b5
         TREE_SPACE,
a3e2b5
         TRIANGULAR_BULLET,
a3e2b5
         BLACK_CIRCLE,
a3e2b5
+        BULLET,
a3e2b5
         ARROW,
a3e2b5
         MDASH,
a3e2b5
         ELLIPSIS,
a3e2b5
+        MU,
a3e2b5
+        CHECK_MARK,
a3e2b5
+        CROSS_MARK,
a3e2b5
+        _SPECIAL_GLYPH_FIRST_SMILEY,
a3e2b5
+        ECSTATIC_SMILEY = _SPECIAL_GLYPH_FIRST_SMILEY,
a3e2b5
+        HAPPY_SMILEY,
a3e2b5
+        SLIGHTLY_HAPPY_SMILEY,
a3e2b5
+        NEUTRAL_SMILEY,
a3e2b5
+        SLIGHTLY_UNHAPPY_SMILEY,
a3e2b5
+        UNHAPPY_SMILEY,
a3e2b5
+        DEPRESSED_SMILEY,
a3e2b5
         _SPECIAL_GLYPH_MAX
a3e2b5
 } SpecialGlyph;
a3e2b5
 
a3e2b5
diff --git a/src/test/test-locale-util.c b/src/test/test-locale-util.c
a3e2b5
index 8ffae8ca03..0c3f6a62ed 100644
a3e2b5
--- a/src/test/test-locale-util.c
a3e2b5
+++ b/src/test/test-locale-util.c
a3e2b5
@@ -65,7 +65,7 @@ static void test_keymaps(void) {
a3e2b5
 
a3e2b5
 #define dump_glyph(x) log_info(STRINGIFY(x) ": %s", special_glyph(x))
a3e2b5
 static void dump_special_glyphs(void) {
a3e2b5
-        assert_cc(ELLIPSIS + 1 == _SPECIAL_GLYPH_MAX);
a3e2b5
+        assert_cc(DEPRESSED_SMILEY + 1 == _SPECIAL_GLYPH_MAX);
a3e2b5
 
a3e2b5
         log_info("/* %s */", __func__);
a3e2b5
 
a3e2b5
@@ -80,6 +80,16 @@ static void dump_special_glyphs(void) {
a3e2b5
         dump_glyph(ARROW);
a3e2b5
         dump_glyph(MDASH);
a3e2b5
         dump_glyph(ELLIPSIS);
a3e2b5
+        dump_glyph(MU);
a3e2b5
+        dump_glyph(CHECK_MARK);
a3e2b5
+        dump_glyph(CROSS_MARK);
a3e2b5
+        dump_glyph(ECSTATIC_SMILEY);
a3e2b5
+        dump_glyph(HAPPY_SMILEY);
a3e2b5
+        dump_glyph(SLIGHTLY_HAPPY_SMILEY);
a3e2b5
+        dump_glyph(NEUTRAL_SMILEY);
a3e2b5
+        dump_glyph(SLIGHTLY_UNHAPPY_SMILEY);
a3e2b5
+        dump_glyph(UNHAPPY_SMILEY);
a3e2b5
+        dump_glyph(DEPRESSED_SMILEY);
a3e2b5
 }
a3e2b5
 
a3e2b5
 int main(int argc, char *argv[]) {