summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorRyo Nakamura <upa@haeena.net>2022-10-25 00:14:47 +0900
committerRyo Nakamura <upa@haeena.net>2022-10-25 00:14:47 +0900
commitc83927cd5a56111a11c2f7879c6e444b31eddb27 (patch)
treec4c6383991360020fda061def970dd3018fb012a /src/main.c
parent7ca4a85b767c2e13c715d06e7c0a133618ad935c (diff)
add copy start and done output
These fputs should be wrapped in a function and protected by a lock. todo.
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c39
1 files changed, 18 insertions, 21 deletions
diff --git a/src/main.c b/src/main.c
index 35fa07f..77f664d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -428,34 +428,31 @@ static void print_progress_bar(double percent, char *suffix)
* [=======> ] XX.X% SUFFIX
*/
+ buf[0] = '\0';
+
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) < 0)
return; /* XXX */
+ bar_width = min(sizeof(buf), ws.ws_col) - strlen(suffix) - 8;
- fputs("\r\033[K", stderr);
-
- bar_width = ws.ws_col - strlen(suffix) - 8;
- if (bar_width < 0)
- goto suffix_only;
-
- memset(buf, 0, sizeof(buf));
- thresh = floor(bar_width * (percent / 100)) - 1;
+ if (bar_width > 8) {
+ memset(buf, 0, sizeof(buf));
+ thresh = floor(bar_width * (percent / 100)) - 1;
-
- for (n = 1; n < bar_width - 1; n++) {
- if (n <= thresh)
- buf[n] = '=';
- else
- buf[n] = ' ';
+ for (n = 1; n < bar_width - 1; n++) {
+ if (n <= thresh)
+ buf[n] = '=';
+ else
+ buf[n] = ' ';
+ }
+ buf[thresh] = '>';
+ buf[0] = '[';
+ buf[bar_width - 1] = ']';
+ snprintf(buf + bar_width, sizeof(buf) - bar_width,
+ " %3d%% ", (int)floor(percent));
}
- buf[thresh] = '>';
- buf[0] = '[';
- buf[bar_width - 1] = ']';
-
- snprintf(buf + bar_width, sizeof(buf) - bar_width,
- " %3d%% ", (int)floor(percent));
+ fputs("\r\033[K", stderr);
fputs(buf, stderr);
-suffix_only:
fputs(suffix, stderr);
fflush(stderr);
}