feat: color in command line

This commit is contained in:
TaurusXin 2024-01-06 10:19:33 +08:00
parent 13aa156214
commit 937a476743
2 changed files with 22 additions and 3 deletions

17
color.h Normal file
View File

@ -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 */

View File

@ -9,6 +9,8 @@
#include <Windows.h> #include <Windows.h>
#endif #endif
#include "color.h"
namespace fs = std::filesystem; namespace fs = std::filesystem;
void displayHelp() { void displayHelp() {
@ -29,11 +31,11 @@ void processFile(const fs::path& filePath) {
crypt.Dump(); crypt.Dump();
crypt.FixMetadata(); 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) { } 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 (...) { } catch (...) {
std::cout << "Unexpected exception while processing file: " << filePath << std::endl; std::cerr << BOLDRED << "Unexpected exception while processing file: " << RESET << filePath.string() << std::endl;
} }
} }