From b742db9cda7f89a9acc6a83fdc80e32c4b44cc74 Mon Sep 17 00:00:00 2001 From: Ruben Date: Wed, 21 Dec 2022 09:49:46 +0100 Subject: [PATCH] Started work on ceev init, and planned ceev clean. Also did some cleanup on show_help(), by adding a simple color library. Not the cleanest, but the code is more readable now, and that's more important. --- CMakeLists.txt | 2 +- src/ceev.cc | 50 ++++++++++++++++++++++++++++-------- src/ceev.h | 4 +++ src/colors.cc | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/colors.h | 22 ++++++++++++++++ 5 files changed, 136 insertions(+), 11 deletions(-) create mode 100644 src/colors.cc create mode 100644 src/colors.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 6aa4977..ead07d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,5 +5,5 @@ project(ceev) set(CMAKE_CXX_STANDARD 17) find_package(SDL2 REQUIRED) include_directories(${SDL2_INCLUDE_DIRS}) -add_executable(ceev src/ceev.cc src/ceev.h) +add_executable(ceev src/ceev.cc src/ceev.h src/colors.cc src/colors.h) target_link_libraries(ceev ${SDL2_LIBRARIES}) \ No newline at end of file diff --git a/src/ceev.cc b/src/ceev.cc index 44e12f3..cb5f83e 100644 --- a/src/ceev.cc +++ b/src/ceev.cc @@ -8,31 +8,36 @@ int usage() { std::cout << "Run `" << program_invocation_short_name << " --help' for more information.\n" << std::endl; return 1; } + int show_help() { - // TODO: Maybe put the colorings into functions? - std::cout << program_invocation_short_name << " [\x1b[36mcommand\x1b[0m] <\x1b[92moptions\x1b[0m>\n"; + std::cout << program_invocation_short_name << " [" << cyan("command") << "] <" << bright_green("options") << ">\n"; std::cout << "\n"; std::cout << "Usage:"; // ceev init std::cout << "\n*\t"; - std::cout << program_invocation_short_name << " \x1b[36minit \x1b[0m<\x1b[92m--force\x1b[0m>\n"; + std::cout << program_invocation_short_name << cyan(" init ") << "<" << bright_green("--force") << ">\n"; std::cout << "\t\t"; std::cout << "Creates the CeeV file system. Can only be used "; std::cout << "if the current folder is empty,"; - std::cout << "\n\t\tor when run with `\x1b[92m--force\x1b[0m'"; + std::cout << "\n\t\tor when run with `" << bright_green("--force") << "'"; // ceev build std::cout << "\n*\t"; - std::cout << program_invocation_short_name << " \x1b[36mbuild\x1b[0m\n"; + std::cout << program_invocation_short_name << cyan(" build") << "\n"; std::cout << "\t\t"; std::cout << "Not yet implemented"; // ceev run std::cout << "\n*\t"; - std::cout << program_invocation_short_name << " \x1b[36mrun\x1b[0m\n"; + std::cout << program_invocation_short_name << cyan(" run") << "\n"; + std::cout << "\t\t"; + std::cout << "Not yet implemented"; + // ceev clean + std::cout << "\n*\t"; + std::cout << program_invocation_short_name << cyan(" clean") << "\n"; std::cout << "\t\t"; std::cout << "Not yet implemented"; // ceev --help std::cout << "\n*\t"; - std::cout << program_invocation_short_name << " \x1b[36m--help\x1b[0m\n"; + std::cout << program_invocation_short_name << cyan(" --help") << "\n"; std::cout << "\t\t"; std::cout << "This help page.\n"; std::cout << std::endl; @@ -40,13 +45,33 @@ int show_help() { } int create_fs(std::deque args) { - std::string cwd = fs::current_path(); + fs::path cwd = fs::current_path(); if (!fs::is_empty(cwd) && args[0] != "--force") { std::cerr << "ERROR: Folder not empty.\n" << "Run the command with `--force' to run anyways" << std::endl; return 1; } std::cout << "running create_fs()" << std::endl; + fs::create_directory(cwd.string() + "/.ceev", cwd); + fs::create_directory(cwd.string() + "/src", cwd); + std::ofstream config(cwd.string() + "/.ceev/config"); + std::string directory = cwd.string().substr(cwd.parent_path().string().length() + 1); + std::cout << "Initializing project...\n"; + std::cout << "You can change this information later by editing .ceev/config\n"; + std::string project_name; + std::cout << "Project name [" << directory << "]: "; + std::getline(std::cin, project_name); + if (project_name == "") project_name = directory; + config << "name = " << project_name << '\n'; + std::string version; + std::cout << "Version [0.0.1]: "; + std::getline(std::cin, version); + if (version == "") version = "0.0.1"; + config << "version = " << version << '\n'; + std::string author; + std::cout << "Author: "; + std::getline(std::cin, author); + if (author == "") author = "Unknown"; return 0; } int build_project(std::deque args) { @@ -57,7 +82,10 @@ int run_project(std::deque args) { std::cout << "Running project..." << std::endl; return 0; } - +int clean_project(std::deque args) { + std::cout << "Cleaning project..." << std::endl; + return 0; +} int main(int argc, char **argv) { if (argc <= 1) { return usage(); @@ -72,10 +100,12 @@ int main(int argc, char **argv) { } if (a1 == "build") return build_project(args); if (a1 == "run") return run_project(args); + if (a1 == "clean") return clean_project(args); std::string kw; if (a1.substr(0, 2) == "--") { kw = a1.substr(2); if (kw == "help") return show_help(); } - return 0; + std::cerr << "ERROR: Unknown command `" << a1 << "'\n" << std::endl; + return usage(); } \ No newline at end of file diff --git a/src/ceev.h b/src/ceev.h index aaecd36..7bbc6d3 100644 --- a/src/ceev.h +++ b/src/ceev.h @@ -3,9 +3,12 @@ #include #include #include +#include #include #include +#include "colors.h" + namespace fs = std::filesystem; int usage(); @@ -13,4 +16,5 @@ int show_help(); int create_fs(std::deque args); int build_project(std::deque args); int run_project(std::deque args); +int clean_project(std::deque args); int main(int argc, char **argv); \ No newline at end of file diff --git a/src/colors.cc b/src/colors.cc new file mode 100644 index 0000000..3a5ca13 --- /dev/null +++ b/src/colors.cc @@ -0,0 +1,69 @@ +#include "colors.h" + +void colors_test() { + std::cout << "Hello World"; +} + +std::string black(std::string input) { + return "\x1b[30m" + input + "\x1b[0m"; +} + +std::string red(std::string input) { + return "\x1b[31m" + input + "\x1b[0m"; +} + +std::string green(std::string input) { + return "\x1b[32m" + input + "\x1b[0m"; +} + +std::string yellow(std::string input) { + return "\x1b[33m" + input + "\x1b[0m"; +} + +std::string blue(std::string input) { + return "\x1b[34m" + input + "\x1b[0m"; +} + +std::string magenta(std::string input) { + return "\x1b[35m" + input + "\x1b[0m"; +} + +std::string cyan(std::string input) { + return "\x1b[36m" + input + "\x1b[0m"; +} + +std::string white(std::string input) { + return "\x1b[37m" + input + "\x1b[0m"; +} + +std::string bright_black(std::string input) { + return "\x1b[90m" + input + "\x1b[0m"; +} + +std::string bright_red(std::string input) { + return "\x1b[91m" + input + "\x1b[0m"; +} + +std::string bright_green(std::string input) { + return "\x1b[92m" + input + "\x1b[0m"; +} + +std::string bright_yellow(std::string input) { + return "\x1b[93m" + input + "\x1b[0m"; +} + +std::string bright_blue(std::string input) { + return "\x1b[94m" + input + "\x1b[0m"; +} + +std::string bright_magenta(std::string input) { + return "\x1b[95m" + input + "\x1b[0m"; +} + +std::string bright_cyan(std::string input) { + return "\x1b[96m" + input + "\x1b[0m"; +} + +std::string bright_white(std::string input) { + return "\x1b[97m" + input + "\x1b[0m"; +} \ No newline at end of file diff --git a/src/colors.h b/src/colors.h new file mode 100644 index 0000000..c466667 --- /dev/null +++ b/src/colors.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include + +void colors_test(); +std::string black(std::string input); +std::string red(std::string input); +std::string green(std::string input); +std::string yellow(std::string input); +std::string blue(std::string input); +std::string magenta(std::string input); +std::string cyan(std::string input); +std::string white(std::string input); +std::string bright_black(std::string input); +std::string bright_red(std::string input); +std::string bright_green(std::string input); +std::string bright_yellow(std::string input); +std::string bright_blue(std::string input); +std::string bright_magenta(std::string input); +std::string bright_cyan(std::string input); +std::string bright_white(std::string input); \ No newline at end of file