chiark / gitweb /
tty-ask-password-agent: reenable color for boot-time password prompt
authorLennart Poettering <lennart@poettering.net>
Wed, 14 Feb 2018 13:30:30 +0000 (14:30 +0100)
committerSven Eden <yamakuzure@gmx.net>
Wed, 30 May 2018 05:58:55 +0000 (07:58 +0200)
The password prompt used to be highlighted, and that was a good thing.
Let's fix things to make the prompt highlighted again.

Fixes: #3853
src/basic/terminal-util.c
src/basic/terminal-util.h

index 31415024f101efaea39918384ec94896ef6bde67..39d3e2ce3ebfd3dcc0b4ffc0beefa38e7424cd4a 100644 (file)
@@ -48,6 +48,8 @@
 #include "log.h"
 #include "macro.h"
 #include "parse-util.h"
+//#include "path-util.h"
+//#include "proc-cmdline.h"
 #include "process-util.h"
 #include "socket-util.h"
 #include "stat-util.h"
@@ -1246,6 +1248,27 @@ bool colors_enabled(void) {
         return cached_colors_enabled;
 }
 
+bool dev_console_colors_enabled(void) {
+        _cleanup_free_ char *s = NULL;
+        int b;
+
+        /* Returns true if we assume that color is supported on /dev/console.
+         *
+         * For that we first check if we explicitly got told to use colors or not, by checking $SYSTEMD_COLORS. If that
+         * didn't tell us anything we check whether PID 1 has $TERM set, and if not whether $TERM is set on the kernel
+         * command line. If we find $TERM set we assume color if it's not set to "dumb", similar to regular
+         * colors_enabled() operates. */
+
+        b = getenv_bool("SYSTEMD_COLORS");
+        if (b >= 0)
+                return b;
+
+        if (getenv_for_pid(1, "TERM", &s) <= 0)
+                (void) proc_cmdline_get_key("TERM", 0, &s);
+
+        return !streq_ptr(s, "dumb");
+}
+
 bool underline_enabled(void) {
 
         if (cached_underline_enabled < 0) {
index 93d8b38dbfb237303072cc53933ca0919cb4e635..4f39bc034601b80607b26ac486b1ceda84174ad5 100644 (file)
@@ -120,6 +120,7 @@ bool on_tty(void);
 bool terminal_is_dumb(void);
 bool colors_enabled(void);
 bool underline_enabled(void);
+bool dev_console_colors_enabled(void);
 
 #define DEFINE_ANSI_FUNC(name, NAME)                            \
         static inline const char *ansi_##name(void) {           \