Skip to content

Commit 49a994c

Browse files
committed
misc: make the naming conv more consistent
snake_case for struct members, CamelCase for classes
1 parent 2f2ec30 commit 49a994c

File tree

13 files changed

+86
-113
lines changed

13 files changed

+86
-113
lines changed

docs/build-plugin.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,8 @@ std::string test_submod_func(const callbackInfo_t* cb) {
8282
* @param modules_info The modules fetched infos
8383
* @param config The config instance
8484
* @param pure_output The output of the string but without tags
85-
* @param layout The layout of customfetch
86-
* @param tmp_layout The temponary layout to be used for multiple-line modules
87-
* @param no_more_reset uhh let me see
85+
* @param layout The layout array of customfetch
86+
* @param tmp_layout A temponary layout to be used for multiple-line modules
8887
* @param parsing_layout Are we parsing the layout or the ASCII art logo?
8988
*/
9089
struct EXPORT parse_args_t

include/libcufetch/common.hh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ void die(const std::string_view fmt, Args&&... args) noexcept
7373
}
7474

7575
// std::format function arguments
76-
// Print to stdout a debug msg with header '[DEBUG]' in hot-pink color
77-
// only if debug_print is set (do not modify it).
76+
// Print to stdout a debug msg with header '[DEBUG]' in pink color
77+
// only if customfetch is run with --debug=1
7878
template <typename... Args>
7979
void debug(const std::string_view fmt, Args&&... args) noexcept
8080
{
8181
if (debug_print)
82-
fmt::print(stdout, "\033[1;38;2;255;105;180m[DEBUG]:\033[0m {}\n",
82+
fmt::print(stdout, "\033[1;35m[DEBUG]:\033[0m {}\n",
8383
fmt::format(fmt::runtime(fmt), std::forward<Args>(args)...));
8484
}
8585

include/libcufetch/cufetch.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct moduleArgs_t
4646
// Struct used in modules callback functions (handler in module_t)
4747
struct callbackInfo_t
4848
{
49-
const moduleArgs_t* moduleArgs;
49+
const moduleArgs_t* module_args;
5050
parse_args_t& parse_args;
5151
};
5252

include/libcufetch/parse.hh

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -45,47 +45,31 @@ struct module_t;
4545
using moduleMap_t = std::unordered_map<std::string, const module_t&>;
4646

4747
/* Context struct used when parsing tags in strings.
48-
* @param input The string to parse
49-
* @param modulesInfo The system infos
50-
* @param pureOutput The output of the string but without tags
51-
* @param layout The layout of customfetch
52-
* @param tmp_layout The temponary layout to be used for multiple-line modules
53-
* @param config The config
54-
* @param no_more_reset If we are recursively parsing, e.g we are inside tags
48+
* @param modules_info The modules fetched infos
49+
* @param config The config instance
50+
* @param pure_output The output of the string but without tags
51+
* @param layout The layout array of customfetch
52+
* @param tmp_layout A temponary layout to be used for multiple-line modules
53+
* @param parsing_layout Are we parsing the layout or the ASCII art logo?
5554
*/
5655
struct EXPORT parse_args_t
5756
{
58-
const moduleMap_t& modulesInfo;
59-
std::string& pureOutput;
57+
const moduleMap_t& modules_info;
58+
const ConfigBase& config;
59+
std::string& pure_output;
6060
std::vector<std::string>& layout;
6161
std::vector<std::string>& tmp_layout;
62-
const ConfigBase& config;
63-
bool parsingLayout;
64-
bool firstrun_clr = true;
62+
bool parsing_layout;
6563
bool no_more_reset = false;
64+
bool firstrun_clr = true; // don't use it. Internal "flag"
6665
};
6766

68-
/* Parse input, in-place, with data from modulesInfo.
69-
* Documentation on formatting is in the flag -w or the customfetch.1 manual.
70-
* @param input The string to parse
71-
* @param modulesInfo The system infos
72-
* @param pureOutput The output of the string but without tags
73-
* @param layout The layout of customfetch
74-
* @param tmp_layout The temponary layout to be used for multiple-line modules
75-
* @param config The config
76-
* @param parsingLayout If we are parsing layout or not
77-
* @param no_more_reset If we are recursively parsing, e.g we are inside tags
78-
*/
79-
std::string parse(std::string input, const moduleMap_t& modulesInfo, std::string& pureOutput,
80-
std::vector<std::string>& layout, std::vector<std::string>& tmp_layout, const ConfigBase& config,
81-
const bool parsingLayout, bool& no_more_reset);
82-
83-
/* Parse input, in-place, with data from modulesInfo.
67+
/* Parse input, in-place, with data from modules_info.
8468
* Documentation on formatting is in the flag -w or the customfetch.1 manual.
8569
* @param input The string to parse
8670
* @param parse_args The parse arguments to be used (parse_args_t)
8771
*/
88-
APICALL EXPORT std::string parse(const std::string& input, parse_args_t& parse_args);
72+
APICALL EXPORT std::string parse(std::string input, parse_args_t& parse_args);
8973

9074
/*
9175
* Create a colored percentage from parse()

libcufetch/parse.cc

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
class Parser
4949
{
5050
public:
51-
Parser(const std::string_view src, std::string& pureOutput) : src{ src }, pureOutput{ pureOutput } {}
51+
Parser(const std::string_view src, std::string& pure_output) : src{ src }, pure_output{ pure_output } {}
5252

5353
bool try_read(const char c)
5454
{
@@ -64,13 +64,13 @@ class Parser
6464
return false;
6565
}
6666

67-
char read_char(const bool add_pureOutput = false)
67+
char read_char(const bool add_pure_output = false)
6868
{
6969
if (is_eof())
7070
return 0;
7171

72-
if (add_pureOutput)
73-
pureOutput += src[pos];
72+
if (add_pure_output)
73+
pure_output += src[pos];
7474

7575
++pos;
7676
return src[pos - 1];
@@ -83,13 +83,13 @@ class Parser
8383
{ pos -= std::min(pos, count); }
8484

8585
const std::string_view src;
86-
std::string& pureOutput;
86+
std::string& pure_output;
8787
size_t dollar_pos = 0;
8888
size_t pos = 0;
8989
};
9090

9191
// useless useful tmp string for parse() without using the original
92-
// pureOutput
92+
// pure_output
9393
std::string _;
9494

9595
#if GUI_APP
@@ -184,14 +184,8 @@ static std::string convert_ansi_escape_rgb(const std::string_view noesc_str)
184184

185185
EXPORT std::string parse(const std::string& input, std::string& _, parse_args_t& parse_args)
186186
{
187-
return parse(input, parse_args.modulesInfo, _, parse_args.layout, parse_args.tmp_layout, parse_args.config,
188-
parse_args.parsingLayout, parse_args.no_more_reset);
189-
}
190-
191-
EXPORT std::string parse(const std::string& input, parse_args_t& parse_args)
192-
{
193-
return parse(input, parse_args.modulesInfo, parse_args.pureOutput, parse_args.layout, parse_args.tmp_layout,
194-
parse_args.config, parse_args.parsingLayout, parse_args.no_more_reset);
187+
parse_args.pure_output = _;
188+
return parse(input, parse_args);
195189
}
196190

197191
EXPORT std::string get_and_color_percentage(const float n1, const float n2, parse_args_t& parse_args, const bool invert)
@@ -343,7 +337,7 @@ std::string getInfoFromName(parse_args_t& parse_args, const std::string& moduleN
343337
debug("name = {}", name);
344338

345339
std::string result = "(unknown/invalid module)";
346-
if (const auto& it = parse_args.modulesInfo.find(name); it != parse_args.modulesInfo.end())
340+
if (const auto& it = parse_args.modules_info.find(name); it != parse_args.modules_info.end())
347341
{
348342
struct callbackInfo_t callbackInfo = { moduleArgs, parse_args };
349343

@@ -399,8 +393,8 @@ std::optional<std::string> parse_command_tag(Parser& parser, parse_args_t& parse
399393

400394
std::string cmd_output;
401395
TinyProcessLib::Process proc(command, "", [&](const char* bytes, size_t n) { cmd_output.assign(bytes, n); });
402-
if (!parse_args.parsingLayout && !removetag && parser.dollar_pos != std::string::npos)
403-
parse_args.pureOutput.replace(parser.dollar_pos, command.length() + "$()"_len, cmd_output);
396+
if (!parse_args.parsing_layout && !removetag && parser.dollar_pos != std::string::npos)
397+
parse_args.pure_output.replace(parser.dollar_pos, command.length() + "$()"_len, cmd_output);
404398

405399
if (!cmd_output.empty() && cmd_output.back() == '\n')
406400
cmd_output.pop_back();
@@ -431,7 +425,7 @@ std::optional<std::string> parse_color_tag(Parser& parser, parse_args_t& parse_a
431425
if (config.getValue("intern.args.disable-colors", false))
432426
{
433427
if (parser.dollar_pos != std::string::npos)
434-
parse_args.pureOutput.erase(parser.dollar_pos, taglen);
428+
parse_args.pure_output.erase(parser.dollar_pos, taglen);
435429
return "";
436430
}
437431

@@ -631,8 +625,8 @@ std::optional<std::string> parse_color_tag(Parser& parser, parse_args_t& parse_a
631625
else
632626
{
633627
error(_("PARSER: failed to parse line with color '{}'"), str_clr);
634-
if (!parse_args.parsingLayout && parser.dollar_pos != std::string::npos)
635-
parse_args.pureOutput.erase(parser.dollar_pos, taglen);
628+
if (!parse_args.parsing_layout && parser.dollar_pos != std::string::npos)
629+
parse_args.pure_output.erase(parser.dollar_pos, taglen);
636630
return output;
637631
}
638632

@@ -725,18 +719,18 @@ std::optional<std::string> parse_color_tag(Parser& parser, parse_args_t& parse_a
725719
else
726720
{
727721
error(_("PARSER: failed to parse line with color '{}'"), str_clr);
728-
if (!parse_args.parsingLayout && parser.dollar_pos != std::string::npos)
729-
parse_args.pureOutput.erase(parser.dollar_pos, taglen);
722+
if (!parse_args.parsing_layout && parser.dollar_pos != std::string::npos)
723+
parse_args.pure_output.erase(parser.dollar_pos, taglen);
730724
return output;
731725
}
732726
#endif
733727

734-
if (!parse_args.parsingLayout && std::find(auto_colors.begin(), auto_colors.end(), color) == auto_colors.end())
728+
if (!parse_args.parsing_layout && std::find(auto_colors.begin(), auto_colors.end(), color) == auto_colors.end())
735729
auto_colors.push_back(color);
736730
}
737731

738-
if (!parse_args.parsingLayout && parser.dollar_pos != std::string::npos)
739-
parse_args.pureOutput.erase(parser.dollar_pos, taglen);
732+
if (!parse_args.parsing_layout && parser.dollar_pos != std::string::npos)
733+
parse_args.pure_output.erase(parser.dollar_pos, taglen);
740734

741735
parse_args.firstrun_clr = false;
742736

@@ -756,7 +750,7 @@ std::optional<std::string> parse_info_tag(Parser& parser, parse_args_t& parse_ar
756750
const std::string& info = getInfoFromName(parse_args, module);
757751

758752
if (parser.dollar_pos != std::string::npos)
759-
parse_args.pureOutput.replace(parser.dollar_pos, module.length() + "$<>"_len, info);
753+
parse_args.pure_output.replace(parser.dollar_pos, module.length() + "$<>"_len, info);
760754
return info;
761755
}
762756

@@ -788,7 +782,7 @@ std::optional<std::string> parse_tags(Parser& parser, parse_args_t& parse_args,
788782
return {};
789783

790784
if (parser.dollar_pos != std::string::npos)
791-
parser.dollar_pos = parser.pureOutput.find('$', parser.dollar_pos);
785+
parser.dollar_pos = parser.pure_output.find('$', parser.dollar_pos);
792786

793787
if (const auto& color_tag = parse_color_tag(parser, parse_args, evaluate))
794788
return color_tag;
@@ -838,31 +832,27 @@ std::string parse(Parser& parser, parse_args_t& parse_args, const bool evaluate,
838832
return result;
839833
}
840834

841-
EXPORT std::string parse(std::string input, const moduleMap_t& modulesInfo, std::string& pureOutput,
842-
std::vector<std::string>& layout, std::vector<std::string>& tmp_layout,
843-
const ConfigBase& config, const bool parsingLayout, bool& no_more_reset)
835+
EXPORT std::string parse(std::string input, parse_args_t& parse_args)
844836
{
845-
static const std::string& sep_reset = config.getValue<std::string>("config.sep-reset", ":");
846-
if (!sep_reset.empty() && parsingLayout && !no_more_reset)
837+
static const std::string& sep_reset = parse_args.config.getValue<std::string>("config.sep-reset", ":");
838+
if (!sep_reset.empty() && parse_args.parsing_layout && !parse_args.no_more_reset)
847839
{
848-
if (config.getValue("config.sep-reset-after", false))
840+
if (parse_args.config.getValue("config.sep-reset-after", false))
849841
replace_str(input, sep_reset, sep_reset + "${0}");
850842
else
851843
replace_str(input, sep_reset, "${0}" + sep_reset);
852844

853-
no_more_reset = true;
845+
parse_args.no_more_reset = true;
854846
}
855847

856-
parse_args_t parse_args{ modulesInfo, pureOutput, layout, tmp_layout, config, parsingLayout, true, no_more_reset };
857-
Parser parser{ input, pureOutput };
858-
848+
Parser parser{ input, parse_args.pure_output };
859849
std::string ret{ parse(parser, parse_args) };
860850

861851
#if GUI_APP
862852
if (!parse_args.firstrun_clr)
863853
ret += "</span>";
864854

865-
replace_str(parse_args.pureOutput, "&nbsp;", " ");
855+
replace_str(parse_args.pure_output, "&nbsp;", " ");
866856

867857
// escape pango markup
868858
// https://gitlab.gnome.org/GNOME/glib/-/blob/main/glib/gmarkup.c#L2150

0 commit comments

Comments
 (0)