X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Futil.c;h=7450565567bf8036affcfe11efea7235d59b12a1;hp=3179502f6c01466b3614fba82d1699ffc1337986;hb=3043935f02da2e680b37cf282587106ad05440ee;hpb=7e4ab3c5a6295193d0c58d353b6430265d842f34 diff --git a/src/util.c b/src/util.c index 3179502f6..745056556 100644 --- a/src/util.c +++ b/src/util.c @@ -2467,14 +2467,14 @@ int ask(char *ret, const char *replies, const char *text, ...) { bool need_nl = true; if (on_tty) - fputs("\x1B[1m", stdout); + fputs(ANSI_HIGHLIGHT_ON, stdout); va_start(ap, text); vprintf(text, ap); va_end(ap); if (on_tty) - fputs("\x1B[0m", stdout); + fputs(ANSI_HIGHLIGHT_OFF, stdout); fflush(stdout); @@ -4402,31 +4402,37 @@ int vtnr_from_tty(const char *tty) { return i; } -const char *default_term_for_tty(const char *tty) { +bool tty_is_vc_resolve(const char *tty) { char *active = NULL; - const char *term; + bool b; assert(tty); if (startswith(tty, "/dev/")) tty += 5; - /* Resolve where /dev/console is pointing when determining - * TERM */ + /* Resolve where /dev/console is pointing to */ if (streq(tty, "console")) if (read_one_line_file("/sys/class/tty/console/active", &active) >= 0) { /* If multiple log outputs are configured the * last one is what /dev/console points to */ - if ((tty = strrchr(active, ' '))) + tty = strrchr(active, ' '); + if (tty) tty++; else tty = active; } - term = tty_is_vc(tty) ? "TERM=linux" : "TERM=vt100"; + b = tty_is_vc(tty); free(active); - return term; + return b; +} + +const char *default_term_for_tty(const char *tty) { + assert(tty); + + return tty_is_vc_resolve(tty) ? "TERM=linux" : "TERM=vt100"; } bool dirent_is_file(const struct dirent *de) {