7 std::cerr <<
"Attempted to open file: " << file_name <<
" ";
8 std::cerr <<
"but a Error ocurred. Check if the file exist." <<
"\n";
16 std::vector<std::string> ret;
17 filein.open(string_path);
19 while (getline(filein, line)) {
27 std::ofstream fileout;
28 fs::create_directories(file_path.parent_path());
29 fileout.open(file_path);
31 for (
const auto& line : content) {
32 fileout << line <<
'\n';
38 std::ifstream json_file(string_path.string(), std::ifstream::binary);
46 if (color == COLOR::NONE) {
67 unsigned char uc =
static_cast<unsigned char>(c);
68 return !(std::isalnum(uc) || c ==
'_');
72 std::string cur_token;
73 std::vector<std::string> ret;
76 if (!cur_token.empty()) {
77 ret.push_back(cur_token);
81 cur_token.push_back(c);
84 if (!cur_token.empty()) {
85 ret.push_back(cur_token);
90Wrapped wrapped(
const std::string& text,
size_t spaces,
bool use_first_line) {
91 return {text, spaces, use_first_line};
95 std::string indent(w.
spaces,
' ');
97 size_t max_line = 80 - w.
spaces;
99 std::string current_line;
100 std::istringstream stream(w.
text);
101 while (stream >> word) {
102 if (current_line.empty()) {
104 }
else if (current_line.length() + 1 + word.length() > max_line) {
106 os << current_line <<
"\n";
109 os << indent << current_line <<
"\n";
113 current_line +=
" " + word;
116 if (!current_line.empty()) {
118 os << current_line <<
"\n";
120 os << indent << current_line <<
"\n";
127 std::string output = input;
128 for (
char &c : output) {
129 c =
static_cast<char>(
130 std::toupper(
static_cast<unsigned char>(c))
137 std::hash<std::string> hasher;
138 size_t hash = hasher(content);
140 std::stringstream ss;
141 ss << std::hex <<
hash;
143 std::string hash_str = ss.str();
144 if (hash_str.length() > 12) {
145 hash_str = hash_str.substr(0, 12);
152 std::uintmax_t size = 0;
154 if (!fs::exists(folder))
return 0;
157 for (
auto& p : fs::recursive_directory_iterator(folder, fs::directory_options::skip_permission_denied, ec)) {
160 if (fs::is_regular_file(p.status(ec)) && !ec) {
161 size += fs::file_size(p, ec);
169 double size =
static_cast<double>(bytes);
170 const char* units[] = {
"B",
"KB",
"MB",
"GB",
"TB"};
173 while (size >= 1024 && unit < 4) {
178 std::ostringstream out;
179 out << std::fixed << std::setprecision(2) << size << units[unit];
185 std::system((
"explorer \"" + path +
"\"").c_str());
187 std::system((
"open \"" + path +
"\"").c_str());
189 std::system((
"xdg-open \"" + path +
"\"").c_str());
static Config & config()
Gets the singleton configuration instance.
Configuration management interface.
std::string to_uppercase(const std::string input)
const std::vector< std::string > COLOR_TOKENS_UTILS_LIGTH
ANSI color codes for light terminal backgrounds.
void write_file_generic(const fs::path &file_path, const std::vector< std::string > &content)
Writes content to a file at specified path.
std::string format_colored_message(const std::string &message, COLOR color)
Formats a message with ANSI color codes.
std::vector< std::string > split_string(const std::string &s, char delimiter)
Splits a string by a delimiter into tokens.
bool is_special_char(char c)
Checks if a character is special (non-alphanumeric and not underscore)
COLOR
Enumeration of available colors for formatted messages.
@ RESET
Reset to default color.
const std::vector< std::string > COLOR_TOKENS_UTILS_DARK
ANSI color codes for dark terminal backgrounds.
void open_folder(const std::string &path)
void ensure_file_is_open(const std::ifstream &file, const fs::path &file_name)
Ensures that a file stream is successfully opened.
json read_json(const fs::path &string_path)
Reads and parses a JSON file, uses nlohmann json library.
bool is_empty_char(char c)
Checks if a character is considered empty/whitespace.
std::string format_size(std::uintmax_t bytes)
Formats a byte size into a human-readable string.
std::uintmax_t folder_size(const fs::path &folder)
Calculates the total size of all regular files in a folder.
std::vector< std::string > read_file_generic(const fs::path &string_path)
Reads a file line by line into a vector of strings.
std::string hash(const std::string &content)
Computes a simple hash of a string.
Wrapped wrapped(const std::string &text, size_t spaces, bool use_first_line)
std::ostream & operator<<(std::ostream &os, const Wrapped &w)
Defines utility functions used across all files.