Skip to content

Commit

Permalink
config and args: add logo-position
Browse files Browse the repository at this point in the history
  • Loading branch information
Toni500github committed Oct 27, 2024
1 parent 481332c commit d171c33
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 12 deletions.
3 changes: 3 additions & 0 deletions cufetch.1
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ Will only print the logo (if not disabled), along side the parsed OS and CPU
\fB\-g\fR, \fB\-\-gui\fR
Use GUI mode instead of priting in the terminal (use \fB\-V\fR to check if it's enabled)
.TP
\fB\-p\fR, \fB\-\-logo-position\fR <value>
Position of the logo ("top" or "left")
.TP
\fB\-o\fR, \fB\-\-offset\fR <num>
Offset between the ascii art and the system infos
.TP
Expand Down
11 changes: 8 additions & 3 deletions include/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class Config
std::string builtin_title_sep;
std::string gui_bg_image;
std::string ascii_logo_type;
std::string logo_position;
std::uint16_t offset = 0;
std::uint16_t logo_padding_left = 0;
std::uint16_t logo_padding_top = 0;
Expand Down Expand Up @@ -228,9 +229,9 @@ sep-reset = ":"
# false = before ("test ${0}-> ")
sep-reset-after = false
# Warn against tradeoffs between slower queries for availability
# e.g. falling back to gsettings when we can't find the config file for GTK
slow-query-warnings = false
# Where the logo should be displayed.
# Values: "top" or "left"
logo-position = "left"
# Offset between the ascii art and the layout
offset = 5
Expand Down Expand Up @@ -279,6 +280,10 @@ percentage-colors = ["green", "yellow", "red"]
# Enable/Disable if you want this
wrap-lines = true
# Warn against tradeoffs between slower queries for availability
# e.g. falling back to gsettings when we can't find the config file for GTK
slow-query-warnings = false
# $<os.uptime> config
[os.uptime]
# how to display the name of the uptime
Expand Down
5 changes: 3 additions & 2 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,18 @@ void Config::loadConfigFile(const std::string_view filename, colors_t& colors)
this->sep_reset_after = getValue<bool>("config.sep-reset-after", false);
this->use_SI_unit = getValue<bool>("config.use-SI-byte-unit", false);
this->wrap_lines = getValue<bool>("config.wrap-lines", true);
this->sep_reset = getValue<std::string>("config.sep-reset", ":");
this->offset = getValue<std::uint16_t>("config.offset", 5);
this->logo_padding_left = getValue<std::uint16_t>("config.logo-padding-left", 0);
this->layout_padding_top = getValue<std::uint16_t>("config.layout-padding-top", 0);
this->logo_padding_top = getValue<std::uint16_t>("config.logo-padding-top", 0);
this->sep_reset = getValue<std::string>("config.sep-reset", ":");
this->ascii_logo_type = getValue<std::string>("config.ascii-logo-type", "");
this->source_path = getValue<std::string>("config.source-path", "os");
this->logo_position = getValue<std::string>("config.logo-position", "left");
this->data_dir = getValue<std::string>("config.data-dir", get_data_dir("customfetch"));
this->builtin_title_sep = getValue<std::string>("config.title-sep", "-");
this->font = getValue<std::string>("gui.font", "Liberation Mono Normal 12");
this->gui_bg_image = getValue<std::string>("gui.bg-image", "disable");
this->builtin_title_sep = getValue<std::string>("config.title-sep", "-");

this->uptime_d_fmt = getValue<std::string>("os.uptime.days", " days");
this->uptime_h_fmt = getValue<std::string>("os.uptime.hours", " hours");
Expand Down
27 changes: 22 additions & 5 deletions src/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static std::vector<std::string> render_with_image(systemInfo_t& systemInfo, std:
const size_t height = image_height / font_height;

if (config.m_image_backend == "kitty")
taur_exec({ "kitty", "+kitten", "icat", "--align", "left", "--place", fmt::format("{}x{}@0x0", width, height),
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 });
Expand All @@ -91,9 +91,17 @@ static std::vector<std::string> render_with_image(systemInfo_t& systemInfo, std:
"Please currently use the GUI mode for rendering the image/gif (use -h for more details)",
config.m_image_backend);

for (size_t i = 0; i < layout.size(); i++)
if (config.logo_position == "top")
{
for (size_t _ = 0; _ < height + config.layout_padding_top; ++_)
layout.insert(layout.begin(), "");

return layout;
}

for (size_t i = 0; i < layout.size(); ++i)
// took math from neofetch in get_term_size() and get_image_size(). seems to work nice
for (size_t _ = 0; _ < width + config.offset; _++)
for (size_t _ = 0; _ < width + config.offset; ++_)
layout.at(i).insert(0, " ");

return layout;
Expand Down Expand Up @@ -285,14 +293,23 @@ std::vector<std::string> Display::render(const Config& config, const colors_t& c

std::string _;
parse_args.parsingLayout = true;
for (std::string& layout : layout)
layout = parse(layout, _, parse_args);
for (std::string& line : layout)
{
line = parse(line, _, parse_args);
line.insert(0, NOCOLOR);
}

// erase each element for each instance of MAGIC_LINE
layout.erase(std::remove_if(layout.begin(), layout.end(),
[](const std::string_view str) { return str.find(MAGIC_LINE) != std::string::npos; }),
layout.end());

if (config.logo_position == "top")
{
Display::display(asciiArt);
return layout;
}

size_t i;
for (i = 0; i < layout.size(); i++)
{
Expand Down
8 changes: 6 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ A command-line system information tool (or neofetch like program), which its foc
Example: `cufetch -m "${{auto}}OS: $<os.name>" -m "${{auto}}CPU: $<cpu.cpu>"`
Will only print the logo (if not disabled), along side the parsed OS and CPU
-g, --gui Use GUI mode instead of priting in the terminal (use -V to check if it was enabled)
-g, --gui Use GUI mode instead of priting in the terminal (use --version to check if it was enabled)
-p, --logo-position <value> Position of the logo ("top" or "left")
-o, --offset <num> Offset between the ascii art and the layout
-l. --list-modules Print the list of the modules and its members
-h, --help Print this help menu
Expand Down Expand Up @@ -293,7 +294,7 @@ static bool parseargs(int argc, char* argv[], Config& config, const std::string_
int opt = 0;
int option_index = 0;
opterr = 1; // re-enable since before we disabled for "invalid option" error
const char *optstring = "-VhnLlgN::a::f:o:C:i:d:D:s:m:";
const char *optstring = "-VhnLlgN::a::f:o:C:i:d:D:p:s:m:";
static const struct option opts[] = {
{"version", no_argument, 0, 'V'},
{"help", no_argument, 0, 'h'},
Expand All @@ -307,6 +308,7 @@ static bool parseargs(int argc, char* argv[], Config& config, const std::string_
{"font", required_argument, 0, 'f'},
{"config", required_argument, 0, 'C'},
{"layout-line", required_argument, 0, 'm'},
{"logo-position", required_argument, 0, 'p'},
{"data-dir", required_argument, 0, 'D'},
{"distro", required_argument, 0, 'd'},
{"source-path", required_argument, 0, 's'},
Expand Down Expand Up @@ -361,6 +363,8 @@ static bool parseargs(int argc, char* argv[], Config& config, const std::string_
config.m_custom_distro = str_tolower(optarg); break;
case 'm':
config.m_args_layout.push_back(optarg); break;
case 'p':
config.logo_position = optarg; break;
case 's':
config.source_path = optarg; break;
case 'i':
Expand Down

0 comments on commit d171c33

Please sign in to comment.