From 511deab4f22a6c25f33cce1e206b656d520ab7e6 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Fri, 28 Feb 2020 01:06:35 -0500 Subject: Improvements: * Refactored a few function names * Can read package metadata * Can delete packages * Can download! and install packages at the same time * Can prompt the user before proceeding --- src/user_input.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/user_input.c') diff --git a/src/user_input.c b/src/user_input.c index 061fb2e..3f358fa 100644 --- a/src/user_input.c +++ b/src/user_input.c @@ -25,6 +25,35 @@ int spm_user_yesno(int answer, int empty_input_is_yes) { return result; } +int spm_prompt_user(const char *msg, int empty_input_is_yes) { + int user_choice = 0; + int status_choice = 0; + char ch_yes = 'y'; + char ch_no = 'n'; + + if (empty_input_is_yes) { + ch_yes = 'Y'; + } else { + ch_no = 'N'; + } + + printf("\n%s [%c/%c] ", msg, ch_yes, ch_no); + while ((user_choice = getchar())) { + status_choice = spm_user_yesno(user_choice, 1); + if (status_choice == 0) { // No + break; + } else if (status_choice == 1) { // Yes + break; + } else { // Only triggers when spm_user_yesno's second argument is zero + puts("Please answer 'y' or 'n'..."); + } + } + puts(""); + + return status_choice; +} + + void spm_user_yesno_test() { int choice; int status; -- cgit