diff options
Diffstat (limited to 'src/common.c')
-rw-r--r-- | src/common.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/common.c b/src/common.c index e1bfaaf..812431a 100644 --- a/src/common.c +++ b/src/common.c @@ -47,27 +47,26 @@ char* trim(char* str) { } void print_bar(int width, float percent, char* buf) { - double fill = width * percent; + int fill_maj = width * percent; + int fill_min = (width * percent - fill_maj) * 10; int i = 1; - int remainder = 0; buf[0] = '['; - while(i < fill) { + while(i <= fill_maj) { buf[i] = ':'; i++; } - remainder = (fill + 1 - i) * 10; - if(i > fill && remainder >= 5.0) { - buf[i] = ':'; - i++; - } else if(i > fill && remainder < 5.0 && remainder > 0) { - buf[i] = '.'; + if(fill_maj > 0 && fill_min > 0) { + if(fill_min >= 5) + buf[i] = ':'; + else + buf[i] = '.'; i++; } - while(i < width) { + while(i <= width) { buf[i] = ' '; i++; } |