From 9ef95235c6fc562c5ff90c18d7e9135d3f7e3470 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Thu, 15 Oct 2020 00:08:33 -0400 Subject: improve converter prompt --- converter/converter.cpp | 67 +++++++++++++++++++++++++++---------------------- 1 file 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 #include #include +#include #include #include @@ -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>; @@ -165,16 +170,16 @@ bool try_convert(const ia_settings_t& ia_settings) { switch (static_cast(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(); } -- cgit v1.2.3