From 6d9b125955d460f43b37847220153983981dc7aa Mon Sep 17 00:00:00 2001 From: davidovski Date: Sat, 12 Feb 2022 00:15:28 +0000 Subject: added terminate option to hbar --- src/hbar.c | 16 +++++++++++++--- test/hbar.sh | 5 ++--- 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 #include #include +#include #include #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 -- cgit v1.2.1