Skip to content

Commit

Permalink
config: add NO_COLOR support + args: make --no-color optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Toni500github committed Oct 27, 2024
1 parent 17ae82f commit f3d0359
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
4 changes: 3 additions & 1 deletion cufetch.1
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ e.g "the number 50 is \\< than 100 \\& 98"
\fB\-n\fR, \fB\-\-no\-display\fR
Do not display the logo
.TP
\fB\-N\fR, \fB\-\-no\-color\fR
\fB\-N\fR, \fB\-\-no\-color\fR [<0,1>]
Disable (0) or Enable (1)
.br
Do not output and parse colors. Useful for stdout or pipe operations
.TP
\fB\-s\fR, \fB\-\-source\-path\fR <path>
Expand Down
5 changes: 5 additions & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "config.hpp"

#include <cstdlib>
#include <filesystem>
#include <fstream>
#include <iostream>
Expand Down Expand Up @@ -95,6 +96,10 @@ void Config::loadConfigFile(const std::string_view filename, colors_t& colors)

for (const std::string& str : this->getValueArrayStr("config.alias-colors", {}))
this->addAliasColors(str);

const char *no_color = std::getenv("NO_COLOR");
if (no_color != NULL && no_color[0] != '\0')
this->m_disable_colors = true;
}

// Config::getValue() but don't want to specify the template
Expand Down
20 changes: 12 additions & 8 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static void help(bool invalid_opt = false)
A command-line system information tool (or neofetch like program), which its focus point is customizability and perfomance
-n, --no-display Do not display the logo
-N, --no-color Do not output and parse colors. Useful for stdout or pipe operations
-N, --no-color [<0,1>] Do not output and parse colors. Useful for stdout or pipe operations (Disable (0) or Enable (1))
-s, --source-path <path> Path to the ascii art or image file to display
-C, --config <path> Path to the config file to use
-a, --ascii-logo-type [<name>]
Expand Down Expand Up @@ -293,15 +293,15 @@ 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 = "-VhnNLlga::f:o:C:i:d:D:s:m:";
const char *optstring = "-VhnLlgN::a::f:o:C:i:d:D:s:m:";
static const struct option opts[] = {
{"version", no_argument, 0, 'V'},
{"help", no_argument, 0, 'h'},
{"no-display", no_argument, 0, 'n'},
{"no-color", no_argument, 0, 'N'},
{"list-modules", no_argument, 0, 'l'},
{"logo-only", no_argument, 0, 'L'},
{"gui", no_argument, 0, 'g'},
{"no-color", optional_argument, 0, 'N'},
{"ascii-logo-type", optional_argument, 0, 'a'},
{"offset", required_argument, 0, 'o'},
{"font", required_argument, 0, 'f'},
Expand Down Expand Up @@ -352,7 +352,7 @@ static bool parseargs(int argc, char* argv[], Config& config, const std::string_
case 'g':
config.gui = true; break;
case 'o':
config.offset = std::atoi(optarg); break;
config.offset = std::stoi(optarg); break;
case 'C': // we have already did it in parse_config_path()
break;
case 'D':
Expand All @@ -366,7 +366,11 @@ static bool parseargs(int argc, char* argv[], Config& config, const std::string_
case 'i':
config.m_image_backend = optarg; break;
case 'N':
config.m_disable_colors = true; break;
if (OPTIONAL_ARGUMENT_IS_PRESENT)
config.m_disable_colors = static_cast<bool>(std::stoi(optarg));
else
config.m_disable_colors = true;
break;
case 'a':
if (OPTIONAL_ARGUMENT_IS_PRESENT)
config.ascii_logo_type = optarg;
Expand All @@ -375,13 +379,13 @@ static bool parseargs(int argc, char* argv[], Config& config, const std::string_
break;

case "logo-padding-top"_fnv1a16:
config.logo_padding_top = std::atoi(optarg); break;
config.logo_padding_top = std::stoi(optarg); break;

case "logo-padding-left"_fnv1a16:
config.logo_padding_left = std::atoi(optarg); break;
config.logo_padding_left = std::stoi(optarg); break;

case "layout-padding-top"_fnv1a16:
config.layout_padding_top = std::atoi(optarg); break;
config.layout_padding_top = std::stoi(optarg); break;

case "bg-image"_fnv1a16:
config.gui_bg_image = optarg; break;
Expand Down

0 comments on commit f3d0359

Please sign in to comment.