#include <stdlib.h>
#include "alloc-util.h"
+#include "ansi-color.h"
#include "chase.h"
#include "dirent-util.h"
#include "env-file.h"
#include "errno-util.h"
+#include "escape.h"
#include "fd-util.h"
#include "fs-util.h"
#include "glyph-util.h"
return empty_to_null(pretty_name) ?:
empty_to_null(name) ?: "Linux";
}
+
+char *unescape_fancy_name(char **fancy_name) {
+ assert(fancy_name);
+
+ /* Checks if the fancy name is valid, unescapes if it is, nullifies it if not */
+
+ _cleanup_free_ char *unescaped_fancy_name = NULL;
+
+ if (isempty(*fancy_name))
+ goto clear;
+
+ /* We undo one level of C escapes on this */
+ ssize_t n = cunescape(*fancy_name, /* flags= */ 0, &unescaped_fancy_name);
+ if (n < 0) {
+ log_debug_errno((int) n, "Failed to unescape FANCY_NAME= string, suppressing: %m");
+ goto clear;
+ }
+
+ if (!utf8_is_valid(unescaped_fancy_name)) {
+ log_debug("Unescaped FANCY_NAME= string is not valid UTF-8, suppressing.");
+ goto clear;
+ }
+
+ free_and_replace(*fancy_name, unescaped_fancy_name);
+ return *fancy_name;
+
+clear:
+ *fancy_name = mfree(*fancy_name);
+ return NULL;
+}
+
+bool use_fancy_name(const char *fancy_name) {
+
+ /* Decides whether to show the specified fancy name */
+
+ if (isempty(fancy_name))
+ return false;
+
+ if (!colors_enabled())
+ return false;
+
+ return emoji_enabled() || ascii_is_valid(fancy_name);
+}
int os_release_support_ended(const char *support_end, bool quiet, usec_t *ret_eol);
const char* os_release_pretty_name(const char *pretty_name, const char *name);
+
+bool use_fancy_name(const char *fancy_name);
+char *unescape_fancy_name(char **fancy_name);
STATIC_DESTRUCTOR_REGISTER(arg_image_policy, image_policy_freep);
static void print_welcome(int rfd, sd_varlink **mute_console_link) {
- _cleanup_free_ char *pretty_name = NULL, *os_name = NULL, *ansi_color = NULL;
+ _cleanup_free_ char *pretty_name = NULL, *os_name = NULL, *ansi_color = NULL, *fancy_name = NULL;
static bool done = false;
const char *pn, *ac;
int r;
r = parse_os_release_at(rfd,
"PRETTY_NAME", &pretty_name,
+ "FANCY_NAME", &fancy_name,
"NAME", &os_name,
"ANSI_COLOR", &ansi_color);
if (r < 0)
pn = os_release_pretty_name(pretty_name, os_name);
ac = isempty(ansi_color) ? "0" : ansi_color;
- if (colors_enabled())
+ if (use_fancy_name(unescape_fancy_name(&fancy_name)))
+ printf(ANSI_HIGHLIGHT "Welcome to " ANSI_NORMAL "%s" ANSI_HIGHLIGHT "!" ANSI_NORMAL "\n", fancy_name);
+ else if (colors_enabled())
printf(ANSI_HIGHLIGHT "Welcome to " ANSI_NORMAL "\x1B[%sm%s" ANSI_HIGHLIGHT "!" ANSI_NORMAL "\n", ac, pn);
else
printf("Welcome to %s!\n", pn);
#include "log.h"
#include "main-func.h"
#include "options.h"
+#include "os-util.h"
#include "parse-argument.h"
#include "polkit-agent.h"
#include "pretty-print.h"
#include "runtime-scope.h"
#include "string-util.h"
#include "time-util.h"
-#include "utf8.h"
#include "verbs.h"
static bool arg_ask_password = true;
return table_log_add_error(r);
}
- if (!isempty(i->os_fancy_name) && (emoji_enabled() || ascii_is_valid(i->os_fancy_name)) && colors_enabled()) {
+ if (use_fancy_name(i->os_fancy_name)) {
r = table_add_many(table,
TABLE_FIELD, "Operating System",
TABLE_STRING_WITH_ANSI, i->os_fancy_name,
#include "device-private.h"
#include "env-file.h"
#include "env-util.h"
-#include "escape.h"
#include "extract-word.h"
#include "fileio.h"
#include "hashmap.h"
if (free_and_strdup(&c->data[PROP_OS_PRETTY_NAME], os_release_pretty_name(os_pretty_name, os_name)) < 0)
log_oom();
- if (!isempty(os_fancy_name)) {
- _cleanup_free_ char *unescaped = NULL;
-
- /* We undo one level of C escapes on this */
- ssize_t l = cunescape(os_fancy_name, /* flags= */ 0, &unescaped);
- if (l < 0) {
- log_warning_errno(l, "Failed to unescape fancy OS name, ignoring: %m");
- os_fancy_name = mfree(os_fancy_name);
- } else if (!utf8_is_valid(unescaped)) {
- log_warning("Unescaped fancy OS name contains invalid UTF-8, ignoring.");
- os_fancy_name = mfree(os_fancy_name);
- } else
- free_and_replace(os_fancy_name, unescaped);
- }
+ unescape_fancy_name(&os_fancy_name);
if (isempty(os_fancy_name)) {
free(os_fancy_name); /* free if empty string */
#include "parse-util.h"
#include "pretty-print.h"
#include "prompt-util.h"
+#include "stdio-util.h"
#include "string-util.h"
#include "strv.h"
#include "terminal-util.h"
_cleanup_free_ char *b = NULL, *ansi_color_reverse = NULL;
if (!bottom) {
- _cleanup_free_ char *pretty_name = NULL, *os_name = NULL, *ansi_color = NULL, *documentation_url = NULL;
+ _cleanup_free_ char *pretty_name = NULL, *os_name = NULL, *ansi_color = NULL, *documentation_url = NULL, *fancy_name = NULL;
r = parse_os_release(
/* root= */ NULL,
"PRETTY_NAME", &pretty_name,
+ "FANCY_NAME", &fancy_name,
"NAME", &os_name,
"ANSI_COLOR", &ansi_color,
"ANSI_COLOR_REVERSE", &ansi_color_reverse,
free_and_replace(ansi_color_reverse, j);
}
- if (asprintf(&b, "\x1B[0;%sm %s %s", c, m, ansi_color_reverse ?: ANSI_COLOR_CHROME) < 0)
+ if (use_fancy_name(unescape_fancy_name(&fancy_name)))
+ b = asprintf_safe("\x1B[0;%sm \x1B[0m%s\x1B[0;%sm %s", c, fancy_name, c, ansi_color_reverse ?: ANSI_COLOR_CHROME);
+ else
+ b = asprintf_safe("\x1B[0;%sm %s %s", c, m, ansi_color_reverse ?: ANSI_COLOR_CHROME);
+ if (!b)
return log_oom_debug();
if (documentation_url) {
}
static int print_welcome(sd_varlink **mute_console_link) {
- _cleanup_free_ char *pretty_name = NULL, *os_name = NULL, *ansi_color = NULL;
+ _cleanup_free_ char *pretty_name = NULL, *os_name = NULL, *ansi_color = NULL, *fancy_name = NULL;
const char *pn, *ac;
int r;
r = parse_os_release(
/* root= */ NULL,
"PRETTY_NAME", &pretty_name,
+ "FANCY_NAME", &fancy_name,
"NAME", &os_name,
"ANSI_COLOR", &ansi_color);
if (r < 0)
pn = os_release_pretty_name(pretty_name, os_name);
ac = isempty(ansi_color) ? "0" : ansi_color;
- if (colors_enabled())
+ if (use_fancy_name(unescape_fancy_name(&fancy_name)))
+ printf(ANSI_HIGHLIGHT "Welcome to the " ANSI_NORMAL "%s" ANSI_HIGHLIGHT " Installer!" ANSI_NORMAL "\n", fancy_name);
+ else if (colors_enabled())
printf(ANSI_HIGHLIGHT "Welcome to the " ANSI_NORMAL "\x1B[%sm%s" ANSI_HIGHLIGHT " Installer!" ANSI_NORMAL "\n", ac, pn);
else
printf("Welcome to the %s Installer!\n", pn);