5template <
typename Stream>
8 throw std::runtime_error(
"Attempted to open file: " + file_name.string() +
" but a Error ocurred. Check if the file exist.");
13 std::ifstream file(path);
14 std::stringstream buffer;
15 buffer << file.rdbuf();
20 fs::create_directories(path.parent_path());
21 std::ofstream file(path, std::ios::out | std::ios::trunc);
29 std::vector<std::string> ret;
32 while (getline(filein, line)) {
40 std::ofstream fileout;
41 fs::create_directories(path.parent_path());
44 for (
const auto& line : content) {
45 fileout << line <<
'\n';
51 std::ifstream json_file(string_path.string(), std::ifstream::binary);
80 unsigned char uc =
static_cast<unsigned char>(c);
81 return !(std::isalnum(uc) || c ==
'_');
85 std::string cur_token;
86 std::vector<std::string> ret;
89 if (!cur_token.empty()) {
90 ret.push_back(cur_token);
94 cur_token.push_back(c);
97 if (!cur_token.empty()) {
98 ret.push_back(cur_token);
104 return {text, spaces, use_first_line};
108 std::string indent(w.
spaces,
' ');
110 size_t max_line = 80 - w.
spaces;
112 std::string current_line;
113 std::istringstream stream(w.
text);
114 while (stream >> word) {
115 if (current_line.empty()) {
117 }
else if (current_line.length() + 1 + word.length() > max_line) {
119 os << current_line <<
"\n";
122 os << indent << current_line <<
"\n";
126 current_line +=
" " + word;
129 if (!current_line.empty()) {
131 os << current_line <<
"\n";
133 os << indent << current_line <<
"\n";
140 std::string output = input;
141 for (
char &c : output) {
142 c =
static_cast<char>(
143 std::toupper(
static_cast<unsigned char>(c))
150 std::hash<std::string> hasher;
151 size_t hash = hasher(content);
153 std::stringstream ss;
154 ss << std::hex <<
hash;
156 std::string hash_str = ss.str();
157 if (hash_str.length() > 12) {
158 hash_str = hash_str.substr(0, 12);
165 std::uintmax_t size = 0;
167 if (!fs::exists(folder))
return 0;
170 for (
auto& p : fs::recursive_directory_iterator(folder, fs::directory_options::skip_permission_denied, ec)) {
173 if (fs::is_regular_file(p.status(ec)) && !ec) {
174 size += fs::file_size(p, ec);
182 double size =
static_cast<double>(bytes);
183 const char* units[] = {
"B",
"KB",
"MB",
"GB",
"TB"};
186 while (size >= 1024 && unit < 4) {
191 std::ostringstream out;
192 out << std::fixed << std::setprecision(2) << size << units[unit];
198 std::system((
"explorer \"" + path +
"\"").c_str());
200 std::system((
"open \"" + path +
"\"").c_str());
202 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.
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.
void write_file_with_vector(const fs::path &path, const std::vector< std::string > &content)
Writes content to a file at specified path.
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.
void write_file(const fs::path &path, const std::string &content)
Writes content to a file at specified path.
const std::vector< std::string > COLOR_TOKENS_UTILS_DARK
ANSI color codes for dark terminal backgrounds.
void open_folder(const std::string &path)
std::string read_file(const fs::path &path)
Reads a file into string.
json read_json(const fs::path &string_path)
Reads and parses a JSON file, uses nlohmann json library.
std::vector< std::string > read_file_with_vector(const fs::path &path)
Reads a file line by line into a vector of strings.
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.
void ensure_file_is_open(const Stream &file, const fs::path &file_name)
Ensures that a file stream is successfully opened.
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.