-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_interaction_helper.cpp
54 lines (49 loc) · 1.33 KB
/
user_interaction_helper.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "user_interaction_helper.h"
#include <iostream>
#include <limits>
namespace fs = std::filesystem;
/**
* Clears the input stream.
*/
void clearInput() {
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
/**
* Prompts for a yes/no input from the terminal.
*
* @param message The message to display.
* @return If the user answered yes or no.
*/
bool requestBoolean(std::string message) {
do {
char input;
std::cout << message << " (y/n):";
if (std::cin >> input) {
clearInput();
switch (toupper(input)) {
case 'Y':
return true;
case 'N':
return false;
default:
std::cout << "Invalid input.\n" << message << " (y/n):";
}
}
} while (true);
}
/**
* Checks if the file at the specified path exists and issues a warning if not.
*
* @param message The message to display.
* @return If a warning was issued.
*/
bool warnIfNothingAtPath(std::filesystem::path filePath, std::string fileDescription) {
if (!fs::exists(filePath)) {
std::cout << "The " << fileDescription << " folder is missing.\n"
<< filePath.string()
<< "\nThere is nothing to do, aborting.\n";
return true;
}
return false;
}