Skip to content

Commit

Permalink
add more customization
Browse files Browse the repository at this point in the history
This is probably going to the be the favourite AUR helper for ricers
  • Loading branch information
Toni500github committed Apr 15, 2024
1 parent 4c47f04 commit 7a7d1f5
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 19 deletions.
13 changes: 13 additions & 0 deletions include/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,19 @@ blue = "#00aaff"
cyan = "#00ffff"
yellow = "#ffff00"
magenta = "#ff11cc"
# custom DB colors such as extra, aur, etc.
# Unfortunatly toml doesn't support things like `aur = blue`
aur = "#00aaff"
extra = "#00ff00"
core = "#ffff00"
multilib = "#00ffff"
# Other DBs such as extra-testing, core-testing, custom ones in custom repos, etc.
others = "#ff11cc"
version = "#00ff00"
popularity = "#00ffff"
index = "#ff11cc"
)#";

inline string red = "#ff2000";
Expand Down
2 changes: 1 addition & 1 deletion include/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ bool taur_exec(std::vector<const char*> cmd, bool exitOnFailure = true);
void sanitizeStr(string& str);
bool is_package_from_syncdb(alpm_pkg_t *pkg, alpm_list_t *syncdbs);
bool commitTransactionAndRelease(bool soft = false);
void printPkgInfo(TaurPkg_t &pkg, int index = -1);
void printPkgInfo(TaurPkg_t &pkg, string db_name, int index = -1);
void free_list_and_internals(alpm_list_t *list);
fmt::text_style getColorFromDBName(string db_name);
std::optional<std::vector<TaurPkg_t>> askUserForPkg(vector<TaurPkg_t> pkgs, TaurBackend& backend, bool useGit);
Expand Down
42 changes: 33 additions & 9 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,42 @@ void usage(int op) {
}

void test_colors() {
TaurPkg_t pkg = {
"TabAUR", // name
VERSION, // version
"https://github.com/BurntRanch/TabAUR", // url
"A customizable and lightweight AUR helper, designed to be simple but powerful.", // desc
10, // Popularity
vector<string>(), // depends
"aur", // db_name
};

if(fmt::disable_colors)
fmt::println("Colors are disabled");
log_printf(LOG_DEBUG, "Debug color: {}\n", fmt::format(BOLD_TEXT(config->getThemeValue("magenta", magenta)), "(bold) magenta"));
log_printf(LOG_INFO, "Info color: {}\n", fmt::format(BOLD_TEXT(config->getThemeValue("cyan", cyan)), "(bold) cyan"));
log_printf(LOG_WARN, "Warning color: {}\n", fmt::format(BOLD_TEXT(config->getThemeValue("yellow", yellow)), "(bold) yellow"));
log_printf(LOG_ERROR, "Error color: {}\n", fmt::format(BOLD_TEXT(config->getThemeValue("red", red)), "(bold) red"));
fmt::println("red: {}", fmt::format(fg(config->getThemeValue("red", red)), config->getThemeHexValue("red", red)));
fmt::println("blue: {}", fmt::format(fg(config->getThemeValue("blue", blue)), config->getThemeHexValue("blue", blue)));
fmt::println("yellow: {}", fmt::format(fg(config->getThemeValue("yellow", yellow)), config->getThemeHexValue("yellow", yellow)));
fmt::println("green: {}", fmt::format(fg(config->getThemeValue("green", green)), config->getThemeHexValue("green", green)));
fmt::println("cyan: {}", fmt::format(fg(config->getThemeValue("cyan", cyan)), config->getThemeHexValue("cyan", cyan)));
fmt::println("magenta: {}",fmt::format(fg(config->getThemeValue("magenta", magenta)), config->getThemeHexValue("magenta", magenta)));
fmt::println(fg(config->getThemeValue("red", red)), "red");
fmt::println(fg(config->getThemeValue("blue", blue)), "blue");
fmt::println(fg(config->getThemeValue("yellow", yellow)), "yellow");
fmt::println(fg(config->getThemeValue("green", green)), "green");
fmt::println(fg(config->getThemeValue("cyan", cyan)), "cyan");
fmt::println(fg(config->getThemeValue("magenta", magenta)), "magenta");

fmt::println("\ndb colors:");
fmt::println(getColorFromDBName("aur"), "(bold) aur");
fmt::println(getColorFromDBName("extra"), "(bold) extra");
fmt::println(getColorFromDBName("core"), "(bold) core");
fmt::println(getColorFromDBName("multilib"), "(bold) multilib");
fmt::println(getColorFromDBName("others"), "(bold) others");

fmt::println(BOLD_TEXT(config->getThemeValue("version", green)), "\n(bold) version " VERSION);
fmt::println(fg(config->getThemeValue("popularity", cyan)), "Popularity: {} ({})", pkg.popularity, getTitleForPopularity(pkg.popularity));
fmt::println(fg(config->getThemeValue("index", magenta)), "index [1]");

fmt::println("\nexamples package search preview:");
printPkgInfo(pkg, pkg.db_name);
}

