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 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src') 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; } -- cgit v1.2.1