[PATCH] progress: use \r as EOL only if isatty(stderr) is true
From: Steffen Daode Nurpmeso <hidden>
Date: 2016-06-15 22:51:31
Subsystem:
the rest · Maintainer:
Linus Torvalds
So far progress always uses \r to produce one-line output on stderr. This only produces useful and easy parsable output if stderr is opened on a file which does interpret CR as a real carriage return operation. This patch changes EOL to the plain newline \n control if isatty() is false instead. Signed-off-by: Steffen Daode Nurpmeso <redacted> --- progress.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/progress.c b/progress.c
index 3971f49..c548de4 100644
--- a/progress.c
+++ b/progress.c@@ -27,6 +27,7 @@ struct throughput { struct progress { const char *title; + const char *eol; int last_value; unsigned total; unsigned last_percent;
@@ -90,7 +91,7 @@ static int display(struct progress *progress, unsigned n, const char *done) progress->last_value = n; tp = (progress->throughput) ? progress->throughput->display : ""; - eol = done ? done : " \r"; + eol = done ? done : progress->eol; if (progress->total) { unsigned percent = n * 100 / progress->total; if (percent != progress->last_percent || progress_update) {
@@ -219,6 +220,7 @@ struct progress *start_progress_delay(const char *title, unsigned total, return NULL; } progress->title = title; + progress->eol = isatty(fileno(stderr)) ? " \r" : "\n"; progress->total = total; progress->last_value = -1; progress->last_percent = -1;
--
1.7.6.rc0