diff options
Diffstat (limited to 'libbb/progress.c')
-rw-r--r-- | libbb/progress.c | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/libbb/progress.c b/libbb/progress.c index 372feb0c2..3c2f01667 100644 --- a/libbb/progress.c +++ b/libbb/progress.c | |||
@@ -45,13 +45,6 @@ enum { | |||
45 | STALLTIME = 5 | 45 | STALLTIME = 5 |
46 | }; | 46 | }; |
47 | 47 | ||
48 | static unsigned int get_tty2_width(void) | ||
49 | { | ||
50 | unsigned width; | ||
51 | get_terminal_width_height(2, &width, NULL); | ||
52 | return width; | ||
53 | } | ||
54 | |||
55 | void FAST_FUNC bb_progress_init(bb_progress_t *p, const char *curfile) | 48 | void FAST_FUNC bb_progress_init(bb_progress_t *p, const char *curfile) |
56 | { | 49 | { |
57 | #if ENABLE_UNICODE_SUPPORT | 50 | #if ENABLE_UNICODE_SUPPORT |
@@ -80,7 +73,7 @@ void FAST_FUNC bb_progress_update(bb_progress_t *p, | |||
80 | { | 73 | { |
81 | uoff_t beg_and_transferred; | 74 | uoff_t beg_and_transferred; |
82 | unsigned since_last_update, elapsed; | 75 | unsigned since_last_update, elapsed; |
83 | int barlength; | 76 | int notty; |
84 | int kiloscale; | 77 | int kiloscale; |
85 | 78 | ||
86 | //transferred = 1234; /* use for stall detection testing */ | 79 | //transferred = 1234; /* use for stall detection testing */ |
@@ -137,18 +130,21 @@ void FAST_FUNC bb_progress_update(bb_progress_t *p, | |||
137 | } | 130 | } |
138 | } | 131 | } |
139 | 132 | ||
133 | notty = !isatty(STDERR_FILENO); | ||
134 | |||
140 | if (ENABLE_UNICODE_SUPPORT) | 135 | if (ENABLE_UNICODE_SUPPORT) |
141 | fprintf(stderr, "\r%s", p->curfile); | 136 | fprintf(stderr, "\r%s" + notty, p->curfile); |
142 | else | 137 | else |
143 | fprintf(stderr, "\r%-20.20s", p->curfile); | 138 | fprintf(stderr, "\r%-20.20s" + notty, p->curfile); |
144 | 139 | ||
145 | beg_and_transferred = beg_size + transferred; | 140 | beg_and_transferred = beg_size + transferred; |
146 | 141 | ||
147 | if (totalsize != 0) { | 142 | if (totalsize != 0) { |
143 | int barlength; | ||
148 | unsigned ratio = 100 * beg_and_transferred / totalsize; | 144 | unsigned ratio = 100 * beg_and_transferred / totalsize; |
149 | fprintf(stderr, "%4u%%", ratio); | 145 | fprintf(stderr, "%4u%%", ratio); |
150 | 146 | ||
151 | barlength = get_tty2_width() - 49; | 147 | barlength = get_terminal_width(2) - 49; |
152 | if (barlength > 0) { | 148 | if (barlength > 0) { |
153 | /* god bless gcc for variable arrays :) */ | 149 | /* god bless gcc for variable arrays :) */ |
154 | char buf[barlength + 1]; | 150 | char buf[barlength + 1]; |
@@ -204,4 +200,6 @@ void FAST_FUNC bb_progress_update(bb_progress_t *p, | |||
204 | hours = eta / 3600; | 200 | hours = eta / 3600; |
205 | fprintf(stderr, "%3u:%02u:%02u ETA", hours, secs / 60, secs % 60); | 201 | fprintf(stderr, "%3u:%02u:%02u ETA", hours, secs / 60, secs % 60); |
206 | } | 202 | } |
203 | if (notty) | ||
204 | fputc('\n', stderr); | ||
207 | } | 205 | } |