Skip to content

Commit

Permalink
clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
Toni500github committed Jan 26, 2025
1 parent 54351b6 commit d7a999a
Show file tree
Hide file tree
Showing 15 changed files with 153 additions and 178 deletions.
7 changes: 4 additions & 3 deletions include/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ 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, bool do_not_load = false);
Config(const std::string_view configFile, const std::string_view configDir, colors_t& colors,
bool do_not_load = false);

// Variables of config file in [config] table
std::vector<std::string> layout;
Expand All @@ -84,7 +85,7 @@ class Config
bool use_SI_unit = false;
bool wrap_lines = false;

// Variables of config file for
// Variables of config file for
// modules specific configs
// [uptime]
std::string uptime_d_fmt;
Expand Down Expand Up @@ -121,7 +122,7 @@ class Config
* @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.
Expand Down
28 changes: 14 additions & 14 deletions include/gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,33 +45,32 @@ 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:
Gtk::Overlay m_overlay;
Gtk::Box m_box;
Gtk::Alignment m_alignment;
Gtk::Label m_label;
Gtk::Image *m_img, m_bg_image;
Gtk::Overlay m_overlay;
Gtk::Box m_box;
Gtk::Alignment m_alignment;
Gtk::Label m_label;
Gtk::Image * m_img, m_bg_image;
Glib::RefPtr<Gdk::PixbufAnimationIter> m_iter;
Glib::RefPtr<Gdk::PixbufAnimation> m_bg_animation;
Glib::RefPtr<Gdk::Pixbuf> m_bg_static_image;
int m_width, m_height;
Glib::RefPtr<Gdk::PixbufAnimation> m_bg_animation;
Glib::RefPtr<Gdk::Pixbuf> m_bg_static_image;
int m_width, m_height;

// Update background image size (gif or static)
// on window resize
void on_window_resize(const Gtk::Allocation& allocation)
{
m_width = allocation.get_width();
m_width = allocation.get_width();
m_height = allocation.get_height();

if (m_bg_static_image)
Expand All @@ -98,7 +97,8 @@ class Window : public Gtk::Window
void update_static_image()
{
// scale the static image to fit the window size
const Glib::RefPtr<Gdk::Pixbuf> scaled_image = m_bg_static_image->scale_simple(m_width, m_height, Gdk::INTERP_BILINEAR);
const Glib::RefPtr<Gdk::Pixbuf> scaled_image =
m_bg_static_image->scale_simple(m_width, m_height, Gdk::INTERP_BILINEAR);
m_bg_image.set(scaled_image);
}

Expand All @@ -109,11 +109,11 @@ class Window : public Gtk::Window
const Glib::RefPtr<Gdk::Pixbuf> current_frame = m_iter->get_pixbuf();
if (current_frame)
{
const Glib::RefPtr<Gdk::Pixbuf> scaled_frame = current_frame->scale_simple(m_width, m_height, Gdk::INTERP_BILINEAR);
const Glib::RefPtr<Gdk::Pixbuf> scaled_frame =
current_frame->scale_simple(m_width, m_height, Gdk::INTERP_BILINEAR);
m_bg_image.set(scaled_frame);
}
}

};

} // namespace GUI
Expand Down
8 changes: 5 additions & 3 deletions include/parse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#define _PARSE_HPP

#include <string>

#include "config.hpp"
#include "query.hpp"

Expand All @@ -41,9 +42,9 @@ struct parse_args_t
const Config& config;
const colors_t& colors;
bool parsingLayout;
bool firstrun_clr = true;
bool firstrun_clr = true;
bool no_more_reset = false;
std::string endspan = ""; // only for ANDROID_APP
std::string endspan = ""; // only for ANDROID_APP
};

