fix(xtask): handle missing chafa gracefully
This commit is contained in:
@@ -16,3 +16,4 @@ ratatui = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
tempfile = { workspace = true }
|
||||
tokio = { workspace = true }
|
||||
which = { workspace = true }
|
||||
|
||||
@@ -22,6 +22,7 @@ use ratatui::{Terminal, backend::TestBackend};
|
||||
use serde_json::json;
|
||||
use tokio::runtime::Runtime;
|
||||
use tokio::sync::mpsc;
|
||||
use which::which;
|
||||
|
||||
use crate::workspace_root;
|
||||
|
||||
@@ -51,6 +52,24 @@ pub(crate) fn run(output: Option<PathBuf>, chafa: Option<PathBuf>, no_png: bool)
|
||||
env::set_var("XDG_DATA_HOME", &config_home);
|
||||
}
|
||||
|
||||
let png_requested = !no_png;
|
||||
let mut chafa_binary: Option<PathBuf> = None;
|
||||
if png_requested {
|
||||
if let Some(ref path) = chafa {
|
||||
if path.exists() {
|
||||
chafa_binary = Some(path.clone());
|
||||
} else {
|
||||
bail!("specified chafa binary '{}' does not exist", path.display());
|
||||
}
|
||||
} else if let Ok(found) = which("chafa") {
|
||||
chafa_binary = Some(found);
|
||||
} else {
|
||||
eprintln!(
|
||||
"warning: chafa not found in PATH; skipping PNG conversion (install `chafa` or rerun with --no-png)"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
let runtime = Runtime::new().context("failed to create tokio runtime")?;
|
||||
|
||||
for scene in scenes() {
|
||||
@@ -60,14 +79,14 @@ pub(crate) fn run(output: Option<PathBuf>, chafa: Option<PathBuf>, no_png: bool)
|
||||
fs::write(&ans_path, ansi.as_bytes())
|
||||
.with_context(|| format!("failed to write ANSI dump {}", ans_path.display()))?;
|
||||
|
||||
if !no_png
|
||||
if let Some(ref binary) = chafa_binary
|
||||
&& let Err(err) = convert_to_png(
|
||||
&ans_path,
|
||||
scene.width,
|
||||
scene.height,
|
||||
&output_dir,
|
||||
scene.name,
|
||||
chafa.as_deref(),
|
||||
Some(binary.as_path()),
|
||||
)
|
||||
{
|
||||
eprintln!("warning: {}", err);
|
||||
@@ -75,7 +94,11 @@ pub(crate) fn run(output: Option<PathBuf>, chafa: Option<PathBuf>, no_png: bool)
|
||||
}
|
||||
|
||||
println!("Screenshots written to {}", output_dir.display());
|
||||
if no_png {
|
||||
if png_requested {
|
||||
if chafa_binary.is_none() {
|
||||
println!("PNG conversion skipped (install `chafa` or pass --no-png to disable)");
|
||||
}
|
||||
} else {
|
||||
println!("PNG conversion skipped (use --no-png=false or omit flag to enable)");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user