diff --git a/include/config.hpp b/include/config.hpp index 2d567d7..79b4494 100644 --- a/include/config.hpp +++ b/include/config.hpp @@ -33,6 +33,8 @@ #include "toml++/toml.hpp" #include "util.hpp" +// config colors +// those without gui_ prefix are for the terminal struct colors_t { std::string black; @@ -57,9 +59,10 @@ struct colors_t class Config { public: + // Create .config directories and files and load the config file (args or default) Config(const std::string_view configFile, const std::string_view configDir, colors_t& colors); - // config file + // Variables of config file in [config] table std::vector layout; std::vector percentage_colors; std::vector colors_name, colors_value; @@ -81,12 +84,14 @@ class Config bool use_SI_unit = false; bool wrap_lines = false; - // modules specific config + // Variables of config file for + // modules specific configs, e.g [uptime] std::string uptime_d_fmt; std::string uptime_h_fmt; std::string uptime_m_fmt; std::string uptime_s_fmt; + // [pkgs] std::vector pkgs_managers; std::vector pacman_dirs; std::vector flatpak_dirs; @@ -102,12 +107,37 @@ class Config bool m_display_distro = true; bool m_print_logo_only = false; - void loadConfigFile(const std::string_view filename, colors_t& colors); - std::string getThemeValue(const std::string_view value, const std::string_view fallback) const; - void generateConfig(const std::string_view filename); - void addAliasColors(const std::string& str); - std::vector getValueArrayStr(const std::string_view value, const std::vector& fallback); + /** + * Load config file and parse every config variables + * @param filename The config file path + * @param colors The colors struct where we'll put the default config colors. + * It doesn't include the colors in config.alias-colors + */ + void loadConfigFile(const std::string_view filename, colors_t& colors); + + /** + * Generate a config file + * @param filename The config file path + */ + void generateConfig(const std::string_view filename); + + /** + * Add alias values to colors_name and colors_value. + * @param str The alias color to add. + * Must have a '=' for separating color name and value, + * E.g "pink=!#FFC0CB" + */ + void addAliasColors(const std::string& str); + +private: + // Parsed config from loadConfigFile() + toml::table tbl; + /** + * Get value of config variables + * @param value The config variable "path" (e.g "config.source-path") + * @param fallback Default value if couldn't retrive value + */ template T getValue(const std::string_view value, const T&& fallback) const { @@ -118,10 +148,23 @@ class Config return ret.value_or(fallback); } -private: - toml::table tbl; + /** + * getValue() but don't want to specify the template, so it's std::string, + * and because of the name, only used when retriving the colors for terminal and GUI + * @param value The config variable "path" (e.g "config.gui-red") + * @param fallback Default value if couldn't retrive value + */ + std::string getThemeValue(const std::string_view value, const std::string_view fallback) const; + + /** + * Get value of config array of string variables + * @param value The config variable "path" (e.g "config.gui-red") + * @param fallback Default value if couldn't retrive value + */ + std::vector getValueArrayStr(const std::string_view value, const std::vector& fallback); }; +// default config inline constexpr std::string_view AUTOCONFIG = R"#([config] # customfetch is designed with customizability in mind # here is how it works: diff --git a/include/display.hpp b/include/display.hpp index de92a44..ba70279 100644 --- a/include/display.hpp +++ b/include/display.hpp @@ -35,7 +35,7 @@ namespace Display { /* - * Render the layout along side the ASCII art and return the vector + * Render the layout along side the source file and return the vector * @param config The config class * @param colors The colors * @param already_analyzed_path If already checked that the source path is not a binary file @@ -45,7 +45,7 @@ std::vector render(const Config& config, const colors_t& colors, co const std::string_view path); /* - * Display the ascii art and layout + * Display the rendered result (or just display a normal vector of strings) * @param renderResult The rendered vector usually by Display::render() */ void display(const std::vector& renderResult); diff --git a/include/gui.hpp b/include/gui.hpp index 9a3ac48..c43df01 100644 --- a/include/gui.hpp +++ b/include/gui.hpp @@ -45,7 +45,15 @@ namespace GUI class Window : public Gtk::Window { public: + + /** + * Initialize and create everything and parse layout with source path. + * @param config The config class + * @param colors The non-alias colors struct + * @param path The logo source path + */ Window(const Config& config, const colors_t& colors, const std::string_view path); + // Destroy the window, handled by GTK virtual ~Window(); private: @@ -59,19 +67,22 @@ class Window : public Gtk::Window Glib::RefPtr m_bg_static_image; int m_width, m_height; - void on_window_resize(Gtk::Allocation& allocation) + // Update background image size (gif or static) + // on window resize + void on_window_resize(const Gtk::Allocation& allocation) { m_width = allocation.get_width(); m_height = allocation.get_height(); if (m_bg_static_image) - // static image: Update to fit the new window size + // static image: update to fit the new window size update_static_image(); else if (m_iter) - // animated image: Update the current frame + // gif: update the current frame update_frame(); } + // Update background gif size bool on_update_animation() { if (!m_iter) @@ -83,6 +94,7 @@ class Window : public Gtk::Window return true; // continue the timer } + // Update background image size void update_static_image() { // scale the static image to fit the window size @@ -90,6 +102,7 @@ class Window : public Gtk::Window m_bg_image.set(scaled_image); } + // Update background gif size in the current frame void update_frame() { // scale the current frame of the animation to fit the window size diff --git a/include/parse.hpp b/include/parse.hpp index a533eee..e9e549a 100644 --- a/include/parse.hpp +++ b/include/parse.hpp @@ -30,8 +30,8 @@ #include "config.hpp" #include "query.hpp" -/* the additional args that parse() needs for getting the necessary infos/configs. - * only used for making the argument passing more clear. +/* The additional args that parse() needs for getting the necessary infos/configs. + * Only used for making the argument passing more clear. * Always pass it non-const and by reference */ struct parse_args_t @@ -84,6 +84,9 @@ void addValueFromModule(const std::string& moduleName, parse_args_t& parse_args) /* * Return a module member value + * @param systemInfo The systemInfo_t map + * @param moduleName The module name + * @param moduleMemberName The module member name */ std::string getInfoFromName(const systemInfo_t& systemInfo, const std::string_view moduleName, const std::string_view moduleMemberName); diff --git a/include/query.hpp b/include/query.hpp index 468fe61..42abd39 100644 --- a/include/query.hpp +++ b/include/query.hpp @@ -45,8 +45,10 @@ extern "C" { #include } +// Special variable for storing info modules values using systemInfo_t = std::unordered_map>>; +// used in systemInfo_t most of the time using variant = std::variant; namespace Query diff --git a/include/util.hpp b/include/util.hpp index 0116ff0..2d5e0d7 100644 --- a/include/util.hpp +++ b/include/util.hpp @@ -38,11 +38,13 @@ #include "platform.hpp" // clang-format off +// Get string literal length constexpr std::size_t operator""_len(const char*, std::size_t ln) noexcept { return ln; } +// used for auto_devide_bytes() struct byte_units_t { std::string unit; @@ -53,8 +55,13 @@ constexpr const char NOCOLOR[] = "\033[0m"; constexpr const char NOCOLOR_BOLD[] = "\033[0m\033[1m"; constexpr const char UNKNOWN[] = "(unknown)"; -// magic line to be sure that I don't cut the wrong line -constexpr const char MAGIC_LINE[] = "(cut this shit NOW!! RAHHH)"; +// Usually in neofetch/fastfetch when some infos couldn't be queried, +// they remove it from the display. With customfetch is kinda difficult to know when to remove +// the info to display, since it's all modular with tags, so I have created +// magic line to be sure that I don't cut the wrong line. +// +// Every instance of this string in a layout line, the whole line will be erased. +constexpr const char MAGIC_LINE[] = "(cut this line NOW!! RAHHH)"; /* lib = library to load (string) * code = code to execute if anything goes wrong @@ -76,47 +83,256 @@ constexpr const char MAGIC_LINE[] = "(cut this shit NOW!! RAHHH)"; #define BOLD_COLOR(x) (fmt::emphasis::bold | fmt::fg(x)) -bool hasEnding(const std::string_view fullString, const std::string_view ending); -bool hasStart(const std::string_view fullString, const std::string_view start); -std::string name_from_entry(size_t dev_entry_pos); -std::string vendor_from_entry(size_t vendor_entry_pos, const std::string_view vendor_id); -std::string binarySearchPCIArray(const std::string_view vendor_id, const std::string_view pci_id); -std::string binarySearchPCIArray(const std::string_view vendor_id); -std::string read_shell_exec(const std::string_view cmd); -void getFileValue(u_short& iterIndex, const std::string_view line, std::string& str, const size_t& amount); +/* https://stackoverflow.com/questions/874134/find-out-if-string-ends-with-another-string-in-c#874160 + * Check if substring exists at the end + * @param fullString The string to lookup + * @param ending The string to check at the end of fullString + */ +bool hasEnding(const std::string_view fullString, const std::string_view ending); + +/* https://stackoverflow.com/questions/874134/find-out-if-string-ends-with-another-string-in-c#874160 + * Check if substring exists at the start + * @param fullString The string to lookup + * @param start The string to check at the start of fullString + */ +bool hasStart(const std::string_view fullString, const std::string_view start); + +std::vector split(const std::string_view text, char delim); + +/* Get device name from `all_ids` in pci.ids.hpp + * @param dev_entry_pos Line position from where the device is located + */ +std::string name_from_entry(size_t dev_entry_pos); + +/* Get vendor device name from `all_ids` in pci.ids.hpp + * @param vendor_entry_pos Line position from where the device is located + * @param vendor_id_s The vendor ID (e.g 10de) + */ +std::string vendor_from_entry(const size_t vendor_entry_pos, const std::string_view vendor_id_s); + +/* Function to perform binary search on the pci vendors array to find a device from a vendor. + * @param vendor_id_s The vendor ID (e.g 10de) + * @param pci_id_s The device ID (e.g 1f82) + */ +std::string binarySearchPCIArray(const std::string_view vendor_id_s, const std::string_view pci_id_s); + +/* Function to perform binary search on the pci vendors array to find a vendor. + * @param vendor_id_s The vendor ID (e.g 10de) + */ +std::string binarySearchPCIArray(const std::string_view vendor_id_s); + +/* http://stackoverflow.com/questions/478898/ddg#478960 + * Execute shell command and read its output from stdout. + * @param cmd The command to execute + */ +std::string read_shell_exec(const std::string_view cmd); + +/* Get file value from a file and trim quotes and double-quotes + * @param iterIndex The iteration index used for getting the necessary value only tot times + * @param line The string used in std::getline + * @param str The string to assign the trimmed value, inline + * @param amount The amount to be used in the line.substr() (should be used with something like "foobar"_len) + */ +void getFileValue(u_short& iterIndex, const std::string_view line, std::string& str, const size_t& amount); + +/* Covert bytes (or bibytes) to be accurate to the max prefix (maxprefix or YB/YiB) + * @param num The number to convert + * @param base Base to devide (1000 = bytes OR 1024 = bibytes) + * @param maxprefix The maxinum prefix we can go up to (empty for ignore) + */ byte_units_t auto_devide_bytes(const double num, const std::uint16_t base, const std::string_view maxprefix = ""); + +/* Covert bytes (or bibytes) to be accurate to a specific prefix + * @param num The number to convert + * @param prefix The prefix we want to convert to (GiB, MB, etc.) + */ byte_units_t devide_bytes(const double num, const std::string_view prefix); -bool is_file_image(const unsigned char* bytes); -void ctrl_d_handler(const std::istream& cin); -std::string expandVar(std::string ret); -bool taur_exec(const std::vector cmd_str, const bool noerror_print = true); -std::string which(const std::string_view command); -std::string get_data_path(const std::string_view file); -std::string get_data_dir(const std::string_view dir); -std::string get_relative_path(const std::string_view relative_path, const std::string_view _env, const long long mode); -bool read_binary_file(std::ifstream& f, std::string& ret); -void replace_str(std::string& str, const std::string_view from, const std::string_view to); -bool read_exec(std::vector cmd, std::string& output, bool useStdErr = false, bool noerror_print = true); -std::string str_tolower(std::string str); -std::string str_toupper(std::string str); -void strip(std::string& input); -std::string read_by_syspath(const std::string_view path); -fmt::rgb hexStringToColor(const std::string_view hexstr); -std::string shorten_vendor_name(std::string vendor); -std::string getHomeConfigDir(); -std::string getConfigDir(); -std::vector split(const std::string_view text, char delim); + +/* Check if file is image (static or gif). + * Doesn't check for mp4, mp3 or other binary formats + * @param bytes The header bytes of the file + */ +bool is_file_image(const unsigned char* bytes); + +/* Write error message and exit if EOF (or CTRL-D most of the time) + * @param cin The std::cin used for getting the input + */ +void ctrl_d_handler(const std::istream& cin); + +/* Replace special symbols such as ~ and $ (at the begging) in std::string + * @param str The string + * @return The modified string + */ +std::string expandVar(std::string ret); + +/* Executes commands with execvp() and keep the program running without existing + * @param cmd_str The command to execute + * @param exitOnFailure Whether to call exit(1) on command failure. + * @return true if the command successed, else false + */ +bool taur_exec(const std::vector cmd_str, const bool noerror_print = true); + +/* Get a relative path from an enviroment variable (PATH, XDG_DATA_DIRS, ...) + * Either path of an executable, directory, etc... + * @param relative_path The path we would search in the env + * @param env The enviroment variable without $ + * @param mode Mode of the file/directory using the enums declared in sys/stat.h + * Such as S_IXUSR for executables, S_IFDIR for directories, etc. + */ +std::string get_relative_path(const std::string_view relative_path, const std::string_view env, const long long mode); + +/* Simulate behaviour of the command `which` + * @param command The command to lookup in the $PATH + */ +std::string which(const std::string_view command); + +/* Get file path from $XDG_DATA_DIRS + * @param file The file to lookup in the env + */ +std::string get_data_path(const std::string_view file); + +/* Get directory path from $XDG_DATA_DIRS + * @param dir The directory to lookup in the env + */ +std::string get_data_dir(const std::string_view dir); + +/* Read a binary file and get its current line, + * which simulates the behaviour of the command `strings` but one line at the time + * @param f The std::ifstream of the file + * @param ret The string to return after we read the line + * @example + * std::ifstream f(exec_path, std::ios::binary); + * if (!f.is_open()) + * return false; + * + * std::string line; + * while (read_binary_file(f, line)) + * { + * if (line == "using GTK+-%d.%d.%d.") + * return true; + * + * // previous line, which will eventually be the version + * ret = line; + * } + * return false; + */ +bool read_binary_file(std::ifstream& f, std::string& ret); + +/* https://gist.github.com/GenesisFR/cceaf433d5b42dcdddecdddee0657292 + * Replace every instances (inplace) of a substring + * @param str The full string to use + * @param from The substring to lookup to be replaced + * @param to The substring to replace in instances of `from` + */ +void replace_str(std::string& str, const std::string_view from, const std::string_view to); + +/* Executes commands with execvp() and read its output + * either from stdout or stderr + * @param cmd_str The command to execute + * @param output The string to use for appending the output + * @param useStdErr Read from stderr instead of stdout + * @param noerror_print Print errors + * @return true if the command successed, else false + */ +bool read_exec(std::vector cmd, std::string& output, bool useStdErr = false, bool noerror_print = true); + +/* Make whole string lowercase + * @param str The string to use + */ +std::string str_tolower(std::string str); + +/* Make whole string uppercase + * @param str The string to use + */ +std::string str_toupper(std::string str); + +/* Remove all white spaces (' ', '\t', '\n') from string inplace! + * @param input The string to strip + * @original https://github.com/lfreist/hwinfo/blob/main/include/hwinfo/utils/stringutils.h#L50 + */ +void strip(std::string& input); + +/* Read file content (usually from /sys) + * and return its first (and only) line + * @param path The path of the file to read + */ +std::string read_by_syspath(const std::string_view path); + +/* Convert hex color (#255224) to a fmt::rgb + * @param hexstr The hex color string (must have a '#' at the start) + */ +fmt::rgb hexStringToColor(const std::string_view hexstr); + +/* Abbreviate the vendors names + * @param vendor The vendor name + */ +std::string shorten_vendor_name(std::string vendor); + +/* + * Get the user config directory + * either from $XDG_CONFIG_HOME or from $HOME/.config/ + * @return user's config directory + */ +std::string getHomeConfigDir(); + +/* + * Get the customfetch config directory + * where we'll have "config.toml" + * from getHomeConfigDir() + * @return customfetch's config directory + */ +std::string getConfigDir(); #if CF_ANDROID +/* Get android property name such as "ro.product.marketname" + * @param name The property name + */ std::string get_android_property(const std::string_view name); #endif -#if ANDROID_APP +#if !ANDROID_APP + +template +void error(const std::string_view fmt, Args&&... args) noexcept +{ + fmt::print(stderr, BOLD_COLOR(fmt::rgb(fmt::color::red)), "ERROR: {}\n", + fmt::format(fmt::runtime(fmt), std::forward(args)...)); +} + +template +void die(const std::string_view fmt, Args&&... args) noexcept +{ + fmt::print(stderr, BOLD_COLOR(fmt::rgb(fmt::color::red)), "FATAL: {}\n", + fmt::format(fmt::runtime(fmt), std::forward(args)...)); + std::exit(1); +} + +template +void debug(const std::string_view fmt, Args&&... args) noexcept +{ +#if DEBUG + fmt::print(BOLD_COLOR((fmt::rgb(fmt::color::hot_pink))), "[DEBUG]: {}\n", + fmt::format(fmt::runtime(fmt), std::forward(args)...)); +#endif +} + +template +void warn(const std::string_view fmt, Args&&... args) noexcept +{ + fmt::print(BOLD_COLOR((fmt::rgb(fmt::color::yellow))), "WARNING: {}\n", + fmt::format(fmt::runtime(fmt), std::forward(args)...)); +} + +template +void info(const std::string_view fmt, Args&&... args) noexcept +{ + fmt::print(BOLD_COLOR((fmt::rgb(fmt::color::cyan))), "INFO: {}\n", + fmt::format(fmt::runtime(fmt), std::forward(args)...)); +} +#else #include "jni.h" #include "android/log.h" -#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, "JNI_TOAST", __VA_ARGS__) - inline struct jni_objects { JNIEnv *env; @@ -175,45 +391,7 @@ void info(const std::string_view fmt, Args&&... args) noexcept nativeLog(jni_objs.env, jni_objs.obj, ANDROID_LOG_INFO, "{}", fmt_str); } -#else -template -void error(const std::string_view fmt, Args&&... args) noexcept -{ - fmt::print(stderr, BOLD_COLOR(fmt::rgb(fmt::color::red)), "ERROR: {}\n", - fmt::format(fmt::runtime(fmt), std::forward(args)...)); -} - -template -void die(const std::string_view fmt, Args&&... args) noexcept -{ - fmt::print(stderr, BOLD_COLOR(fmt::rgb(fmt::color::red)), "FATAL: {}\n", - fmt::format(fmt::runtime(fmt), std::forward(args)...)); - std::exit(1); -} - -template -void debug(const std::string_view fmt, Args&&... args) noexcept -{ -#if DEBUG - fmt::print(BOLD_COLOR((fmt::rgb(fmt::color::hot_pink))), "[DEBUG]: {}\n", - fmt::format(fmt::runtime(fmt), std::forward(args)...)); -#endif -} - -template -void warn(const std::string_view fmt, Args&&... args) noexcept -{ - fmt::print(BOLD_COLOR((fmt::rgb(fmt::color::yellow))), "WARNING: {}\n", - fmt::format(fmt::runtime(fmt), std::forward(args)...)); -} - -template -void info(const std::string_view fmt, Args&&... args) noexcept -{ - fmt::print(BOLD_COLOR((fmt::rgb(fmt::color::cyan))), "INFO: {}\n", - fmt::format(fmt::runtime(fmt), std::forward(args)...)); -} -#endif +#endif // !ANDROID_APP /** Ask the user a yes or no question. * @param def The default result diff --git a/src/config.cpp b/src/config.cpp index b76686b..3a65796 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -128,7 +128,6 @@ void Config::loadConfigFile(const std::string_view filename, colors_t& colors) this->m_disable_colors = true; } -// Config::getValue() but don't want to specify the template std::string Config::getThemeValue(const std::string_view value, const std::string_view fallback) const { return this->tbl.at_path(value).value().value_or(fallback.data()); diff --git a/src/parse.cpp b/src/parse.cpp index c8e49be..64cd9d8 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -205,7 +205,7 @@ static std::string get_and_color_percentage(const float& n1, const float& n2, pa const bool invert = false) { const Config& config = parse_args.config; - const float result = static_cast(n1 / n2 * static_cast(100)); + const float result = n1 / n2 * static_cast(100); std::string color; if (!invert) diff --git a/src/query/android/gpu.cpp b/src/query/android/gpu.cpp index 0cbfbe1..6906f6c 100644 --- a/src/query/android/gpu.cpp +++ b/src/query/android/gpu.cpp @@ -181,6 +181,7 @@ static std::string detect_adreno(const std::string& cpu_model_name) case "SM7675-AB"_fnv1a16: return "Adreno (TM) 732"; case "SM8635"_fnv1a16: return "Adreno (TM) 735"; + case "SM8550"_fnv1a16: case "SM8550-AB"_fnv1a16: case "SM8550-AC"_fnv1a16: return "Adreno (TM) 740"; diff --git a/src/util.cpp b/src/util.cpp index 5771fdb..de8b862 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -50,7 +50,6 @@ #include "pci.ids.hpp" #include "platform.hpp" -// https://stackoverflow.com/questions/874134/find-out-if-string-ends-with-another-string-in-c#874160 bool hasEnding(const std::string_view fullString, const std::string_view ending) { if (ending.length() > fullString.length()) @@ -84,10 +83,6 @@ void ctrl_d_handler(const std::istream& cin) die("Exiting due to CTRL-D or EOF"); } -/** Replace special symbols such as ~ and $ in std::strings - * @param str The string - * @return The modified string - */ std::string expandVar(std::string ret) { if (ret.empty()) @@ -208,12 +203,6 @@ bool is_file_image(const unsigned char* bytes) // clang-format on } -/** - * remove all white spaces (' ', '\t', '\n') from start and end of input - * inplace! - * @param input - * @Original https://github.com/lfreist/hwinfo/blob/main/include/hwinfo/utils/stringutils.h#L50 - */ void strip(std::string& input) { if (input.empty()) @@ -241,12 +230,6 @@ void strip(std::string& input) input.erase(0, input.find_first_not_of(ws)); } -/* Get file value from a file and trim quotes and double-quotes - * @param iterIndex The iteration index used for getting the necessary value only tot times - * @param line The string used in std::getline - * @param str The string to assign the trimmed value, inline - * @param amount The amount to be used in the line.substr() (should be used with something like "foobar"_len) - */ void getFileValue(u_short& iterIndex, const std::string_view line, std::string& str, const size_t& amount) { str = line.substr(amount); @@ -305,17 +288,17 @@ bool read_binary_file(std::ifstream& f, std::string& ret) return false; } -std::string get_relative_path(const std::string_view relative_path, const std::string_view _env, const long long mode) +std::string get_relative_path(const std::string_view relative_path, const std::string_view env, const long long mode) { - const char *env = std::getenv(_env.data()); - if (!env) + const char *_env = std::getenv(env.data()); + if (!_env) return UNKNOWN; struct stat sb; std::string fullPath; fullPath.reserve(1024); - for (const std::string& dir : split(env, ':')) + for (const std::string& dir : split(_env, ':')) { // -300ns for not creating a string. stonks fullPath += dir; @@ -358,7 +341,6 @@ std::string get_android_property(const std::string_view name) } #endif -// https://gist.github.com/GenesisFR/cceaf433d5b42dcdddecdddee0657292 void replace_str(std::string& str, const std::string_view from, const std::string_view to) { size_t start_pos = 0; @@ -432,11 +414,6 @@ bool read_exec(std::vector cmd, std::string& output, bool useStdErr return false; } -/** Executes commands with execvp() and keep the program running without existing - * @param cmd_str The command to execute - * @param exitOnFailure Whether to call exit(1) on command failure. - * @return true if the command successed, else false - */ bool taur_exec(const std::vector cmd_str, const bool noerror_print) { std::vector cmd; @@ -491,7 +468,6 @@ std::string str_toupper(std::string str) return str; } -// Function to perform binary search on the pci vendors array to find a device from a vendor. std::string binarySearchPCIArray(const std::string_view vendor_id_s, const std::string_view pci_id_s) { const std::string_view vendor_id = hasStart(vendor_id_s, "0x") ? vendor_id_s.substr(2) : vendor_id_s; @@ -532,7 +508,6 @@ std::string binarySearchPCIArray(const std::string_view vendor_id_s, const std:: return name_from_entry(device_location); } -// Function to perform binary search on the pci vendors array to find a vendor. std::string binarySearchPCIArray(const std::string_view vendor_id_s) { const std::string_view vendor_id = hasStart(vendor_id_s, "0x") ? vendor_id_s.substr(2) : vendor_id_s; @@ -571,7 +546,6 @@ std::string binarySearchPCIArray(const std::string_view vendor_id_s) return vendor_from_entry(vendors_location, vendor_id); } -// http://stackoverflow.com/questions/478898/ddg#478960 std::string read_shell_exec(const std::string_view cmd) { std::array buffer; @@ -612,7 +586,7 @@ std::string name_from_entry(size_t dev_entry_pos) return name; } -std::string vendor_from_entry(const size_t vendor_entry_pos, const std::string_view vendor_id) +std::string vendor_from_entry(const size_t vendor_entry_pos, const std::string_view vendor_id_s) { size_t end_line_pos = all_ids.find('\n', vendor_entry_pos); if (end_line_pos == std::string::npos) @@ -620,7 +594,7 @@ std::string vendor_from_entry(const size_t vendor_entry_pos, const std::string_v const std::string& line = all_ids.substr(vendor_entry_pos, end_line_pos - vendor_entry_pos); - const size_t after_id_pos = line.find(vendor_id) + 4; + const size_t after_id_pos = line.find(vendor_id_s) + 4; const std::string& description = line.substr(after_id_pos); const size_t first = description.find_first_not_of(' '); @@ -633,11 +607,6 @@ std::string vendor_from_entry(const size_t vendor_entry_pos, const std::string_v } // clang-format off -/* - * Get the user config directory - * either from $XDG_CONFIG_HOME or from $HOME/.config/ - * @return user's config directory - */ #if ANDROID_APP std::string getHomeConfigDir() { @@ -665,11 +634,5 @@ std::string getHomeConfigDir() } #endif -/* - * Get the customfetch config directory - * where we'll have "config.toml" - * from getHomeConfigDir() - * @return customfetch's config directory - */ std::string getConfigDir() { return getHomeConfigDir() + "/customfetch"; }