/* Parse input, in-place, with data from systemInfo.
Expand Down Expand Up @@ -72,7 +73,8 @@ std::string parse(const std::string_view input, std::string& _, parse_args_t& pa
* @param moduleMemberName The module member name
* @param parse_args The parse() like arguments
*/
void addValueFromModuleMember(const std::string& moduleName, const std::string& moduleMemberName, parse_args_t& parse_args);
void addValueFromModuleMember(const std::string& moduleName, const std::string& moduleMemberName,
parse_args_t& parse_args);

/* Set module only values to a systemInfo_t map.
* If the name of said module matches any module name, it will be added
Expand Down
2 changes: 1 addition & 1 deletion include/pci.ids.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39097,6 +39097,6 @@ inline const std::string& all_ids =
inline constexpr std::array<std::string_view, 2405> pci_vendors_array = {};
inline constexpr std::array<int, 2405> pci_vendors_location_array = {};

#endif // !CF_ANDROID
#endif // !CF_ANDROID

#endif // _PCI_IDS_HPP
25 changes: 12 additions & 13 deletions include/query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,11 @@ class CPU
std::string& vendor() noexcept;
std::string& modelname() noexcept;

double& freq_max() noexcept;
double& freq_min() noexcept;
double& freq_cur() noexcept;
double& freq_bios_limit() noexcept;
double& temp() noexcept;
double& freq_max() noexcept;
double& freq_min() noexcept;
double& freq_cur() noexcept;
double& freq_bios_limit() noexcept;
double& temp() noexcept;

private:
static bool m_bInit;
Expand All @@ -233,12 +233,12 @@ class GPU
std::string& vendor() noexcept;

private:
uint16_t m_vendor_id;
uint16_t m_device_id;
std::string m_vendor_id_s;
std::string m_device_id_s;
uint16_t m_vendor_id;
uint16_t m_device_id;
std::string m_vendor_id_s;
std::string m_device_id_s;

static GPU_t m_gpu_infos;
static GPU_t m_gpu_infos;
};

class Battery
Expand All @@ -251,8 +251,8 @@ class Battery
std::string status{ MAGIC_LINE };
std::string technology{ UNKNOWN };
std::string capacity_level{ UNKNOWN };
double temp{0};
double capacity{0};
double temp{ 0 };
double capacity{ 0 };
};

Battery();
Expand All @@ -265,7 +265,6 @@ class Battery
double& capacity() noexcept;
double& temp() noexcept;


private:
static bool m_bInit;
static Battery_t m_battery_infos;
Expand Down
6 changes: 3 additions & 3 deletions include/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@
#include <sys/stat.h>
#include <sys/types.h>

#include <chrono>
#include <cstdlib>
#include <filesystem>
#include <iostream>
#include <chrono>
#include <string>
#include <vector>

#include "fmt/base.h"
#include "fmt/chrono.h"
#include "fmt/color.h"
#include "fmt/base.h"
#include "fmt/os.h"
#include "platform.hpp"

Expand Down Expand Up @@ -345,8 +345,8 @@ void info(const std::string_view fmt, Args&&... args) noexcept
fmt::format(fmt::runtime(fmt), std::forward<Args>(args)...));
}
#else
#include "jni.h"
#include "android/log.h"
#include "jni.h"

inline struct jni_objects
{
Expand Down
25 changes: 12 additions & 13 deletions src/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ std::string Display::detect_distro(const Config& config)
#else
return config.data_dir + "/ascii/linux.txt";
#endif

}

#if !ANDROID_APP
Expand All @@ -94,10 +93,10 @@ static std::vector<std::string> render_with_image(systemInfo_t& systemInfo, std:

if (!img)
die(_("Unable to load image '{}'"), path);

stbi_image_free(img);

std::string _;
std::string _;
parse_args_t parse_args{ systemInfo, _, config, colors, true };
for (std::string& line : layout)
{
Expand All @@ -111,19 +110,20 @@ static std::vector<std::string> render_with_image(systemInfo_t& systemInfo, std:
layout.erase(std::remove_if(layout.begin(), layout.end(),
[](const std::string_view str) { return str.find(MAGIC_LINE) != std::string::npos; }),
layout.end());

// took math from neofetch in get_term_size() and get_image_size(). seems to work nice
const size_t width = image_width / font_width;
const size_t height = image_height / font_height;

if (config.m_image_backend == "kitty")
taur_exec({ "kitty", "+kitten", "icat", "--align", (config.logo_position == "top" ? "center" : config.logo_position), "--place", fmt::format("{}x{}@0x0", width, height),
path });
taur_exec({ "kitty", "+kitten", "icat", "--align",
(config.logo_position == "top" ? "center" : config.logo_position), "--place",
fmt::format("{}x{}@0x0", width, height), path });
else if (config.m_image_backend == "viu")
taur_exec({ "viu", "-t", "-w", fmt::to_string(width), "-h", fmt::to_string(height), path });
else
die(_("The image backend '{}' isn't supported, only 'kitty' and 'viu'.\n"
"Please currently use the GUI mode for rendering the image/gif (use -h for more details)"),
"Please currently use the GUI mode for rendering the image/gif (use -h for more details)"),
config.m_image_backend);

if (config.logo_position == "top")
Expand Down Expand Up @@ -295,10 +295,10 @@ std::vector<std::string> Display::render(const Config& config, const colors_t& c
std::string line;
while (std::getline(file, line))
{
std::string pureOutput;
std::string pureOutput;
parse_args_t parse_args{ systemInfo, pureOutput, config, colors, false };

std::string asciiArt_s = parse(line, parse_args);
std::string asciiArt_s = parse(line, parse_args);
parse_args.no_more_reset = false;
if (!config.m_disable_colors)
asciiArt_s += config.gui ? "" : NOCOLOR;
Expand All @@ -324,16 +324,16 @@ std::vector<std::string> Display::render(const Config& config, const colors_t& c
if (config.m_print_logo_only)
return asciiArt;

std::string _;
std::string _;
parse_args_t parse_args{ systemInfo, _, config, colors, true };
for (std::string& line : layout)
{
line = parse(line, parse_args);
line = parse(line, parse_args);
parse_args.no_more_reset = false;
if (!config.gui && !config.m_disable_colors)
line.insert(0, NOCOLOR);
}

auto_colors.clear();

// erase each element for each instance of MAGIC_LINE
Expand Down Expand Up @@ -374,7 +374,6 @@ std::vector<std::string> Display::render(const Config& config, const colors_t& c

if (!config.m_disable_colors)
layout.at(i) += config.gui ? "" : NOCOLOR;

}

for (; i < asciiArt.size(); i++)
Expand Down
8 changes: 4 additions & 4 deletions src/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
#include "display.hpp"
#include "fmt/ranges.h"
#include "gdkmm/pixbufanimation.h"
#include "gtkmm/enums.h"
#include "glibmm/main.h"
#include "gtkmm/enums.h"
#include "pangomm/fontdescription.h"
#include "parse.hpp"
#include "query.hpp"
Expand Down Expand Up @@ -87,7 +87,7 @@ static std::vector<std::string> render_with_image(const Config& config, const co
// this is just for parse() to auto add the distro colors
std::ifstream file(path, std::ios::binary);
std::string line, _;
parse_args_t parse_args{ systemInfo, _, config, colors, false, true };
parse_args_t parse_args{ systemInfo, _, config, colors, false, true };

while (std::getline(file, line))
{
Expand All @@ -96,9 +96,9 @@ static std::vector<std::string> render_with_image(const Config& config, const co
}

parse_args.parsingLayout = true;
for (std::string& layout : layout)
for (std::string& line : layout)
{
layout = parse(layout, parse_args);
line = parse(line, parse_args);
parse_args.no_more_reset = false;
}

Expand Down
Loading

0 comments on commit d7a999a

Please sign in to comment.