Skip to content

Commit 34639b8

Browse files
committed
misc: code stuff, nothing important
WE reached 300 commits in less than 5 months. Thanks yall for the support :)
1 parent 412e587 commit 34639b8

File tree

4 files changed

+33
-34
lines changed

4 files changed

+33
-34
lines changed

include/gui.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace GUI
1818
class Window : public Gtk::Window
1919
{
2020
public:
21-
Window(const Config& config, const colors_t& colors);
21+
Window(const Config& config, const colors_t& colors, const std::string_view path);
2222
virtual ~Window();
2323

2424
private:

src/gui.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#include <array>
21
#ifdef GUI_MODE
32

43
#define STB_IMAGE_IMPLEMENTATION
54
#include <filesystem>
65
#include <fstream>
6+
#include <array>
77

88
#include "config.hpp"
99
#include "display.hpp"
@@ -64,20 +64,16 @@ static std::vector<std::string> render_with_image(const Config& config, const co
6464
return layouts;
6565
}
6666

67-
Window::Window(const Config& config, const colors_t& colors)
67+
Window::Window(const Config& config, const colors_t& colors, const std::string_view path)
6868
{
6969
set_title("customfetch - Higly customizable and fast neofetch like program");
7070
set_default_size(1000, 600);
71-
72-
std::string path = config.m_display_distro ? Display::detect_distro(config) : config.source_path;
73-
if (!std::filesystem::exists(path) &&
74-
!std::filesystem::exists((path = config.data_dir + "/ascii/linux.txt")))
75-
die("'{}' doesn't exist. Can't load image/text file", path);
71+
set_position(Gtk::WIN_POS_CENTER_ALWAYS);
7672

7773
bool useImage = false;
7874

7975
debug("Window::Window analyzing file");
80-
std::ifstream f(path);
76+
std::ifstream f(path.data());
8177
std::array<unsigned char, 32> buffer;
8278
f.read(reinterpret_cast<char*>(&buffer.at(0)), buffer.size());
8379
if (is_file_image(buffer.data()))
@@ -86,7 +82,7 @@ Window::Window(const Config& config, const colors_t& colors)
8682
// useImage can be either a gif or an image
8783
if (useImage && !config.m_disable_source)
8884
{
89-
Glib::RefPtr<Gdk::PixbufAnimation> img = Gdk::PixbufAnimation::create_from_file(path);
85+
Glib::RefPtr<Gdk::PixbufAnimation> img = Gdk::PixbufAnimation::create_from_file(path.data());
9086
m_img = Gtk::manage(new Gtk::Image(img));
9187
m_img->set(img);
9288
m_img->set_alignment(Gtk::ALIGN_CENTER);

src/main.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -428,11 +428,25 @@ int main (int argc, char *argv[]) {
428428

429429
config.m_display_distro = (config.source_path == "os");
430430

431+
std::string path = config.m_display_distro ? Display::detect_distro(config) : config.source_path;
432+
if (!std::filesystem::exists(path) &&
433+
!std::filesystem::exists((path = config.data_dir + "/ascii/linux.txt")))
434+
die("'{}' doesn't exist. Can't load image/text file", path);
435+
436+
if (!config.ascii_logo_type.empty())
437+
{
438+
const size_t& pos = path.rfind('.');
439+
if (pos != std::string::npos)
440+
path.insert(pos, "_" + config.ascii_logo_type);
441+
else
442+
path += "_" + config.ascii_logo_type;
443+
}
444+
431445
#ifdef GUI_MODE
432446
if (config.gui)
433447
{
434-
auto app = Gtk::Application::create("org.toni.customfetch");
435-
GUI::Window window(config, colors);
448+
const Glib::RefPtr<Gtk::Application>& app = Gtk::Application::create("org.toni.customfetch");
449+
GUI::Window window(config, colors, path);
436450
return app->run(window);
437451
}
438452
#else
@@ -441,16 +455,6 @@ int main (int argc, char *argv[]) {
441455
"Compile customfetch with GUI_MODE=1 or contact your distro to enable it");
442456
#endif
443457

444-
std::string path = config.m_display_distro ? Display::detect_distro(config) : config.source_path;
445-
if (!config.ascii_logo_type.empty())
446-
{
447-
const size_t& pos = path.rfind('.');
448-
if (pos != std::string::npos)
449-
path.insert(pos, "_" + config.ascii_logo_type);
450-
else
451-
path += "_" + config.ascii_logo_type;
452-
}
453-
454458
Display::display(Display::render(config, colors, false, path));
455459

456460
return 0;

src/parse.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static std::array<std::string, 3> get_ansi_color(const std::string_view str, con
5252
col.erase(0, 2);
5353

5454
debug("col = {}", col);
55-
int n = std::stoi(col);
55+
const int n = std::stoi(col);
5656

5757
// unfortunatly you can't do bold and light in pango
5858
if ((n >= 100 && n <= 107) || (n >= 90 && n <= 97))
@@ -63,18 +63,17 @@ static std::array<std::string, 3> get_ansi_color(const std::string_view str, con
6363

6464
// last number
6565
// https://stackoverflow.com/a/5030086
66-
n = col.back() - '0';
6766

68-
switch (n)
67+
switch (col.back())
6968
{
70-
case 0: col = colors.gui_black; break;
71-
case 1: col = colors.gui_red; break;
72-
case 2: col = colors.gui_green; break;
73-
case 3: col = colors.gui_yellow; break;
74-
case 4: col = colors.gui_blue; break;
75-
case 5: col = colors.gui_magenta; break;
76-
case 6: col = colors.gui_cyan; break;
77-
case 7: col = colors.gui_white; break;
69+
case '0': col = colors.gui_black; break;
70+
case '1': col = colors.gui_red; break;
71+
case '2': col = colors.gui_green; break;
72+
case '3': col = colors.gui_yellow; break;
73+
case '4': col = colors.gui_blue; break;
74+
case '5': col = colors.gui_magenta; break;
75+
case '6': col = colors.gui_cyan; break;
76+
case '7': col = colors.gui_white; break;
7877
}
7978

8079
if (col[0] != '#')
@@ -536,7 +535,7 @@ void addValueFromModule(systemInfo_t& sysInfo, const std::string& moduleName, co
536535
{
537536
#define SYSINFO_INSERT(x) sysInfo[moduleName].insert({ moduleValueName, variant(x) })
538537
// yikes, here we go.
539-
auto moduleValue_hash = fnv1a16::hash(moduleValueName);
538+
const auto& moduleValue_hash = fnv1a16::hash(moduleValueName);
540539
static std::vector<std::uint16_t> queried_gpus;
541540
static std::vector<std::string_view> queried_disks;
542541
static std::vector<std::string> queried_themes_names;

0 commit comments

Comments
 (0)