From c105ed13a0f9e5a02a2173f116a4ea9ee972f0fb Mon Sep 17 00:00:00 2001 From: David Vereb Date: Tue, 10 Mar 2020 16:15:13 -0400 Subject: [PATCH] Don't show time elapsed screen if you quit. --- main.cpp | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/main.cpp b/main.cpp index 500a22b..d0f5108 100644 --- a/main.cpp +++ b/main.cpp @@ -66,12 +66,12 @@ int main(int argc, char *argv[]) // Keep track of time: auto start_time = std::chrono::steady_clock::now(); + unsigned int input = 'q'; while(selected != problems.end() && *selected) { - Problem *current_problem = *selected; current_problem->Draw(true, input_style); // refresh with new input - auto input = getch(); + input = getch(); if(input == 'q') // early exit break; switch(input) @@ -106,21 +106,24 @@ int main(int argc, char *argv[]) current_problem->Draw(current_problem == *selected, input_style); // refresh with new input } - // Keep track of time: - auto end_time = std::chrono::steady_clock::now(); - auto elapsed_time = std::chrono::duration_cast(end_time - start_time); - int middle_h = COLS / 2; - int middle_v = LINES / 2; - clear(); - mvprintw(middle_v - 1, middle_h - 10, - "Time Elapsed: %02dm %02ds\n", - elapsed_time / 60, elapsed_time % 60); - mvprintw(middle_v + 1, middle_h - 8, - "Press Q to quit."); - wrefresh(stdscr); + if(input != 'q') // if you didn't quit + { + // Keep track of time: + auto end_time = std::chrono::steady_clock::now(); + auto elapsed_time = std::chrono::duration_cast(end_time - start_time); + int middle_h = COLS / 2; + int middle_v = LINES / 2; + clear(); + mvprintw(middle_v - 1, middle_h - 10, + "Time Elapsed: %02dm %02ds\n", + elapsed_time / 60, elapsed_time % 60); + mvprintw(middle_v + 1, middle_h - 8, + "Press Q to quit."); + wrefresh(stdscr); - while(!(getch() == 'q')) - ; + while(!(getch() == 'q')) + ; + } for(auto *problem : problems) if(problem)