From 83d5ba42f8a98fc0df177efef4333f74a0481f61 Mon Sep 17 00:00:00 2001 From: pants Date: Mon, 21 Sep 2026 14:18:06 -0700 Subject: init --- include/util.hpp | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 include/util.hpp (limited to 'include/util.hpp') diff --git a/include/util.hpp b/include/util.hpp new file mode 100644 index 0000000..9a0d3a7 --- /dev/null +++ b/include/util.hpp @@ -0,0 +1,67 @@ +// Display images inside a terminal +// Copyright (C) 2023 JustKidding +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#ifndef NAMESPACE_UTIL_H +#define NAMESPACE_UTIL_H + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "flags.hpp" +#include "os.hpp" +#include "process.hpp" + +namespace util +{ +auto str_split(std::string_view str, std::string_view delim) -> std::vector; +auto get_process_tree(int pid) -> std::vector; +auto get_process_tree_v2(int pid) -> std::vector; +auto get_b2_hash_ssl(std::string_view str) -> std::string; +auto get_cache_path() -> std::string; +auto get_cache_file_save_location(const std::filesystem::path &path) -> std::string; +auto get_log_filename() -> std::string; +auto get_socket_path(int pid = os::get_pid()) -> std::string; +void send_socket_message(std::string_view msg, std::string_view endpoint); +auto base64_encode(const unsigned char *input, size_t length) -> std::string; +void base64_encode_v2(const unsigned char *input, size_t length, unsigned char *out); +void move_cursor(int row, int col); +void save_cursor_position(); +void restore_cursor_position(); +void benchmark(const std::function &func); +void send_command(const Flags &flags); +void clear_terminal_area(int xcoord, int ycoord, int width, int height); +auto generate_random_string(std::size_t length) -> std::string; +auto round_up(int num_to_round, int multiple) -> int; +auto temp_directory_path() -> std::filesystem::path; + +auto read_exif_rotation(const std::filesystem::path &path) -> std::optional; +template +auto generate_random_number(T min, T max = std::numeric_limits::max()) -> T +{ + std::random_device dev; + std::mt19937 rng(dev()); + std::uniform_int_distribution dist(min, max); + return dist(rng); +} +} // namespace util + +#endif -- cgit v1.2.3