Skip to content

Commit

Permalink
parse: add new color option modes
Browse files Browse the repository at this point in the history
  • Loading branch information
Toni500github committed Oct 1, 2024
1 parent 09a6a31 commit eb6fdb4
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 20 deletions.
19 changes: 11 additions & 8 deletions cufetch.1
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,17 @@ layout = [
The colors can be predefined such as: \fIblack\fR, \fIred\fR, \fIgreen\fR, \fIblue\fR, \fIcyan\fR, \fIyellow\fR, \fImagenta\fR, \fIwhite\fR and they can be configured in the config file.
They can have hexcodes colors (e.g "#5522dd").
You can apply special effects to colors by using the following symbols before the '#' in hex codes:
\fBTerminal and GUI\fR \fBGUI Only\fR
* \fBb\fR for background color. * \fBo\fR for overline
* \fBu\fR to underline the text * \fBa(value)\fR for fg alpha (either a plain integer between 1 and 65536 or a percentage value like `50%`)
* \fB!\fR for bold text * \fBL(value)\fR to underline with a style (`none`, `single`, `double`, `low`, `error`)
* \fBi\fR for italic text * \fBU(value)\fR for choosing the underline color (hexcode without #)
* \fBB(value)\fR for bg color text (hexcode without #)
\fBTerminal Only\fR
* \fBl\fR for blinking text

\fBTerminal and GUI\fR \fBGUI Only\fR
* \fBb\fR for background color. * \fBo\fR for overline
* \fBu\fR to underline the text * \fBa(value)\fR for fg alpha (either a plain integer between 1 and 65536 or a percentage value like `50%`)
* \fB!\fR for bold text * \fBL(value)\fR to underline with a style (`none`, `single`, `double`, `low`, `error`)
* \fBi\fR for italic text * \fBU(value)\fR for choosing the underline color (hexcode without #)
* \fBB(value)\fR for bg color text (hexcode without #)
\fBTerminal Only\fR * \fBS(value)\fR for strikethrough color (same value as above)
* \fBl\fR for blinking text * \fBO(value)\fR for overline color (same value as above)
* \fBA(value)\fR for bg alpha (same value as a(value))
* \fBw(value)\fR for specify font weight (`ultralight`, `light`, `normal`, `bold`, `ultrabold`, `heavy`, or a numeric weight)
.fi
.PP
Alternatively, ANSI escape codes can be used, e.g "\\e[1;31m" and "\\e[38;5;160m".
Expand Down
13 changes: 8 additions & 5 deletions include/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,19 @@ inline constexpr std::string_view AUTOCONFIG = R"#([config]
#
# They can have hexcodes colors (e.g "#5522dd").
# You can apply special effects to colors by using the following symbols before the '#' in hex codes:
# Terminal and GUI GUI Only
#
# Terminal and GUI GUI Only
# * b - for background color. * o - for overline
# * u - to underline the text * a(value) - for fg alpha (either a plain integer between 1 and 65536 or a percentage value like `50%`)
# * ! - for bold text * L(value) - to underline the text with a style (`none`, `single`, `double`, `low`, `error`)
# * i - for italic text * U(value) - for choosing the underline color (hexcode without #)
# * B(value) - for bg color text (hexcode without #)
# Terminal Only
# * l - for blinking text
# * s - for strikethrough text * B(value) - for bg color text (same value as above)
# * S(value) - for strikethrough color (same value as above)
# Terminal Only * O(value) - for overline color (same value as above)
# * l - for blinking text * A(value) - for bg alpha (same value as a(value))
# * w(value) - for specify font weight (`ultralight`, `light`, `normal`, `bold`, `ultrabold`, `heavy`, or a numeric weight)
#
# Alternatively, ANSI escape codes can be used, e.g ${\e[1;32m} or ${\e[0;34m}.
# Alternatively, ANSI escape codes can be used, e.g ${\e[1;32m} or ${\e[38;2;34;255;11m}.
#
# To reset colors, use ${0} for a normal reset or ${1} for a bold reset.
#
Expand Down
50 changes: 43 additions & 7 deletions src/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ static std::string convert_ansi_escape_rgb(const std::string_view noesc_str)
return ss.str();
}

/*
static std::string convert_hex_ansi_escape(const std::string_view hexstr, const bool bg = false)
{
fmt::rgb rgb(hexStringToColor(hexstr));
fmt::detail::ansi_color_escape<char> ansi(rgb, bg ? "\x1b[48;2;" : "\x1b[38;2;");
return ansi.begin();
}
*/
static std::string get_and_color_percentage(const float& n1, const float& n2, systemInfo_t& systemInfo,
const Config& config, const colors_t& colors, const bool parsingLayout,
const bool invert = false)
Expand Down Expand Up @@ -385,7 +393,7 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s
}
break;

case '}': // please pay very attention when reading this really long code
case '}': // please pay close attention when reading this really long code

// if at end there a '$', it will make the end output "$</span>" and so it will confuse
// addValueFromModule() and so let's make it "$ </span>". this is geniunenly stupid
Expand Down Expand Up @@ -500,12 +508,19 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s
tagfmt += "style='italic' "; break;
case 'o':
tagfmt += "overline='single' "; break;

case 's':
tagfmt += "strikethrough='true' "; break;

case 'a':
argmode_pos = i;
i += append_argmode("fgalpha='", "fgalpha");
break;

case 'A':
argmode_pos = i;
i += append_argmode("bgalpha='", "bgalpha");
break;

case 'L':
argmode_pos = i;
i += append_argmode("underline='", "underline option");
Expand All @@ -520,6 +535,21 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s
argmode_pos = i;
i += append_argmode("bgcolor='#", "bgcolor");
break;

case 'w':
argmode_pos = i;
i += append_argmode("weight='", "font weight style");
break;

case 'O':
argmode_pos = i;
i += append_argmode("overline_color='#", "overline color");
break;

case 'S':
argmode_pos = i;
i += append_argmode("strikethrough_color='#", "color of strikethrough line");
break;
}
}

Expand Down Expand Up @@ -564,7 +594,7 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s

firstrun_noclr = false;
}

// if (!config.gui)
else
{
switch (fnv1a16::hash(command))
Expand All @@ -589,7 +619,7 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s

fmt::text_style style;

const auto& skip_gui_argmode = [&](size_t index) -> size_t
const auto& skip_gui_argmode = [&opt_clr](const size_t index) -> size_t
{
if (opt_clr.at(index + 1) == '(')
{
Expand Down Expand Up @@ -619,12 +649,18 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s
append_styles(style, fmt::emphasis::italic); break;
case 'l':
append_styles(style, fmt::emphasis::blink); break;
case 's':
append_styles(style, fmt::emphasis::strikethrough); break;

case 'a':
case 'U':
case 'B':
case 'S':
case 'a':
case 'w':
case 'O':
case 'A':
case 'L':
case 'U':
i += skip_gui_argmode(i);
i += skip_gui_argmode(i); break;
}
}

Expand Down

0 comments on commit eb6fdb4

Please sign in to comment.