Skip to content

Commit

Permalink
misc improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
rifsxd committed Sep 11, 2024
1 parent 6c4beae commit 6a78705
Showing 1 changed file with 13 additions and 59 deletions.
72 changes: 13 additions & 59 deletions src/helper/version.cpp
Original file line number Diff line number Diff line change
@@ -1,63 +1,18 @@
#include "defines.cpp"
#include "colors.cpp"

#define VERSION "2.9.15"
#define PROGRAM_NAME "Blazefetch"
#define VERSION "2.9.17"
#define BUILD_DATE __DATE__
#define BUILD_TIME __TIME__
#define COPYRIGHT_YEAR "2023"
#define COPYRIGHT_OWNER "RifsxD"

// Macro defined during build process
#ifndef BUILD_ARCH
#define BUILD_ARCH "Unknown Architecture"
#endif

std::string execHelperVersion(const char* cmd) {
char buffer[256];
std::string result = "";
FILE* pipe = popen(cmd, "r");
if (!pipe) {
return "ERROR";
}
while (!feof(pipe)) {
if (fgets(buffer, 256, pipe) != nullptr)
result += buffer;
}
pclose(pipe);
return result;
}

std::string getUserHostInfo() {
std::string username = execHelperVersion("whoami");
std::string hostname = execHelperVersion("hostname");

// Remove newline characters from the end of each string
if (!username.empty() && !hostname.empty()) {
username.erase(username.find_last_not_of("\n") + 1);
hostname.erase(hostname.find_last_not_of("\n") + 1);
return username + "@" + hostname;
} else {
return "Unknown user@host";
}
}

std::string getKernelVersion() {
FILE* pipe = popen("uname -s -r", "r");
if (!pipe) {
return "Unknown Kernel";
}

char buffer[256];
std::string result = "";
while (!feof(pipe)) {
if (fgets(buffer, 256, pipe) != nullptr)
result += buffer;
}

result.pop_back();

pclose(pipe);
return result;
}

std::string getArchInfo() {
return BUILD_ARCH;
}
Expand All @@ -68,23 +23,23 @@ std::string getCompilerInfo() {
return "Clang " + std::string(__clang_version__);
#elif defined(__GNUC__) || defined(__GNUG__)
return "GCC " + std::to_string(__GNUC__) + "." + std::to_string(__GNUC_MINOR__) + "." + std::to_string(__GNUC_PATCHLEVEL__);
#elif defined(_MSC_VER)
return "MSVC " + std::to_string(_MSC_VER);
#else
return "Unknown Compiler";
#endif
}

int printVersion() {

std::string hostusername = getUserHostInfo();

std::string kernelversion = getKernelVersion();

std::string compilerInfo = getCompilerInfo();

std::string archInfo = getArchInfo();

const std::string linkSource = "\033]8;;https://github.com/rifsxd/blazefetch\033\\";

const std::string linkCopyright = "\033]8;;https://raw.githubusercontent.com/rifsxd/blazefetch/main/LICENSE\033\\";

const std::string linkEnd = "\033]8;;\033\\";

std::cout << "\n";
std::cout << redColor << R"(
▄▄▄▄ ██▓ ▄▄▄ ▒███████▒▓█████ █████▒▓█████▄▄▄█████▓ ▄████▄ ██░ ██
Expand All @@ -99,10 +54,9 @@ int printVersion() {
░ ░ ░
)" << std::endl;

std::cout << greenColor << "Blazefetch version " << VERSION << "\n" << std::endl;
std::cout << yellowColor << "Build metadata - " << BUILD_TIME << " | " << BUILD_DATE << " | " << hostusername << " | " << kernelversion << " | " << compilerInfo << " | " << "Arch " << archInfo << "\n" << std::endl;
std::cout << blueColor << "Copyright \u00A9 2024 RifsxD" << "\n" << std::endl;
std::cout << cyanColor << "Blazefetch is a MIT licensed project" << resetColor << "\n" << std::endl;
std::cout << greenColor << linkSource << PROGRAM_NAME << linkEnd << " version " << VERSION << "\n" << std::endl;
std::cout << yellowColor << "Build metadata - " << BUILD_TIME << " | " << BUILD_DATE << " | " << compilerInfo << " | " << "Arch " << archInfo << "\n" << std::endl;
std::cout << blueColor << linkCopyright << "Copyright \u00A9 " << COPYRIGHT_YEAR << " " << COPYRIGHT_OWNER << " " << "(MIT)" << linkEnd << resetColor << "\n" << std::endl;

return 0;
}

0 comments on commit 6a78705

Please sign in to comment.