summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordavidovski <david@davidovski.xyz>2022-02-12 00:15:28 +0000
committerdavidovski <david@davidovski.xyz>2022-02-12 00:15:28 +0000
commit6d9b125955d460f43b37847220153983981dc7aa (patch)
tree0a94d2550dcada057582171003db789e4ae09131
parentf090af0af78491efbbe41ef0b888dc7e7304e7fe (diff)
added terminate option to hbar
-rw-r--r--src/hbar.c16
-rwxr-xr-xtest/hbar.sh5
2 files changed, 15 insertions, 6 deletions
diff --git a/src/hbar.c b/src/hbar.c
index d0482c0..a26fca5 100644
--- a/src/hbar.c
+++ b/src/hbar.c
@@ -9,6 +9,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
+#include <stdbool.h>
#include <getopt.h>
#include "colors.h"
@@ -25,6 +26,7 @@ int main (int argc, char **argv) {
char *unit = "";
int total = 0;
int completed = 0;
+ bool terminate = false;
char *color = DEFAULT_COLOR;
char *reset = DEFAULT_RESET;
@@ -32,12 +34,13 @@ int main (int argc, char **argv) {
int opt;
int option_index = 0;
- const char *optstring = "T:u:c:r:";
+ const char *optstring = "T:u:c:r: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'}
+ {"reset", optional_argument, 0, 'r'},
+ {"terminate", no_argument, 0, 't'}
};
while ((opt = getopt_long(argc, argv, optstring, opts, &option_index)) != -1) {
@@ -55,6 +58,9 @@ int main (int argc, char **argv) {
case 'u':
unit = optarg;
break;
+ case 't':
+ terminate = true;
+ break;
}
}
@@ -91,7 +97,11 @@ int main (int argc, char **argv) {
}
}
- printf(RESET "\r");
+ if (terminate) {
+ printf(RESET "\n");
+ } else {
+ printf(RESET "\r");
+ }
return 0;
}
diff --git a/test/hbar.sh b/test/hbar.sh
index d40c2ad..7d99df9 100755
--- a/test/hbar.sh
+++ b/test/hbar.sh
@@ -1,6 +1,6 @@
#!/bin/bash
-HBAR=./src/hbar/hbar
+HBAR=./bin/hbar
TEXT="Hello there"
UNIT="mb"
MAX=100
@@ -9,5 +9,4 @@ for x in $(seq $MAX); do
${HBAR} -T "${TEXT}" -u ${UNIT} $x $MAX
sleep 0.01
done
-
-${HBAR}
+${HBAR} -t -T "${TEXT}" -u ${UNIT} $x $MAX