feat: add support for custom logos at runtime
Some checks failed
CI / ${{ matrix.name }} (${{ matrix.target }}) (false, Linux x86_64, ubuntu-latest, true, x86_64-unknown-linux-gnu) (push) Has been cancelled
CI / ${{ matrix.name }} (${{ matrix.target }}) (false, Windows x86_64, windows-latest, true, x86_64-pc-windows-gnu) (push) Has been cancelled
CI / ${{ matrix.name }} (${{ matrix.target }}) (false, macOS x86_64, macos-latest, true, x86_64-apple-darwin) (push) Has been cancelled
CI / ${{ matrix.name }} (${{ matrix.target }}) (true, Android, ubuntu-latest, true, aarch64-linux-android) (push) Has been cancelled
CI / ${{ matrix.name }} (${{ matrix.target }}) (true, FreeBSD, ubuntu-latest, true, x86_64-unknown-freebsd) (push) Has been cancelled
Some checks failed
CI / ${{ matrix.name }} (${{ matrix.target }}) (false, Linux x86_64, ubuntu-latest, true, x86_64-unknown-linux-gnu) (push) Has been cancelled
CI / ${{ matrix.name }} (${{ matrix.target }}) (false, Windows x86_64, windows-latest, true, x86_64-pc-windows-gnu) (push) Has been cancelled
CI / ${{ matrix.name }} (${{ matrix.target }}) (false, macOS x86_64, macos-latest, true, x86_64-apple-darwin) (push) Has been cancelled
CI / ${{ matrix.name }} (${{ matrix.target }}) (true, Android, ubuntu-latest, true, aarch64-linux-android) (push) Has been cancelled
CI / ${{ matrix.name }} (${{ matrix.target }}) (true, FreeBSD, ubuntu-latest, true, x86_64-unknown-freebsd) (push) Has been cancelled
closes #33 This allows to use the `PF_CUSTOM_LOGOS` option to load a file containing pfetch logos
This commit is contained in:
parent
a786e8971e
commit
62be00b3b9
59
README.md
59
README.md
@ -85,12 +85,11 @@ value.
|
||||
## Configuration
|
||||
|
||||
Like the original `pfetch`, `pfetch-rs` is configured through environment
|
||||
variables. Your existing config will probably still work, the only difference is
|
||||
variables. Your existing config will probably still work, the main difference is
|
||||
how padding is configured.
|
||||
|
||||
If you want to display a custom logo, you will have to download the source code,
|
||||
make your changes to `./pfetch-extractor/logos.sh` and build the binary with
|
||||
`cargo b --release`.
|
||||
If you want to display a custom logo, use the `PF_CUSTOM_LOGOS` option, an
|
||||
example for a custom logos file can be found below.
|
||||
|
||||
```sh
|
||||
# Which information to display.
|
||||
@ -106,11 +105,16 @@ PF_INFO="ascii"
|
||||
# Example: Only Information.
|
||||
PF_INFO="title os host kernel uptime pkgs memory"
|
||||
|
||||
# A file containing environment variables to source before running pfetch.
|
||||
# A file containing environment variables to source before running pfetch
|
||||
# Default: unset
|
||||
# Valid: A shell script
|
||||
PF_SOURCE=""
|
||||
|
||||
# A file containing pfetch logos to overwrite default logos or add new logos
|
||||
# Default: unset
|
||||
# Valid: Path to a file containing pfetch logos (example below)
|
||||
PF_CUSTOM_LOGOS="~/.config/pfetch_logos"
|
||||
|
||||
# Separator between info name and info data.
|
||||
# Default: unset
|
||||
# Valid: string
|
||||
@ -162,3 +166,48 @@ HOSTNAME=""
|
||||
# Skip package managers that take "long" to query package count (like nix)
|
||||
PF_FAST_PKG_COUNT=1
|
||||
```
|
||||
|
||||
A file containing custom pfetch logos could look like this (also found under
|
||||
`custom_logos_example`). This will turn the Arch Linux logo red, the Debian Logo
|
||||
blue and the Fedora logo yellow:
|
||||
|
||||
```
|
||||
[Aa]rch*)
|
||||
read_ascii 1 <<- EOF
|
||||
${c1} /\\
|
||||
${c1} / \\
|
||||
${c1} /\\ \\
|
||||
${c1} / \\
|
||||
${c1} / ,, \\
|
||||
${c1} / | | -\\
|
||||
${c1} /_-'' ''-_\\
|
||||
EOF
|
||||
;;
|
||||
[Dd]ebian*)
|
||||
read_ascii 4 <<- EOF
|
||||
${c4} _____
|
||||
${c4} / __ \\
|
||||
${c4}| / |
|
||||
${c4}| \\___-
|
||||
${c4}-_
|
||||
${c4} --_
|
||||
EOF
|
||||
;;
|
||||
[Ff]edora*)
|
||||
read_ascii 3 <<- EOF
|
||||
${c3},'''''.
|
||||
${c3}| ,. |
|
||||
${c3}| | '_'
|
||||
${c3} ,....| |..
|
||||
${c3}.' ,_;| ..'
|
||||
${c3}| | | |
|
||||
${c3}| ',_,' |
|
||||
${c3} '. ,'
|
||||
${c3}'''''
|
||||
EOF
|
||||
```
|
||||
|
||||
_Note: Make sure to use tabs for indentation and separate logos with `;;`, as
|
||||
seen above. You only need to add the logos you want to overwrite/add, the
|
||||
default logos will stay available. The included logos can be found at
|
||||
`./pfetch-extractor/logos.sh`._
|
||||
|
||||
34
custom_logos_example
Normal file
34
custom_logos_example
Normal file
@ -0,0 +1,34 @@
|
||||
[Aa]rch*)
|
||||
read_ascii 1 <<- EOF
|
||||
${c1} /\\
|
||||
${c1} / \\
|
||||
${c1} /\\ \\
|
||||
${c1} / \\
|
||||
${c1} / ,, \\
|
||||
${c1} / | | -\\
|
||||
${c1} /_-'' ''-_\\
|
||||
EOF
|
||||
;;
|
||||
[Dd]ebian*)
|
||||
read_ascii 4 <<- EOF
|
||||
${c4} _____
|
||||
${c4} / __ \\
|
||||
${c4}| / |
|
||||
${c4}| \\___-
|
||||
${c4}-_
|
||||
${c4} --_
|
||||
EOF
|
||||
;;
|
||||
|
||||
[Ff]edora*)
|
||||
read_ascii 3 <<- EOF
|
||||
${c3},'''''.
|
||||
${c3}| ,. |
|
||||
${c3}| | '_'
|
||||
${c3} ,....| |..
|
||||
${c3}.' ,_;| ..'
|
||||
${c3}| | | |
|
||||
${c3}| ',_,' |
|
||||
${c3} '. ,'
|
||||
${c3}'''''
|
||||
EOF
|
||||
21
src/lib.rs
21
src/lib.rs
@ -1,4 +1,4 @@
|
||||
use std::{env, fs, io::Result, process::Command};
|
||||
use std::{collections::VecDeque, env, fs, io::Result, process::Command};
|
||||
|
||||
use glob::glob;
|
||||
use globset::Glob;
|
||||
@ -6,7 +6,7 @@ use libmacchina::{
|
||||
traits::GeneralReadout as _, traits::KernelReadout as _, traits::MemoryReadout as _,
|
||||
traits::PackageReadout as _, GeneralReadout, KernelReadout, MemoryReadout, PackageReadout,
|
||||
};
|
||||
use pfetch_logo_parser::Logo;
|
||||
use pfetch_logo_parser::{parse_logo, Logo};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum PackageManager {
|
||||
@ -311,8 +311,23 @@ pub fn host(general_readout: &GeneralReadout) -> Option<String> {
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_custom_logos(filename: &str) -> Vec<Option<Logo>> {
|
||||
let file_contents = fs::read_to_string(filename).expect("Could not open custom logo file");
|
||||
file_contents
|
||||
.split(";;")
|
||||
.map(|raw_logo| parse_logo(raw_logo).map(|(_, logo)| logo))
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
|
||||
pub fn logo(logo_name: &str) -> Logo {
|
||||
let (tux, logos) = pfetch_extractor::parse_logos!();
|
||||
let (tux, included_logos) = pfetch_extractor::parse_logos!();
|
||||
let mut logos: VecDeque<_> = included_logos.into();
|
||||
if let Ok(filename) = dotenvy::var("PF_CUSTOM_LOGOS") {
|
||||
// insert custom logos in front of incuded logos
|
||||
for custom_logo in parse_custom_logos(&filename).into_iter().flatten() {
|
||||
logos.insert(0, custom_logo.clone());
|
||||
}
|
||||
};
|
||||
logos
|
||||
.into_iter()
|
||||
.find(|logo| {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user