From 943af064dcef5d7ce2b9a7427c463de64f928f10 Mon Sep 17 00:00:00 2001 From: al1-ce Date: Thu, 8 Dec 2022 19:17:40 +0300 Subject: [PATCH] Added line formatting --- README.md | 47 +++++++++++++++++++++++------------------------ src/pkm/app.d | 2 +- src/pkm/config.d | 2 ++ src/pkm/search.d | 17 +++++++++++------ 4 files changed, 37 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 2e07234..92b0aaf 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,7 @@ pkm can be configured with config file located at `~/.config/pkm/conf.yaml`, `~/ | color | bool | Sets if search will be printed with colors.
Will not work if `yaysearch` is `true`. | `true` | | separate | bool | Separates search results with separator.
Will not work if `yaysearch` is `true`. | `false` | | separator | string | Sets separator for `separate` option. If it's unicode escape sequence then it must be wrapped in `"` | `"\u2500"` | +| separator-color | string | Sets formatting for `separate` option. Must be set with `\e` as escape symbol | `\e[90m` | | auronly | bool | Should yay search only AUR. | `false` | | managers | string[] | Defines custom managers. | `[ ]` | | custom | string[] | Custom commands. | `[ ]` | @@ -217,30 +218,28 @@ If package is from AUR then it's displaying votes/popularity instead of size and See [yay faq](https://github.com/Jguer/yay#frequently-asked-questions) - ### My config - ```yaml - # ~/.config/pkm/conf.yaml - managers: - aura: /usr/bin/aura - pacman: /usr/bin/pacman - pamac: /usr/bin/pamac - custom: - updupg: -Syu - stats: -Ps - pkgbuild: -Gp - vote: -Wv - unvote: -Wu - sysupdate: pacman -Syu - alias: - # alias: name - i: install - s: search - r: remove - b: pkgbuild - u: updupg - I: info - separate: yes - separator: "\u2500" - ``` +```yaml +# ~/.config/pkm/conf.yaml +managers: +pacman: /usr/bin/pacman +custom: + updupg: -Syu + stats: -Ps + pkgbuild: -Gp + vote: -Wv + unvote: -Wu + sysupdate: pacman -Syu +alias: + i: install + s: search + r: remove + b: pkgbuild + u: updupg + I: info +separate: yes +separator: "\u2500" +separator-color: "\e[38;5;237m" +``` ### Other AUR helpers/tools - [yay](https://github.com/Jguer/yay) diff --git a/src/pkm/app.d b/src/pkm/app.d index cfd0e7d..d9099d7 100644 --- a/src/pkm/app.d +++ b/src/pkm/app.d @@ -179,7 +179,7 @@ int main(string[] args) { if (conf.yaysearch) { return wait(spawnProcess([yay, "-Ss"] ~ ops)); } else { - return search(yay, ops, conf.color, conf.separate, conf.separator); + return search(yay, ops, conf); } case "list": return wait(spawnProcess([yay, "-Q"])); diff --git a/src/pkm/config.d b/src/pkm/config.d index fdb5783..cde7390 100644 --- a/src/pkm/config.d +++ b/src/pkm/config.d @@ -40,6 +40,7 @@ Config __getConfig(string configPath) { root.getKey!bool(&conf.color, "color"); root.getKey!bool(&conf.auronly, "auronly"); root.getKey!string(&conf.separator, "separator"); + root.getKey!string(&conf.separator_color, "separator-color"); root.getKey!bool(&conf.separate, "separate"); if (root.hasKeyType!(NodeType.mapping)("custom")) { @@ -93,6 +94,7 @@ struct Config { bool auronly = false; bool separate = false; string separator = "\u2500"; + string separator_color = "\033[90m"; string[] custom = []; string[][] args = []; string[string] aliases; diff --git a/src/pkm/search.d b/src/pkm/search.d index aa6a933..1798654 100644 --- a/src/pkm/search.d +++ b/src/pkm/search.d @@ -16,6 +16,7 @@ import sily.bashfmt; import sily.path: fixPath; import pkm.pkg; +import pkm.config: SearchConfig = Config; // yay regex: // (.*?)\/(.*?)\s(.*?)\s\((.*?)\)(?:\s\[(.*)\])?(?:\s\((Orphaned)\))?(?:\s\(Out-of-date:\s(.*?)\))?(?:\s\((Installed)(?:\:\s(.*?))?\))?(?:\s{6}|\s{5})(.*)(?:\r|\n|\z) @@ -26,7 +27,7 @@ private auto reg = regex( r"(?:\s\((Orphaned)\))?(?:\s\(Out-of-date:\s(.*?)\))?" ~ r"(?:\s\((Installed)(?:\:\s(.*?))?\))?(?:\s{6}|\s{5})(.*)(?:\r|\n|\z)", "gm"); -int search(string yay, string[] terms, bool color, bool separate, string separator) { +int search(string yay, string[] terms, SearchConfig conf) { // string yay = "/usr/bin/yay"; string tmpFile = tempDir ~ "/" ~ "pkm-yay-search-output.txt"; tmpFile = tmpFile.fixPath; @@ -43,7 +44,7 @@ int search(string yay, string[] terms, bool color, bool separate, string separat return pidErr; } - printPackages(tmpFile, terms, color, separate, separator); + printPackages(tmpFile, terms, conf); remove(tmpFile); @@ -55,7 +56,7 @@ int search(string yay, string[] terms, bool color, bool separate, string separat // repo/name version (size|aur-votes) [group]? (orphaned) // 7 8 9 10 // (outofdate) (installed: (version)) \n (description) -void printPackages(string tmpFile, string[] searchTerms, bool color, bool separate, string separator) { +void printPackages(string tmpFile, string[] searchTerms, SearchConfig conf) { string contents = readText(tmpFile); Pkg[] pkgs = []; @@ -105,10 +106,14 @@ void printPackages(string tmpFile, string[] searchTerms, bool color, bool separa })(pkgs); foreach (pkg; pkgs) { - if (separate && print_) { - writeln(repeat(separator.to!dstring, terminalWidth).join); + if (conf.separate && print_) { + if (conf.color) { + writeln(conf.separator_color, repeat(conf.separator.to!dstring, terminalWidth).join, "\033[m"); + } else { + writeln(repeat(conf.separator.to!dstring, terminalWidth).join); + } } - printPackage(pkg, color); + printPackage(pkg, conf.color); if (!print_) print_ = true; }