pull: merge maukkis's pull request

This commit is contained in:
Kaley, Fischer 2024-07-27 19:42:36 +02:00
commit 2ed4323f9a
3 changed files with 38 additions and 3 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
build/ build/
.vscode/ .vscode/
goodideas.md

10
shell.nix Normal file
View file

@ -0,0 +1,10 @@
{ pkgs ? import <nixpkgs> {}}:
pkgs.mkShell {
packages = with pkgs; [
cmake
gnumake
ninja
tomlplusplus
cpptoml
];
}

View file

@ -1,7 +1,9 @@
#include <ios>
#include <iostream> #include <iostream>
#include <filesystem> #include <filesystem>
#include <algorithm> #include <algorithm>
#include <cctype> #include <cctype>
#include <limits>
#include <string> #include <string>
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
@ -10,6 +12,22 @@
#include <stdexcept> #include <stdexcept>
#include <cpptoml.h> #include <cpptoml.h>
void clearBuffer(){
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
inline void checkIfExtractionFailed(){
if (!std::cin){ // if previous extraction failed
if (std::cin.eof()){ // check if eof and if yes aborts the program
std::abort();
}
std::cin.clear(); //put std::cin back into normal mode
clearBuffer(); // remove bad input
}
}
const std::string USAGE = R"#(usage: RapidMenu [flags] [<command> [args]] const std::string USAGE = R"#(usage: RapidMenu [flags] [<command> [args]]
LISTING COMMANDS: LISTING COMMANDS:
-c: To specify which config to use. -c: To specify which config to use.
@ -171,10 +189,11 @@ int main(int argc, char* argv[]) {
} else { } else {
while (!(std::filesystem::exists(bconfigfile) && std::filesystem::is_regular_file(bconfigfile))) { while (!(std::filesystem::exists(bconfigfile) && std::filesystem::is_regular_file(bconfigfile))) {
std::cout << "Invalid config file: " << bconfigfile; std::cout << "Invalid config file: " << bconfigfile << ' ';
std::cout << "Please enter a valid config: "; std::cout << "Please enter a valid config: ";
std::cin >> bconfigfile; std::cin >> bconfigfile;
checkIfExtractionFailed();
clearBuffer(); // clear extra input if entered
bconfig = bconfigfile.c_str(); bconfig = bconfigfile.c_str();
} }
@ -183,13 +202,16 @@ int main(int argc, char* argv[]) {
// executable // executable
std::cout << "What do you want to call your executable?: "; std::cout << "What do you want to call your executable?: ";
std::cin >> bexeout; std::cin >> bexeout;
checkIfExtractionFailed();
clearBuffer();
std::string bexefile = std::string(userHome) + "/.local/bin/" + bexeout; std::string bexefile = std::string(userHome) + "/.local/bin/" + bexeout;
if (std::filesystem::exists(bexefile) && std::filesystem::is_regular_file(bexefile)) { if (std::filesystem::exists(bexefile) && std::filesystem::is_regular_file(bexefile)) {
while (std::filesystem::exists(bexefile) && std::filesystem::is_regular_file(bexefile)) { while (std::filesystem::exists(bexefile) && std::filesystem::is_regular_file(bexefile)) {
std::cout << "do you want to overwrite: " << bexeout << "? (y/n) "; std::cout << "do you want to overwrite: " << bexeout << "? (y/n) ";
std::cin >> byn; std::cin >> byn;
checkIfExtractionFailed();
clearBuffer();
transform(byn.begin(), byn.end(), byn.begin(), ::tolower); transform(byn.begin(), byn.end(), byn.begin(), ::tolower);
if (byn == "y") { if (byn == "y") {
@ -198,6 +220,8 @@ int main(int argc, char* argv[]) {
} else if (byn == "n") { } else if (byn == "n") {
std::cout << "What do you want to call your executable?: "; std::cout << "What do you want to call your executable?: ";
std::cin >> bexeout; std::cin >> bexeout;
checkIfExtractionFailed();
clearBuffer();
bexe = bexeout.c_str(); bexe = bexeout.c_str();
} }
} }