Skip to content

Commit

Permalink
android app (misc): auto clean colors everytime we finished rendering…
Browse files Browse the repository at this point in the history
… the text

fix for everytime we add new widgets and the ${auto} colors are the same from the previous widget

* fix logo-position=top + modify example_appwidget_preview.png
  • Loading branch information
Toni500github committed Dec 6, 2024
1 parent 0f8d8bf commit 46877f3
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class customfetchConfigureActivity : Activity() {
appWidgetText.setText(loadTitlePref(this@customfetchConfigureActivity, appWidgetId))
argsHelp.text = mainAndroid("customfetch --help")

showModulesList.setOnCheckedChangeListener(CompoundButton.OnCheckedChangeListener { buttonView, isChecked ->
showModulesList.setOnCheckedChangeListener(CompoundButton.OnCheckedChangeListener { _, isChecked ->
if (isChecked)
argsHelp.text = mainAndroid("customfetch -l")
else
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions include/parse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,6 @@ void append_styles(fmt::text_style& current_style, Styles&&... styles)
current_style |= (styles | ...);
}

inline std::vector<std::string> auto_colors;

#endif
4 changes: 2 additions & 2 deletions include/query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ class User
public:
struct User_t
{
std::string shell_path{ UNKNOWN };
std::string shell_name{ UNKNOWN };
std::string shell_path{ MAGIC_LINE };
std::string shell_name{ MAGIC_LINE };
std::string shell_version{ UNKNOWN };
std::string wm_name{ MAGIC_LINE };
std::string wm_version{ UNKNOWN };
Expand Down
9 changes: 8 additions & 1 deletion src/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ std::vector<std::string> Display::render(const Config& config, const colors_t& c
if (!config.gui && !config.m_disable_colors)
line.insert(0, NOCOLOR);
}

auto_colors.clear();

// erase each element for each instance of MAGIC_LINE
layout.erase(std::remove_if(layout.begin(), layout.end(),
Expand All @@ -336,7 +338,12 @@ std::vector<std::string> Display::render(const Config& config, const colors_t& c

if (config.logo_position == "top")
{
#if ANDROID_APP
if (!asciiArt.empty())
layout.insert(layout.begin(), asciiArt.begin(), asciiArt.end());
#else
Display::display(asciiArt);
#endif
return layout;
}

Expand Down Expand Up @@ -374,7 +381,7 @@ std::vector<std::string> Display::render(const Config& config, const colors_t& c
line.reserve(config.logo_padding_left + asciiArt.at(i).length());

for (size_t j = 0; j < config.logo_padding_left; j++)
line += ' ';
line += space;

line += asciiArt.at(i);

Expand Down
2 changes: 2 additions & 0 deletions src/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ Window::Window(const Config& config, const colors_t& colors, const std::string_v
m_label.set_markup(fmt::format("{}", fmt::join(Display::render(config, colors, true, path), "\n")));
}

auto_colors.clear();

if (config.gui_bg_image != "disable")
{
if (!std::filesystem::exists(config.gui_bg_image))
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Read the manual "customfetch.1" or the autogenerated config file for more infos
)");

RETURN_OR_PRINT(help.data());
std::exit(EXIT_SUCCESS);
std::exit(invalid_opt);
}

static STRING_IF_ANDROID_APP_ELSE(void) modules_list()
Expand Down
4 changes: 1 addition & 3 deletions src/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,6 @@ std::optional<std::string> parse_color_tag(Parser& parser, parse_args_t& parse_a

if (!evaluate)
return {};

static std::vector<std::string> auto_colors;

std::string output;
const Config& config = parse_args.config;
Expand All @@ -314,7 +312,7 @@ std::optional<std::string> parse_color_tag(Parser& parser, parse_args_t& parse_a
output += endspan;
endspan.clear();

const auto& append_endspan = [&](const std::string_view tag) {
const auto& append_endspan = [&endspan](const std::string_view tag) {
endspan += "</";
endspan += tag;
endspan += ">";
Expand Down

0 comments on commit 46877f3

Please sign in to comment.