diff options
author | davidovski <david@davidovski.xyz> | 2022-02-13 22:35:27 +0000 |
---|---|---|
committer | davidovski <david@davidovski.xyz> | 2022-02-13 22:35:27 +0000 |
commit | 44542b58bb94727c5708924bd414cc49fd4bafb7 (patch) | |
tree | e3f74fa4e17bfaeadbb9980a5385e4dea32d3855 /src | |
parent | 8ce2ebf8ffd9f5e0bf1070530ada9fd10ae1ae81 (diff) |
added any line bars
Diffstat (limited to 'src')
-rw-r--r-- | src/hbar.c | 21 |
1 files changed, 18 insertions, 3 deletions
@@ -17,6 +17,9 @@ #define DEFAULT_COLOR BLACK BG_WHITE #define DEFAULT_RESET WHITE BG_BLACK +#define SAVE_POS "\033[s" +#define LOAD_POS "\033[u" + int main (int argc, char **argv) { struct winsize w; ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); @@ -26,6 +29,7 @@ int main (int argc, char **argv) { char *unit = ""; int total = 0; int completed = 0; + int line = 1; bool terminate = false; char *color = DEFAULT_COLOR; @@ -34,12 +38,13 @@ int main (int argc, char **argv) { int opt; int option_index = 0; - const char *optstring = "T:u:c:r:t"; + const char *optstring = "T:u:c:r:l:t"; static const struct option opts[] = { {"text", required_argument, 0, 'T'}, {"unit", optional_argument, 0, 'u'}, {"color", optional_argument, 0, 'c'}, {"reset", optional_argument, 0, 'r'}, + {"line", optional_argument, 0, ';'}, {"terminate", no_argument, 0, 't'} }; @@ -61,6 +66,9 @@ int main (int argc, char **argv) { case 't': terminate = true; break; + case 'l': + line = atoi(optarg); + break; } } @@ -73,9 +81,14 @@ int main (int argc, char **argv) { completed = atoi(argv[optind]); total = atoi(argv[optind+1]); + if (line != -1) { + printf("\033[%dA", line, 0); + } + char *count = malloc(width); sprintf(count, "[%d%s/%d%s]", completed, unit, total, unit); + printf(RESET "\r"); printf(color); for (int i = 0; i < width; i++) { int reset_at = 0; @@ -97,12 +110,14 @@ int main (int argc, char **argv) { } } + if (line != -1) { + printf("\033[%dB", line, 0); + } if (terminate) { - printf(RESET "\n"); - } else { printf(RESET "\r"); } + return 0; } |