Skip to content

Commit

Permalink
Added line formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
al1-ce committed Dec 8, 2022
1 parent 864f9df commit 943af06
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 31 deletions.
47 changes: 23 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. <br> Will not work if `yaysearch` is `true`. | `true` |
| separate | bool | Separates search results with separator. <br> 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. | `[ ]` |
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/pkm/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -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"]));
Expand Down
2 changes: 2 additions & 0 deletions src/pkm/config.d
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 11 additions & 6 deletions src/pkm/search.d
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand All @@ -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);

Expand All @@ -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 = [];
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 943af06

Please sign in to comment.