2#ifndef _CONSOLIX_SYSTEM_UTILS_HPP_INCLUDED 
    3#define _CONSOLIX_SYSTEM_UTILS_HPP_INCLUDED 
   13#elif defined(__linux__) || defined(__APPLE__) 
   15#include <sys/sysinfo.h> 
   27        if (OpenClipboard(
nullptr)) {
 
   29            size_t size = (text.size() + 1) * 
sizeof(char);
 
   30            HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, size);
 
   35            memcpy(GlobalLock(hMem), text.c_str(), size);
 
   37            SetClipboardData(CF_TEXT, hMem);
 
   42#       elif defined(__APPLE__) 
   43        std::string command = 
"echo \"" + text + 
"\" | pbcopy";
 
   44        return system(command.c_str()) == 0;
 
   45#       elif defined(__linux__) 
   46        std::string command = 
"echo \"" + text + 
"\" | xclip -selection clipboard";
 
   47        return system(command.c_str()) == 0;
 
 
   57        if (!OpenClipboard(
nullptr)) 
return "";
 
   58        HANDLE hData = GetClipboardData(CF_TEXT);
 
   63        char* text = 
static_cast<char*
>(GlobalLock(hData));
 
   64        std::string result(text ? text : 
"");
 
   68#       elif defined(__APPLE__) 
   69        return system(
"pbpaste") == 0 ? 
"(clipboard contents)" : 
"";
 
   70#       elif defined(__linux__) 
   71        return system(
"xclip -selection clipboard -o") == 0 ? 
"(clipboard contents)" : 
"";
 
 
   82#       elif defined(__APPLE__) 
   84#       elif defined(__linux__) 
 
   94        return std::chrono::duration_cast<std::chrono::milliseconds>(
 
   95            std::chrono::system_clock::now().time_since_epoch()
 
 
  104        GetSystemInfo(&sysinfo);
 
  105        return sysinfo.dwNumberOfProcessors;
 
  106#       elif defined(__linux__) || defined(__APPLE__) 
  107        return sysconf(_SC_NPROCESSORS_ONLN);
 
 
  117        char* home = getenv(
"USERPROFILE");
 
  118        return home ? std::string(home) : 
"";
 
  119#       elif defined(__linux__) || defined(__APPLE__) 
  120        struct passwd* pw = getpwuid(getuid());
 
  121        return pw ? std::string(pw->pw_dir) : 
"";
 
 
  131        char tempPath[MAX_PATH];
 
  132        GetTempPathA(MAX_PATH, tempPath);
 
  133        return std::string(tempPath);
 
  134#       elif defined(__linux__) || defined(__APPLE__) 
  135        char* temp = getenv(
"TMPDIR");
 
  136        return temp ? std::string(temp) : 
"/tmp";
 
 
  146        const char* value = getenv(var_name.c_str());
 
  147        return value ? std::string(value) : 
"";
 
 
< Utility modules and helpers.
 
int get_cpu_count()
Gets the number of logical CPU cores.
 
std::string get_env_var(const std::string &var_name)
Retrieves an environment variable's value.
 
std::string get_temp_directory()
Gets the system temporary directory path.
 
bool copy_to_clipboard(const std::string &text)
Copies the given text to the system clipboard.
 
std::string get_home_directory()
Gets the user's home directory path.
 
std::string get_clipboard_text()
Retrieves text from the system clipboard.
 
uint64_t get_system_time_ms()
Gets the current system time in milliseconds.
 
std::string get_os_name()
Gets the name of the operating system.