summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/hbar.c21
-rwxr-xr-xtest/hbar.sh11
2 files changed, 29 insertions, 3 deletions
diff --git a/src/hbar.c b/src/hbar.c
index a26fca5..27ae437 100644
--- a/src/hbar.c
+++ b/src/hbar.c
@@ -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;
}
diff --git a/test/hbar.sh b/test/hbar.sh
index 7d99df9..ab0c812 100755
--- a/test/hbar.sh
+++ b/test/hbar.sh
@@ -5,8 +5,19 @@ TEXT="Hello there"
UNIT="mb"
MAX=100
+
+echo
for x in $(seq $MAX); do
${HBAR} -T "${TEXT}" -u ${UNIT} $x $MAX
sleep 0.01
done
${HBAR} -t -T "${TEXT}" -u ${UNIT} $x $MAX
+
+echo 1; echo 2
+for x in $(seq $MAX); do
+ ${HBAR} -l 1 -T "${TEXT}" -u ${UNIT} $((MAX - x)) $MAX
+ ${HBAR} -l 2 -T "${TEXT}" -u ${UNIT} $x $MAX
+ sleep 0.01
+done
+${HBAR} -l 1 -t -T "${TEXT}" -u ${UNIT} $((MAX-x)) $MAX
+${HBAR} -l 2 -t -T "${TEXT}" -u ${UNIT} $x $MAX