-
Notifications
You must be signed in to change notification settings - Fork 147
Port missed changes from the Python version #370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ccc8121
Add queer subculture flags (port of #302)
teohhanhui a60dd35
Add caninekin flag for all the dogs (port of #318)
teohhanhui e78ae32
Add a higher-contrast version of pangender flag (port of f4d6b75)
teohhanhui 99d6523
Add random preset option (port of 1211dc6)
teohhanhui 6558cf3
Apply fix from clippy (Rust 1.83)
teohhanhui 191995c
Fix preset name mismatch ("throatlozenges")
teohhanhui deb2bdd
[+] Font logo
hykilpikonna 9435030
[+] Add print_font_logo CLI option
hykilpikonna e78d95e
[U] Bump version to 2.0.0
hykilpikonna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ resolver = "2" | |
| members = ["crates/*"] | ||
|
|
||
| [workspace.package] | ||
| version = "1.4.11" | ||
| version = "2.0.0" | ||
| authors = ["Azalea Gui <[email protected]>"] | ||
| edition = "2021" | ||
| rust-version = "1.75.0" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| use crate::neofetch_util::get_distro_name; | ||
| use crate::types::Backend; | ||
| use crate::utils::get_cache_path; | ||
| use anyhow::{Context, Result}; | ||
| use std::collections::HashMap; | ||
| use std::fs::{self, File}; | ||
| use std::io::{Read, Write}; | ||
|
|
||
| const FONT_LOGOS: &str = r#"{"Alma":"","Alpine":"","AOSC OS":"","Apple":"","Archcraft":"","ArchLabs":"","Arch":"","Arco":"","Arduino":"","Artix":"","Awesome WM":"","Big":"","bspwm":"","Budgie":"","CentOS":"","Cinnamon":"","Codeberg":"","CoreOS":"","Crystal":"","Debian":"","Deepin":"","Devuan":"","Docker":"","dwm":"","elementary OS":"","Endeavour OS":"","Enlightenment":"","F-droid":"","Fedora":"","Fedora (inverse)":"","Ferris":"","Flathub":"","Fluxbox":"","Forgejo":"","FOSDEM":"","FreeBSD":"","FreeCAD":"","freedesktop.org":"","Garuda":"","Gentoo":"","GIMP":"","Gitea":"","GNOME":"","GNU Guix":"","GTK":"","Hyperbola -libre":"","Hyprland":"","i3":"","illumos":"","Inkscape":"","JWM":"","Kali":"","KDE":"","KDE Neon":"","KDE Plasma":"","Kdenlive":"","KiCad":"","Krita":"","Kubuntu":"","Kubuntu (inverse)":"","Mint":"","Mint (inverse)":"","Loc-OS":"","LXDE":"","LXLE":"","LXQt":"","Mageia":"","Mandriva":"","Manjaro":"","MATE":"","mpv":"","MX":"","Neovim":"","NixOS":"","Octoprint":"","OpenBSD":"","OpenSCAD":"","OpenSUSE":"","OSH":"","OSHWA":"","OSI":"","Parabola -libre":"","Parrot OS":"","Pop!_OS":"","PostmarketOS":"","Prusa Slicer":"","Puppy":"","Qt":"","Qtile":"","QubesOS":"","Raspberry pi":"","Red Hat":"","RepRap":"","RISC-V":"","Rocky":"","Sabayon":"","Slackware":"","Slackware (inverse)":"","Snappy":"","Solus":"","Sway":"","Tails":"","Thunderbird":"","Tor Browser":"","Trisquel":"","Tux":"","Ubuntu":"","Ubuntu (inverse)":"","Vanilla OS":"","Void":"","VS Codium":"","Wayland":"","Wikimedia":"","Xero":"","XFCE":"","Xmonad":"","Xorg":"","Zorin OS":"","Windows":""}"#; | ||
|
|
||
| pub fn get_font_logo(backend: Backend) -> Result<String> { | ||
| // Check if the cache file exists and return its contents if it does | ||
| let cache_path = get_cache_path().context("Failed to get cache path")?.join("font_logo"); | ||
| if cache_path.exists() { | ||
| let mut cached_logo = String::new(); | ||
| File::open(cache_path).context("Failed to open cache file")? | ||
| .read_to_string(&mut cached_logo).context("Failed to read from cache file")?; | ||
| return Ok(cached_logo); | ||
| } | ||
|
|
||
| // Deserialize the JSON into a HashMap | ||
| let font_logos: HashMap<String, String> = serde_json::from_str::<HashMap<String, String>>(FONT_LOGOS) | ||
| .context("Failed to deserialize font logos JSON file")? | ||
| .into_iter().map(|(k, v)| (k.to_lowercase(), v)).collect(); | ||
|
|
||
| // Get the distro name | ||
| let distro = get_distro_name(backend).context("Failed to get distro name")?.to_lowercase(); | ||
|
|
||
| // Find the most likely matching distro from font_logos | ||
| let matched_distro = font_logos.keys().find(|&k| distro.contains(k)) | ||
| .or_else(|| font_logos.keys().find(|k| k.contains(&distro))) | ||
| .or_else(|| font_logos.keys().find(|k| k.split_whitespace().any(|part| distro.contains(part)))) | ||
| .ok_or_else(|| anyhow::anyhow!("No font logo found for distro: {distro}. The supported logos are in https://github.com/Lukas-W/font-logos"))?; | ||
|
|
||
| let logo = font_logos.get(matched_distro).unwrap(); | ||
|
|
||
| // Create parent directories for the cache if they don't exist | ||
| if let Some(parent) = cache_path.parent() { | ||
| fs::create_dir_all(parent).context("Failed to create cache directory")?; | ||
| } | ||
|
|
||
| // Write the logo to the cache file | ||
| let mut cache_file = File::create(cache_path).context("Failed to create cache file")?; | ||
| cache_file.write_all(logo.as_bytes()).context("Failed to write logo to cache file")?; | ||
|
|
||
| Ok(logo.clone()) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.