bool execPacman(int argc, char* argv[]) {
Expand Down Expand Up @@ -131,7 +155,7 @@ int installPkg(string pkgName) {
// ./taur -Ss -- list only, don't install.
if (op.op_s_search) {
for (size_t i = 0; i < pkgs.size(); i++)
printPkgInfo(pkgs[i]);
printPkgInfo(pkgs[i], pkgs[i].db_name);
return true;
}

Expand All @@ -148,7 +172,7 @@ int installPkg(string pkgName) {
string url = pkg.url;

if (url == "") {
vector<const char *> cmd = {"sudo", "pacman", "-S"};
vector<const char *> cmd = {config->sudo.c_str(), "pacman", "-S"};
if(op.op_s_sync)
cmd.push_back("-y");
if(op.op_s_upgrade)
Expand Down Expand Up @@ -245,7 +269,7 @@ bool queryPkgs() {
fmt::println("{}", pkgs[i]);
}
} else {
fmt::rgb _green = config->getThemeValue("green", green);
fmt::rgb _green = config->getThemeValue("version", green);
for(size_t i = 0; i < pkgs.size(); i++) {
if (!pkgs[i])
continue;
Expand Down
20 changes: 11 additions & 9 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,24 +293,26 @@ void free_list_and_internals(alpm_list_t *list) {
*/
fmt::text_style getColorFromDBName(string db_name) {
if (db_name == "aur")
return BOLD_TEXT(config->getThemeValue("blue", blue));
return BOLD_TEXT(config->getThemeValue("aur", blue));
else if (db_name == "extra")
return BOLD_TEXT(config->getThemeValue("green", green));
return BOLD_TEXT(config->getThemeValue("extra", green));
else if (db_name == "core")
return BOLD_TEXT(config->getThemeValue("core", yellow));
else if (db_name == "multilib")
return BOLD_TEXT(config->getThemeValue("cyan", cyan));
return BOLD_TEXT(config->getThemeValue("multilib", cyan));
else
return BOLD_TEXT(config->getThemeValue("yellow", yellow));
return BOLD_TEXT(config->getThemeValue("others", magenta));
}

// Takes a pkg, and index, to show. index is for show and can be set to -1 to hide.
void printPkgInfo(TaurPkg_t &pkg, int index) {
void printPkgInfo(TaurPkg_t &pkg, string db_name, int index) {
if (index > -1)
fmt::print(fmt::fg(config->getThemeValue("magenta", magenta)), "[{}] ", index);

fmt::print(getColorFromDBName(pkg.db_name), "{}/", pkg.db_name);
fmt::print(getColorFromDBName(db_name), "{}/", db_name);
fmt::print(fmt::emphasis::bold, "{} ", pkg.name);
fmt::print(BOLD_TEXT(config->getThemeValue("green", green)), "{} ", pkg.version);
fmt::println(fmt::fg(config->getThemeValue("cyan", cyan)), " Popularity: {} ({})", pkg.popularity, getTitleForPopularity(pkg.popularity));
fmt::print(BOLD_TEXT(config->getThemeValue("version", green)), "{} ", pkg.version);
fmt::println(fmt::fg(config->getThemeValue("popularity", cyan)), " Popularity: {} ({})", pkg.popularity, getTitleForPopularity(pkg.popularity));
fmt::println(" {}", pkg.desc);
}

Expand All @@ -337,7 +339,7 @@ optional<vector<TaurPkg_t>> askUserForPkg(vector<TaurPkg_t> pkgs, TaurBackend& b
log_printf(LOG_WARN, "Invalid input!\n");

for (size_t i = 0; i < pkgs.size(); i++)
printPkgInfo(pkgs[i], i);
printPkgInfo(pkgs[i], pkgs[i].db_name, i);

fmt::print("Choose a package to download: ");
std::getline(std::cin, input);
Expand Down

0 comments on commit 7a7d1f5

Please sign in to comment.