-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAcceptionLib.h
55 lines (46 loc) · 1.37 KB
/
AcceptionLib.h
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
55
/**
* @file AcceptionLib.h
* @brief AcceptionLib is a lib which makes terminal questions('[y/n]') easier to do.
*
* Copyright (c) 2020-forever Vlad Rogozin ([email protected])
*
* Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
* or copy at http://opensource.org/licenses/MIT)
*/
#ifndef RED_ACCEPTIONLIB_H
#define RED_ACCEPTIONLIB_H
#define REDACCEPTIONLIB_VERSION "1.1"
// System libs.
#include <iostream>
#include <string>
namespace Red {
class AcceptionObj {
public:
/**
* @brief AcceptionObj
*
* Base ctor.
*/
AcceptionObj() {}
/**
* @brief Request
*
* @param Text Text to be shown.
*
* @return True if received yes, false if received no.
*/
bool Request(std::string Text = "[\033[91m*\033[0m] Are you sure?") {
std::string inp = "";
std::cout << Text << " [y/n]: ";
while (true) {
std::cin >> inp;
if (inp[0] == 'y' || inp[0] == 'Y') {
return true;
} else if (inp[0] == 'n' || inp[0] == 'N') {
return false;
}
}
}
};
}
#endif // RED_ACCEPTIONLIB_H