aboutsummaryrefslogtreecommitdiff
path: root/src/user_input.c
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2020-02-28 01:06:35 -0500
committerJoseph Hunkeler <jhunkeler@gmail.com>2020-02-28 01:06:35 -0500
commit511deab4f22a6c25f33cce1e206b656d520ab7e6 (patch)
tree669591ef38f61f0dc842e96b86aa1533f274269f /src/user_input.c
parentb6587f1d905e308cab713b1d5545e4667c80d6e4 (diff)
downloadspmc-511deab4f22a6c25f33cce1e206b656d520ab7e6.tar.gz
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
Diffstat (limited to 'src/user_input.c')
-rw-r--r--src/user_input.c29
1 files changed, 29 insertions, 0 deletions
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;