Compare commits
3 commits
d83884b379
...
2ed4323f9a
Author | SHA1 | Date | |
---|---|---|---|
2ed4323f9a | |||
e22f00e8c9 | |||
|
fb599bc7f9 |
3 changed files with 38 additions and 3 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
||||||
build/
|
build/
|
||||||
.vscode/
|
.vscode/
|
||||||
|
goodideas.md
|
||||||
|
|
10
shell.nix
Normal file
10
shell.nix
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{ pkgs ? import <nixpkgs> {}}:
|
||||||
|
pkgs.mkShell {
|
||||||
|
packages = with pkgs; [
|
||||||
|
cmake
|
||||||
|
gnumake
|
||||||
|
ninja
|
||||||
|
tomlplusplus
|
||||||
|
cpptoml
|
||||||
|
];
|
||||||
|
}
|
30
src/main.cpp
30
src/main.cpp
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue