2#ifndef _CONSOLIX_SYSTEM_UTILS_HPP_INCLUDED
3#define _CONSOLIX_SYSTEM_UTILS_HPP_INCLUDED
16#elif defined(__linux__) || defined(__APPLE__)
29 if (OpenClipboard(
nullptr)) {
31 const std::size_t size = (text.size() + 1) *
sizeof(char);
32 HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, size);
37 std::memcpy(GlobalLock(hMem), text.c_str(), size);
39 SetClipboardData(CF_TEXT, hMem);
44# elif defined(__APPLE__)
45 const std::string command =
"echo \"" + text +
"\" | pbcopy";
46 return std::system(command.c_str()) == 0;
47# elif defined(__linux__)
48 const std::string command =
"echo \"" + text +
"\" | xclip -selection clipboard";
49 return std::system(command.c_str()) == 0;
59 if (!OpenClipboard(
nullptr))
return "";
60 HANDLE hData = GetClipboardData(CF_TEXT);
65 char* text =
static_cast<char*
>(GlobalLock(hData));
66 const std::string result(text ? text :
"");
70# elif defined(__APPLE__)
71 return std::system(
"pbpaste") == 0 ?
"(clipboard contents)" :
"";
72# elif defined(__linux__)
73 return std::system(
"xclip -selection clipboard -o") == 0 ?
"(clipboard contents)" :
"";
84# elif defined(__APPLE__)
86# elif defined(__linux__)
96 return static_cast<std::uint64_t
>(std::chrono::duration_cast<std::chrono::milliseconds>(
97 std::chrono::system_clock::now().time_since_epoch()
106 GetSystemInfo(&sysinfo);
107 return static_cast<int>(sysinfo.dwNumberOfProcessors);
108# elif defined(__linux__) || defined(__APPLE__)
109 return static_cast<int>(sysconf(_SC_NPROCESSORS_ONLN));
119 const char* home = std::getenv(
"USERPROFILE");
120 return home ? std::string(home) :
"";
121# elif defined(__linux__) || defined(__APPLE__)
122 struct passwd* pw = getpwuid(getuid());
123 return pw ? std::string(pw->pw_dir) :
"";
133 char tempPath[MAX_PATH];
134 GetTempPathA(MAX_PATH, tempPath);
135 return std::string(tempPath);
136# elif defined(__linux__) || defined(__APPLE__)
137 const char* temp = std::getenv(
"TMPDIR");
138 return temp ? std::string(temp) :
"/tmp";
148 const char* value = std::getenv(var_name.c_str());
149 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.
std::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.