/* * hbar * * create a horizontal progres bar across the screen */ #include #include #include #include #include #include #include "colors.h" #define DEFAULT_COLOR BLACK BG_WHITE #define DEFAULT_RESET WHITE BG_DEFAULT #define SAVE_POS "\033[s" #define LOAD_POS "\033[u" void human_format(int bytes, char *output) { char *suffix[] = {"B", "KB", "MB", "GB", "TB"}; char length = sizeof(suffix) / sizeof(suffix[0]); int i = 0; double dblBytes = bytes; if (bytes > 1024) { for (i = 0; (bytes / 1024) > 0 && i 0) { float percent = (float) completed / (float) total; reset_at = percent * width; } if (i == reset_at) { printf(reset); } if (text && i < len(text)) { printf("%c", text[i]); } else if (i + 1 > width - len(count)) { printf("%c", count[i - width + len(count)]); } else { printf(" "); } } if (line != -1) { printf("\033[%dB", line); } if (terminate) { printf(RESET "\n"); } return 0; }