[F] 💢💢💢💢💢

This commit is contained in:
Azalea Gui 2025-08-21 09:47:48 -04:00
parent 8c1713c37d
commit b58425badd
6 changed files with 38 additions and 12 deletions

View file

@ -44,6 +44,7 @@ which = { workspace = true, features = [] }
indexmap = { workspace = true, features = ["std"] }
regex = { workspace = true, features = ["perf", "std", "unicode"] }
unicode-normalization = { workspace = true, features = ["std"] }
fs_extra = "1.3.0"
[target.'cfg(windows)'.dependencies]
enable-ansi-support = { workspace = true, features = [] }

View file

@ -1,7 +1,9 @@
use std::env;
use std::fmt::Write as _;
use std::path::Path;
use std::{env, fs};
use std::fs;
use std::path::{Path, PathBuf};
use fs_extra::dir::{CopyOptions};
use indexmap::IndexMap;
use regex::Regex;
use unicode_normalization::UnicodeNormalization as _;
@ -23,15 +25,31 @@ impl AsciiDistro {
}
}
fn anything_that_exist(paths: &[&Path]) -> Option<PathBuf> {
paths.iter().copied().find(|p| p.exists()).map(Path::to_path_buf)
}
fn main() {
let neofetch_path = Path::new(env!("CARGO_WORKSPACE_DIR")).join("neofetch");
// Path hack to make file paths work in both workspace and manifest directory
let p_ws = PathBuf::from(env::var_os("CARGO_WORKSPACE_DIR").unwrap());
let p_mn = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
let o = PathBuf::from(env::var_os("OUT_DIR").unwrap());
for file in &["neofetch", "hyfetch"] {
let src = anything_that_exist(&[&p_ws.join(file), &p_mn.join(file)])
.expect(&format!("{} not found in workspace or manifest directory", file));
let dst = o.join(file);
println!("cargo:rerun-if-changed={}", src.display());
println!("cargo:rerun-if-changed={}", neofetch_path.display());
// Copy either file or directory
if src.is_dir() {
let opt = CopyOptions { overwrite: true, copy_inside: true, ..CopyOptions::default() };
fs_extra::dir::copy(&src, &dst, &opt).expect("Failed to copy directory to OUT_DIR");
}
else { fs::copy(&src, &dst).expect("Failed to copy file to OUT_DIR"); }
}
let out_dir = env::var_os("OUT_DIR").unwrap();
let out_path = Path::new(&out_dir);
export_distros(neofetch_path, out_path);
export_distros(&o.join("neofetch"), &o);
}
fn export_distros<P>(neofetch_path: P, out_path: &Path)

View file

@ -6,7 +6,7 @@ use std::collections::HashMap;
use std::fs::{self, File};
use std::io::{Read, Write};
const FONT_LOGOS: &str = include_str!(concat!(env!("CARGO_WORKSPACE_DIR"), "/hyfetch/data/font_logos.json"));
const FONT_LOGOS: &str = include_str!(concat!(env!("OUT_DIR"), "/hyfetch/data/font_logos.json"));
pub fn get_font_logo(backend: Backend) -> Result<String> {
// Check if the cache file exists and return its contents if it does

View file

@ -53,7 +53,7 @@ _/\_\_ _/_/\_
pub const NEOFETCH_COLOR_PATTERNS: [&str; 6] =
["${c1}", "${c2}", "${c3}", "${c4}", "${c5}", "${c6}"];
pub static NEOFETCH_COLORS_AC: OnceLock<AhoCorasick> = OnceLock::new();
pub const NEOFETCH_SCRIPT: &str = include_str!(concat!(env!("CARGO_WORKSPACE_DIR"), "/neofetch"));
pub const NEOFETCH_SCRIPT: &str = include_str!(concat!(env!("OUT_DIR"), "/neofetch"));
#[derive(Clone, Eq, PartialEq, Debug, AsRefStr, Deserialize, Serialize)]
#[serde(tag = "mode")]