Merge pull request #3392 from poettering/assorted-stuff

Assorted stuff
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2016-06-04 18:47:56 -04:00
19 changed files with 91 additions and 152 deletions
+4
View File
@@ -66,6 +66,10 @@ static inline bool isempty(const char *p) {
return !p || !p[0];
}
static inline const char *empty_to_null(const char *p) {
return isempty(p) ? NULL : p;
}
static inline char *startswith(const char *s, const char *prefix) {
size_t l;
+18 -7
View File
@@ -155,14 +155,14 @@ int ask_char(char *ret, const char *replies, const char *text, ...) {
char c;
bool need_nl = true;
if (on_tty())
if (colors_enabled())
fputs(ANSI_HIGHLIGHT, stdout);
va_start(ap, text);
vprintf(text, ap);
va_end(ap);
if (on_tty())
if (colors_enabled())
fputs(ANSI_NORMAL, stdout);
fflush(stdout);
@@ -199,14 +199,14 @@ int ask_string(char **ret, const char *text, ...) {
char line[LINE_MAX];
va_list ap;
if (on_tty())
if (colors_enabled())
fputs(ANSI_HIGHLIGHT, stdout);
va_start(ap, text);
vprintf(text, ap);
va_end(ap);
if (on_tty())
if (colors_enabled())
fputs(ANSI_NORMAL, stdout);
fflush(stdout);
@@ -1193,6 +1193,19 @@ int open_terminal_in_namespace(pid_t pid, const char *name, int mode) {
return receive_one_fd(pair[0], 0);
}
bool terminal_is_dumb(void) {
const char *e;
if (!on_tty())
return true;
e = getenv("TERM");
if (!e)
return true;
return streq(e, "dumb");
}
bool colors_enabled(void) {
static int enabled = -1;
@@ -1202,10 +1215,8 @@ bool colors_enabled(void) {
colors = getenv("SYSTEMD_COLORS");
if (colors)
enabled = parse_boolean(colors) != 0;
else if (streq_ptr(getenv("TERM"), "dumb"))
enabled = false;
else
enabled = on_tty();
enabled = !terminal_is_dumb();
}
return enabled;
+1
View File
@@ -80,6 +80,7 @@ unsigned lines(void);
void columns_lines_cache_reset(int _unused_ signum);
bool on_tty(void);
bool terminal_is_dumb(void);
bool colors_enabled(void);
static inline const char *ansi_underline(void) {