feat(mm): Initial commit with a basic image viewer
Some checks failed
build / checks-matrix (push) Successful in 19m22s
build / codecov (push) Failing after 24m19s
docs / docs (push) Failing after 33m0s
build / checks-build (push) Has been cancelled

This commit is contained in:
uttarayan21
2025-10-07 03:25:54 +05:30
commit f6e431b6ac
13 changed files with 7927 additions and 0 deletions

39
src/main.rs Normal file
View File

@@ -0,0 +1,39 @@
mod cli;
mod errors;
use std::path::{Path, PathBuf};
use errors::*;
mod viewer;
pub fn main() -> Result<()> {
let args = <cli::Cli as clap::Parser>::parse();
if let Some(shell) = args.completions {
cli::Cli::completions(shell);
return Ok(());
}
let files = walker(args.input);
if files.is_empty() {
return Err(Error).attach("No files found");
}
viewer::run(files);
Ok(())
}
// Returns all the children (if a dir) and sister (if an image) files of the input path
fn walker(input: impl AsRef<Path>) -> Vec<PathBuf> {
let mut tb = ignore::types::TypesBuilder::new();
tb.add("image", "*.jpg").expect("Failed to add image type");
ignore::WalkBuilder::new(input)
.types(
tb.select("image")
.add_defaults()
.build()
.expect("Failed to build type finder"),
)
.sort_by_file_name(|a, b| a.cmp(b))
.build()
.filter_map(|e| e.ok())
.filter(|e| e.file_type().map_or(false, |ft| ft.is_file()))
.map(|e| e.path().to_path_buf())
.collect()
}