From 48d70b4ac9cca12f24ce1105e1571c1493aaa259 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 15 Apr 2020 11:58:25 +0200 Subject: [PATCH 1/4] locale-util: add support for lock+key emoji It looks pretty nice on gnome-terminal at least, let's make use of it when asking for passwords. --- src/basic/locale-util.c | 6 +++++- src/basic/locale-util.h | 5 +++-- src/test/test-locale-util.c | 3 ++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/basic/locale-util.c b/src/basic/locale-util.c index 96151ffbf8..c367c03a4a 100644 --- a/src/basic/locale-util.c +++ b/src/basic/locale-util.c @@ -357,6 +357,7 @@ const char *special_glyph(SpecialGlyph code) { [SPECIAL_GLYPH_SLIGHTLY_UNHAPPY_SMILEY] = ":-(", [SPECIAL_GLYPH_UNHAPPY_SMILEY] = ":-{", [SPECIAL_GLYPH_DEPRESSED_SMILEY] = ":-[", + [SPECIAL_GLYPH_LOCK_AND_KEY] = "o-," }, /* UTF-8 */ @@ -392,12 +393,15 @@ const char *special_glyph(SpecialGlyph code) { [SPECIAL_GLYPH_SLIGHTLY_UNHAPPY_SMILEY] = "\360\237\231\201", /* 🙁 (actually called: SLIGHTLY FROWNING FACE) */ [SPECIAL_GLYPH_UNHAPPY_SMILEY] = "\360\237\230\250", /* 😨 (actually called: FEARFUL FACE) */ [SPECIAL_GLYPH_DEPRESSED_SMILEY] = "\360\237\244\242", /* 🤢 (actually called: NAUSEATED FACE) */ + + /* This emoji is a single character cell glyph in Unicode, and three in ASCII */ + [SPECIAL_GLYPH_LOCK_AND_KEY] = "\360\237\224\220", /* 🔐 (actually called: CLOSED LOCK WITH KEY) */ }, }; assert(code < _SPECIAL_GLYPH_MAX); - return draw_table[code >= _SPECIAL_GLYPH_FIRST_SMILEY ? emoji_enabled() : is_locale_utf8()][code]; + return draw_table[code >= _SPECIAL_GLYPH_FIRST_EMOJI ? emoji_enabled() : is_locale_utf8()][code]; } void locale_variables_free(char *l[_VARIABLE_LC_MAX]) { diff --git a/src/basic/locale-util.h b/src/basic/locale-util.h index cefc4e7f0e..9c85928e16 100644 --- a/src/basic/locale-util.h +++ b/src/basic/locale-util.h @@ -54,14 +54,15 @@ typedef enum { SPECIAL_GLYPH_LIGHT_SHADE, SPECIAL_GLYPH_DARK_SHADE, SPECIAL_GLYPH_SIGMA, - _SPECIAL_GLYPH_FIRST_SMILEY, - SPECIAL_GLYPH_ECSTATIC_SMILEY = _SPECIAL_GLYPH_FIRST_SMILEY, + _SPECIAL_GLYPH_FIRST_EMOJI, + SPECIAL_GLYPH_ECSTATIC_SMILEY = _SPECIAL_GLYPH_FIRST_EMOJI, SPECIAL_GLYPH_HAPPY_SMILEY, SPECIAL_GLYPH_SLIGHTLY_HAPPY_SMILEY, SPECIAL_GLYPH_NEUTRAL_SMILEY, SPECIAL_GLYPH_SLIGHTLY_UNHAPPY_SMILEY, SPECIAL_GLYPH_UNHAPPY_SMILEY, SPECIAL_GLYPH_DEPRESSED_SMILEY, + SPECIAL_GLYPH_LOCK_AND_KEY, _SPECIAL_GLYPH_MAX } SpecialGlyph; diff --git a/src/test/test-locale-util.c b/src/test/test-locale-util.c index f49cc6371e..e7a22797bb 100644 --- a/src/test/test-locale-util.c +++ b/src/test/test-locale-util.c @@ -67,7 +67,7 @@ static void test_keymaps(void) { #define dump_glyph(x) log_info(STRINGIFY(x) ": %s", special_glyph(x)) static void dump_special_glyphs(void) { - assert_cc(SPECIAL_GLYPH_DEPRESSED_SMILEY + 1 == _SPECIAL_GLYPH_MAX); + assert_cc(SPECIAL_GLYPH_LOCK_AND_KEY + 1 == _SPECIAL_GLYPH_MAX); log_info("/* %s */", __func__); @@ -92,6 +92,7 @@ static void dump_special_glyphs(void) { dump_glyph(SPECIAL_GLYPH_SLIGHTLY_UNHAPPY_SMILEY); dump_glyph(SPECIAL_GLYPH_UNHAPPY_SMILEY); dump_glyph(SPECIAL_GLYPH_DEPRESSED_SMILEY); + dump_glyph(SPECIAL_GLYPH_LOCK_AND_KEY); } int main(int argc, char *argv[]) { From 539ee0989eca9a85371cb629e44e177776da7136 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 15 Apr 2020 11:59:06 +0200 Subject: [PATCH 2/4] locale-util: export emoji_enable() for other code to use --- src/basic/locale-util.c | 2 +- src/basic/locale-util.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/basic/locale-util.c b/src/basic/locale-util.c index c367c03a4a..e4ce289c51 100644 --- a/src/basic/locale-util.c +++ b/src/basic/locale-util.c @@ -305,7 +305,7 @@ out: return (bool) cached_answer; } -static bool emoji_enabled(void) { +bool emoji_enabled(void) { static int cached_emoji_enabled = -1; if (cached_emoji_enabled < 0) { diff --git a/src/basic/locale-util.h b/src/basic/locale-util.h index 9c85928e16..7d77fa2bda 100644 --- a/src/basic/locale-util.h +++ b/src/basic/locale-util.h @@ -68,6 +68,8 @@ typedef enum { const char *special_glyph(SpecialGlyph code) _const_; +bool emoji_enabled(void); + const char* locale_variable_to_string(LocaleVariable i) _const_; LocaleVariable locale_variable_from_string(const char *s) _pure_; From 52d199e318b8fc0428f5753d999899a55ebbb2b4 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 15 Apr 2020 11:59:30 +0200 Subject: [PATCH 3/4] ask-password: prefix password questions with lock and key emoji It's pretty, and it highlights that the pw prompt is kinda special and needs user input. We suppress the emoji entirel if there's no emoji support (i.e. this means we suppress the ASCII replacement), since it carries no additional information, it is just decoration to highlight a line. --- src/shared/ask-password-api.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c index b64663bd1e..3a76ea4f67 100644 --- a/src/shared/ask-password-api.c +++ b/src/shared/ask-password-api.c @@ -27,6 +27,7 @@ #include "format-util.h" #include "fs-util.h" #include "io-util.h" +#include "locale-util.h" #include "log.h" #include "macro.h" #include "memory-util.h" @@ -430,6 +431,9 @@ int ask_password_tty( if (!message) message = "Password:"; + if (emoji_enabled()) + message = strjoina(special_glyph(SPECIAL_GLYPH_LOCK_AND_KEY), " ", message); + if (flag_file || ((flags & ASK_PASSWORD_ACCEPT_CACHED) && keyname)) { notify = inotify_init1(IN_CLOEXEC|IN_NONBLOCK); if (notify < 0) From e3ac53a27ddf022d427b590bdcc920d5571c8bfc Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 15 Apr 2020 12:01:03 +0200 Subject: [PATCH 4/4] ask-password-api: reword some debug messages Otherwise, seeing this in the log output is confusing since we don't know what kind of timeout or what kind if key we are adjusting here. --- src/shared/ask-password-api.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c index 3a76ea4f67..9b74d909b1 100644 --- a/src/shared/ask-password-api.c +++ b/src/shared/ask-password-api.c @@ -135,12 +135,12 @@ static int add_to_keyring(const char *keyname, AskPasswordFlags flags, char **pa if (keyctl(KEYCTL_SET_TIMEOUT, (unsigned long) serial, (unsigned long) DIV_ROUND_UP(KEYRING_TIMEOUT_USEC, USEC_PER_SEC), 0, 0) < 0) - log_debug_errno(errno, "Failed to adjust timeout: %m"); + log_debug_errno(errno, "Failed to adjust kernel keyring key timeout: %m"); /* Tell everyone to check the keyring */ (void) touch("/run/systemd/ask-password"); - log_debug("Added key to keyring as %" PRIi32 ".", serial); + log_debug("Added key to kernel keyring as %" PRIi32 ".", serial); return 1; } @@ -152,7 +152,7 @@ static int add_to_keyring_and_log(const char *keyname, AskPasswordFlags flags, c r = add_to_keyring(keyname, flags, passwords); if (r < 0) - return log_debug_errno(r, "Failed to add password to keyring: %m"); + return log_debug_errno(r, "Failed to add password to kernel keyring: %m"); return 0; }