From 937a476743661fdfd4ce103b4d2f22f5344b6377 Mon Sep 17 00:00:00 2001 From: TaurusXin Date: Sat, 6 Jan 2024 10:19:33 +0800 Subject: [PATCH] feat: color in command line --- color.h | 17 +++++++++++++++++ main.cpp | 8 +++++--- 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 color.h diff --git a/color.h b/color.h new file mode 100644 index 0000000..c5816d0 --- /dev/null +++ b/color.h @@ -0,0 +1,17 @@ +#define RESET "\033[0m" +#define BLACK "\033[30m" /* Black */ +#define RED "\033[31m" /* Red */ +#define GREEN "\033[32m" /* Green */ +#define YELLOW "\033[33m" /* Yellow */ +#define BLUE "\033[34m" /* Blue */ +#define MAGENTA "\033[35m" /* Magenta */ +#define CYAN "\033[36m" /* Cyan */ +#define WHITE "\033[37m" /* White */ +#define BOLDBLACK "\033[1m\033[30m" /* Bold Black */ +#define BOLDRED "\033[1m\033[31m" /* Bold Red */ +#define BOLDGREEN "\033[1m\033[32m" /* Bold Green */ +#define BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */ +#define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */ +#define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */ +#define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */ +#define BOLDWHITE "\033[1m\033[37m" /* Bold White */ \ No newline at end of file diff --git a/main.cpp b/main.cpp index 13650df..8cb2c75 100644 --- a/main.cpp +++ b/main.cpp @@ -9,6 +9,8 @@ #include #endif +#include "color.h" + namespace fs = std::filesystem; void displayHelp() { @@ -29,11 +31,11 @@ void processFile(const fs::path& filePath) { crypt.Dump(); crypt.FixMetadata(); - std::cout << "Done: '" << crypt.dumpFilepath().string() << "'" << std::endl; + std::cout << BOLDGREEN << "Done: '" << RESET << crypt.dumpFilepath().string() << "'" << std::endl; } catch (const std::invalid_argument& e) { - std::cout << "Exception: '" << filePath << "'" << e.what() << std::endl; + std::cerr << BOLDRED << "Exception: " << RESET << RED << e.what() << RESET << " '" << filePath.string() << "'" << std::endl; } catch (...) { - std::cout << "Unexpected exception while processing file: " << filePath << std::endl; + std::cerr << BOLDRED << "Unexpected exception while processing file: " << RESET << filePath.string() << std::endl; } }