diff options
Diffstat (limited to 'src/btop_theme.cpp')
-rw-r--r-- | src/btop_theme.cpp | 62 |
1 files changed, 31 insertions, 31 deletions
diff --git a/src/btop_theme.cpp b/src/btop_theme.cpp index 0969cf5..8a641fe 100644 --- a/src/btop_theme.cpp +++ b/src/btop_theme.cpp @@ -4,7 +4,7 @@ you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, @@ -150,15 +150,15 @@ namespace Theme { } } - string hex_to_color(string hexa, bool t_to_256, const string& depth) { + string hex_to_color(string hexa, bool t_to_256, const string& depth) { if (hexa.size() > 1) { hexa.erase(0, 1); - for (auto& c : hexa) { - if (not isxdigit(c)) { - Logger::error("Invalid hex value: " + hexa); - return ""; - } - } + for (auto& c : hexa) { + if (not isxdigit(c)) { + Logger::error("Invalid hex value: " + hexa); + return ""; + } + } string pre = Fx::e + (depth == "fg" ? "38" : "48") + ";" + (t_to_256 ? "5;" : "2;"); if (hexa.size() == 2) { @@ -189,7 +189,7 @@ namespace Theme { return ""; } - string dec_to_color(int r, int g, int b, bool t_to_256, const string& depth) { + string dec_to_color(int r, int g, int b, bool t_to_256, const string& depth) { string pre = Fx::e + (depth == "fg" ? "38" : "48") + ";" + (t_to_256 ? "5;" : "2;"); r = std::clamp(r, 0, 255); g = std::clamp(g, 0, 255); @@ -203,17 +203,17 @@ namespace Theme { array<int, 3> hex_to_dec(string hexa) { if (hexa.size() > 1) { hexa.erase(0, 1); - for (auto& c : hexa) { - if (not isxdigit(c)) - return array{-1, -1, -1}; - } + for (auto& c : hexa) { + if (not isxdigit(c)) + return array{-1, -1, -1}; + } if (hexa.size() == 2) { int h_int = stoi(hexa, nullptr, 16); - return array{h_int, h_int, h_int}; + return array{h_int, h_int, h_int}; } else if (hexa.size() == 6) { - return array{ + return array{ stoi(hexa.substr(0, 2), nullptr, 16), stoi(hexa.substr(2, 2), nullptr, 16), stoi(hexa.substr(4, 2), nullptr, 16) @@ -227,7 +227,7 @@ namespace Theme { void generateColors(const unordered_flat_map<string, string>& source) { vector<string> t_rgb; string depth; - bool t_to_256 = Config::getB("lowcolor"); + bool t_to_256 = Config::getB("lowcolor"); colors.clear(); rgbs.clear(); for (const auto& [name, color] : Default_theme) { if (name == "main_bg" and not Config::getB("theme_background")) { @@ -253,11 +253,11 @@ namespace Theme { } else if (not source.at(name).empty()) { t_rgb = ssplit(source.at(name)); - if (t_rgb.size() != 3) { - Logger::error("Invalid RGB decimal value: \"" + source.at(name) + "\""); - } else { + if (t_rgb.size() != 3) { + Logger::error("Invalid RGB decimal value: \"" + source.at(name) + "\""); + } else { colors[name] = dec_to_color(stoi(t_rgb[0]), stoi(t_rgb[1]), stoi(t_rgb[2]), t_to_256, depth); - rgbs[name] = array{stoi(t_rgb[0]), stoi(t_rgb[1]), stoi(t_rgb[2])}; + rgbs[name] = array{stoi(t_rgb[0]), stoi(t_rgb[1]), stoi(t_rgb[2])}; } } @@ -290,16 +290,16 @@ namespace Theme { //* Generate color gradients from two or three colors, 101 values indexed 0-100 void generateGradients() { gradients.clear(); - bool t_to_256 = Config::getB("lowcolor"); + bool t_to_256 = Config::getB("lowcolor"); //? Insert values for processes greyscale gradient and processes color gradient - rgbs.insert({ - { "proc_start", rgbs["main_fg"] }, - { "proc_mid", {-1, -1, -1} }, - { "proc_end", rgbs["inactive_fg"] }, - { "proc_color_start", rgbs["inactive_fg"] }, - { "proc_color_mid", {-1, -1, -1} }, - { "proc_color_end", rgbs["process_start"] }, + rgbs.insert({ + { "proc_start", rgbs["main_fg"] }, + { "proc_mid", {-1, -1, -1} }, + { "proc_end", rgbs["inactive_fg"] }, + { "proc_color_start", rgbs["inactive_fg"] }, + { "proc_color_mid", {-1, -1, -1} }, + { "proc_color_end", rgbs["process_start"] }, }); for (const auto& [name, source_arr] : rgbs) { @@ -322,10 +322,10 @@ namespace Theme { //? Split iteration in two passes of 50 + 51 instead of one pass of 101 if gradient has start, mid and end values defined int current_range = (input_colors[1][0] >= 0) ? 50 : 100; - for (int rgb : iota(0, 3)) { + for (int rgb : iota(0, 3)) { int start = 0, offset = 0; int end = (current_range == 50) ? 1 : 2; - for (int i : iota(0, 101)) { + for (int i : iota(0, 101)) { output_colors[i][rgb] = input_colors[start][rgb] + (i - offset) * (input_colors[end][rgb] - input_colors[start][rgb]) / current_range; //? Switch source arrays from start->mid to mid->end at 50 passes if mid is defined @@ -360,7 +360,7 @@ namespace Theme { const string base_name = rtrim(c.first, "_start"); string section = "_start"; int split = colors.at(base_name + "_mid").empty() ? 50 : 33; - for (int i : iota(0, 101)) { + for (int i : iota(0, 101)) { gradients[base_name][i] = colors.at(base_name + section); if (i == split) { section = (split == 33) ? "_mid" : "_end"; |