From dada58bbd2f4a008c52bf148cf852d548c83199f Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 26 Mar 2021 08:56:11 +0100 Subject: stopwatch: do not reset when saving lap time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- stopwatch.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'stopwatch.c') diff --git a/stopwatch.c b/stopwatch.c index 7c5ec76..b978753 100644 --- a/stopwatch.c +++ b/stopwatch.c @@ -26,7 +26,7 @@ static int display_stopwatch(int timerfd) { uint64_t overrun = 0; - uintmax_t total_overrun = 0, h, m, s, d, first_overrun = 0; + uintmax_t total_overrun = 0, subtotal_overrun = 0, h, m, s, d, first_overrun = 0; int paused = 0, have_first = 0; struct itimerspec old_time, zero_time; size_t lap = 1; @@ -63,34 +63,34 @@ display_stopwatch(int timerfd) } else if (c == '\n') { if (timerfd_settime(timerfd, 0, &orig_time, NULL)) goto fail; - d = total_overrun % 10; - s = total_overrun / 10 % 60; - m = total_overrun / 10 / 60 % 60; - h = total_overrun / 10 / 60 / 60; + d = subtotal_overrun % 10; + s = subtotal_overrun / 10 % 60; + m = subtotal_overrun / 10 / 60 % 60; + h = subtotal_overrun / 10 / 60 / 60; if (quadsize) printf("\033#5"); printf("Lap %2zu: %ju:%02ju:%02ju.%ju", lap, h, m, s, d); lap++; if (!have_first) { have_first = 1; - first_overrun = total_overrun; - } else if (total_overrun > first_overrun) { - total_overrun = total_overrun - first_overrun; - d = total_overrun % 10; - s = total_overrun / 10 % 60; - m = total_overrun / 10 / 60 % 60; - h = total_overrun / 10 / 60 / 60; + first_overrun = subtotal_overrun; + } else if (subtotal_overrun > first_overrun) { + subtotal_overrun = subtotal_overrun - first_overrun; + d = subtotal_overrun % 10; + s = subtotal_overrun / 10 % 60; + m = subtotal_overrun / 10 / 60 % 60; + h = subtotal_overrun / 10 / 60 / 60; printf(" \033[31m(+%ju:%02ju:%02ju.%ju)\033[m", h, m, s, d); - } else if (total_overrun < first_overrun) { - total_overrun = first_overrun - total_overrun; - d = total_overrun % 10; - s = total_overrun / 10 % 60; - m = total_overrun / 10 / 60 % 60; - h = total_overrun / 10 / 60 / 60; + } else if (subtotal_overrun < first_overrun) { + subtotal_overrun = first_overrun - subtotal_overrun; + d = subtotal_overrun % 10; + s = subtotal_overrun / 10 % 60; + m = subtotal_overrun / 10 / 60 % 60; + h = subtotal_overrun / 10 / 60 / 60; printf(" \033[34m(-%ju:%02ju:%02ju.%ju)\033[m", h, m, s, d); } printf("\033[K\n"); - total_overrun = 0; + subtotal_overrun = 0; } } } @@ -125,6 +125,7 @@ display_stopwatch(int timerfd) goto fail; } else { total_overrun += (uintmax_t)overrun; + subtotal_overrun += (uintmax_t)overrun; } } -- cgit v1.2.3-70-g09d2