summaryrefslogtreecommitdiff
path: root/converter/converter.cpp
diff options
context:
space:
mode:
authora1xd <[email protected]>2020-10-15 00:08:33 -0400
committera1xd <[email protected]>2020-10-15 00:08:33 -0400
commit9ef95235c6fc562c5ff90c18d7e9135d3f7e3470 (patch)
tree5e61fe1963e7d96b980df401330bd439ba3bc097 /converter/converter.cpp
parentMerge pull request #35 from a1xd/1.1.1 (diff)
downloadrawaccel-9ef95235c6fc562c5ff90c18d7e9135d3f7e3470.tar.xz
rawaccel-9ef95235c6fc562c5ff90c18d7e9135d3f7e3470.zip
improve converter prompt
Diffstat (limited to 'converter/converter.cpp')
-rw-r--r--converter/converter.cpp67
1 files changed, 37 insertions, 30 deletions
diff --git a/converter/converter.cpp b/converter/converter.cpp
index e282ca4..242a331 100644
--- a/converter/converter.cpp
+++ b/converter/converter.cpp
@@ -4,6 +4,7 @@
#include <fstream>
#include <iostream>
#include <optional>
+#include <sstream>
#include <string>
#include <rawaccel-settings.h>
@@ -44,12 +45,16 @@ static inline void trim(std::string& s) {
rtrim(s);
}
-bool yes() {
- for (;;) {
- wchar_t c = _getwch();
- if (c == 'y') return true;
- else if (c == 'n') return false;
- }
+bool ask(std::string_view question) {
+ std::cout << question << " (Y/N)" << std::endl;
+ wchar_t ch;
+ bool yes;
+ do
+ {
+ ch = towupper(_getwch());
+ yes = ch == 'Y';
+ } while (ch != 'N' && !yes);
+ return yes;
}
using ia_settings_t = std::vector<std::pair<std::string, double>>;
@@ -165,16 +170,16 @@ bool try_convert(const ia_settings_t& ia_settings) {
switch (static_cast<IA_MODES_ENUM>(mode)) {
case IA_QL: {
- std::cout << "We recommend trying out our new cap and offset styles.\n"
- "Use new cap and offset? (y|n)\n";
+ bool legacy = !ask("We recommend trying out our new cap and offset styles.\n"
+ "Use new cap and offset?");
ra_settings.modes.x = ra::accel_mode::classic;
- ra_settings.argsv.x = convert_quake(ia_settings, !yes());
+ ra_settings.argsv.x = convert_quake(ia_settings, legacy);
break;
}
case IA_NAT: {
- std::cout << "Raw Accel offers a new mode that you might like more than Natural.\n"
- "Wanna try it out now? (y|n)\n";
- ra_settings.modes.x = yes() ? ra::accel_mode::naturalgain : ra::accel_mode::natural;
+ bool nat_gain = ask("Raw Accel offers a new mode that you might like more than Natural.\n"
+ "Wanna try it out now?");
+ ra_settings.modes.x = nat_gain ? ra::accel_mode::naturalgain : ra::accel_mode::natural;
ra_settings.argsv.x = convert_natural(ia_settings);
break;
}
@@ -223,29 +228,31 @@ int main()
}
if (opt_path) {
- std::cout << "Found " << opt_path->filename() <<
- "\n\nConvert and send settings generated from " <<
- opt_path->filename() << "? (y|n)\n";
- if (!yes()) return 0;
- try {
- if (!try_convert(parse_ia_settings(opt_path.value())))
- std::cout << "Unable to convert settings.\n";
- }
- catch (DriverNotInstalledException^) {
- Console::WriteLine("\nDriver is not installed.");
- }
- catch (Exception^ e) {
- Console::WriteLine("\nError: " + e->ToString());
- }
- catch (const std::exception& e) {
- std::cout << "Error: " << e.what() << '\n';
+ std::string path = opt_path->filename().generic_string();
+ std::stringstream ss;
+ ss << "Found " << path <<
+ "\n\nConvert and send settings generated from " << path << '?';
+ if (ask(ss.str())) {
+ try {
+ if (!try_convert(parse_ia_settings(opt_path.value())))
+ std::cout << "Unable to convert settings.\n";
+ }
+ catch (DriverNotInstalledException^) {
+ Console::WriteLine("\nDriver is not installed.");
+ }
+ catch (Exception^ e) {
+ Console::WriteLine("\nError: " + e->ToString());
+ }
+ catch (const std::exception& e) {
+ std::cout << "Error: " << e.what() << '\n';
+ }
}
}
else {
std::cout << "Drop your InterAccel settings/profile into this directory.\n"
"Then run this program to generate the equivalent Raw Accel settings.\n";
}
-
- std::cout << "Press any key to close this window . . .\n";
+
+ std::cout << "Press any key to close this window . . ." << std::endl;
_getwch();
}