summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Pitcock <nenolod@dereferenced.org>2017-06-01 05:25:56 +0000
committerWilliam Pitcock <nenolod@dereferenced.org>2017-06-01 05:25:56 +0000
commit17f8c2edec3c62d00d0a77b3d114540a6cb2ad9a (patch)
tree9b2f1816da350ee7b705c0ba5e54986dd9ca0859
parent40aee5f1d055461f17be6e1c564dee2679ba6e3c (diff)
downloadapk-tools-17f8c2edec3c62d00d0a77b3d114540a6cb2ad9a.tar.gz
apk-tools-17f8c2edec3c62d00d0a77b3d114540a6cb2ad9a.tar.bz2
apk-tools-17f8c2edec3c62d00d0a77b3d114540a6cb2ad9a.tar.xz
apk-tools-17f8c2edec3c62d00d0a77b3d114540a6cb2ad9a.zip
print: oh dear, i have reworked the progress bar again
- rework the progress bar a little bit, basically removing the [ and ] to give a more modern aesthetic. - if utf-8 locale is enabled, use unicode codepoint 0x2588 instead of # to give the progress bar a nicer look. - if APK_PROGRESS_CHAR environment variable is defined, use the character defined there for the progress bar.
-rw-r--r--src/print.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/print.c b/src/print.c
index ee89c43..63be863 100644
--- a/src/print.c
+++ b/src/print.c
@@ -22,6 +22,7 @@
int apk_progress_fd;
static int apk_screen_width = 0;
static int apk_progress_force = 1;
+static const char *apk_progress_char = "#";
void apk_reset_screen_width(void)
{
@@ -32,6 +33,8 @@ void apk_reset_screen_width(void)
int apk_get_screen_width(void)
{
struct winsize w;
+ const char *lang;
+ const char *progress_char;
if (apk_screen_width == 0) {
apk_screen_width = 50;
@@ -40,6 +43,13 @@ int apk_get_screen_width(void)
apk_screen_width = w.ws_col;
}
+ lang = getenv("LANG");
+ if (lang != NULL && strstr(lang, "UTF-8") != NULL)
+ apk_progress_char = "\u2588";
+
+ if ((progress_char = getenv("APK_PROGRESS_CHAR")) != NULL)
+ apk_progress_char = progress_char;
+
return apk_screen_width;
}
@@ -64,7 +74,7 @@ void apk_print_progress(size_t done, size_t total)
if (!(apk_flags & APK_PROGRESS))
return;
- bar_width = apk_get_screen_width() - 8;
+ bar_width = apk_get_screen_width() - 6;
if (total > 0) {
bar = muldiv(bar_width, done, total);
percent = muldiv(100, done, total);
@@ -77,12 +87,13 @@ void apk_print_progress(size_t done, size_t total)
last_percent = percent;
apk_progress_force = 0;
- fprintf(stdout, "\e7%3i%% [", percent);
+ fprintf(stdout, "\e7%3i%% ", percent);
+
for (i = 0; i < bar; i++)
- fputc('#', stdout);
+ fputs(apk_progress_char, stdout);
for (; i < bar_width; i++)
fputc(' ', stdout);
- fputc(']', stdout);
+
fflush(stdout);
fputs("\e8\e[0K", stdout);
}