summaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-09-17 02:10:08 +0200
committerLennart Poettering <lennart@poettering.net>2010-09-17 02:10:08 +0200
commit1b39d4b9d271f2309a193d4e4fae6633248b0e94 (patch)
tree4a5f63b2d36ad5124dec91dc56bb7c1161e67c17 /src/util.c
parent490aed584944b684026a3fd01f8d81f2881e38d6 (diff)
ask-password: optionally ask questions on tty
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/util.c b/src/util.c
index c1ee936aaf..bdc194e80c 100644
--- a/src/util.c
+++ b/src/util.c
@@ -2009,23 +2009,29 @@ int read_one_char(FILE *f, char *ret, bool *need_nl) {
}
int ask(char *ret, const char *replies, const char *text, ...) {
+ bool on_tty;
+
assert(ret);
assert(replies);
assert(text);
+ on_tty = isatty(STDOUT_FILENO);
+
for (;;) {
va_list ap;
char c;
int r;
bool need_nl = true;
- fputs("\x1B[1m", stdout);
+ if (on_tty)
+ fputs("\x1B[1m", stdout);
va_start(ap, text);
vprintf(text, ap);
va_end(ap);
- fputs("\x1B[0m", stdout);
+ if (on_tty)
+ fputs("\x1B[0m", stdout);
fflush(stdout);