diff --git a/src/main.rs b/src/main.rs index 47c05cc..3ab9d61 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,16 +41,39 @@ struct Taggart { editing: Option<(usize, usize)>, show_hash: bool, } -#[derive(Ord, Eq, PartialEq, PartialOrd, Default)] +#[derive(Default, Ord, Eq, PartialEq, PartialOrd)] struct Entry { path: PathBuf, - is_dir: bool, - is_mus: bool, - is_img: bool, + is_dir: Option, + is_mus: Option, + is_img: Option, depth: usize, hash: Option, file_type: Option<&'static FileType>, } +#[derive(Default, Ord, Eq, PartialEq, PartialOrd)] +struct DirInfo { + hash_file: Option<()>, + catalog_file: Option<()>, + artist_file: Option<()>, + release_file: Option<()>, +} +#[derive(Default, Ord, Eq, PartialEq, PartialOrd)] +struct MusInfo { + artist: Option, + release: Option, + track: Option, + title: Option, + date: Option, + year: Option, + people: Option>, + publisher: Option, + key: Option, +} +#[derive(Default, Ord, Eq, PartialEq, PartialOrd)] +struct ImgInfo { + author: Option, +} fn main () -> Usually<()> { let args = cli().get_matches(); @@ -79,13 +102,8 @@ impl Taggart { } fn collect (root: &impl AsRef) -> Usually> { let mut paths = vec![]; - for entry in WalkDir::new(&root) - .into_iter() - .filter_entry(|e|!e - .file_name() - .to_str() - .map(|s|s.starts_with(".")) - .unwrap_or(false)) + for entry in WalkDir::new(&root).into_iter() + .filter_entry(|e|!e.file_name().to_str().map(|s|s.starts_with(".")).unwrap_or(false)) { let entry = entry?; if entry.depth() == 0 { @@ -94,28 +112,28 @@ impl Taggart { let depth = entry.depth(); let path = entry.into_path(); let (is_dir, is_mus, is_img, hash, file_type) = if path.is_dir() { - (true, false, false, None, None) + (Some(Default::default()), None, None, None, None) } else { let bytes = read(&path)?; let hash = hex::encode(xxh3_64(&bytes).to_be_bytes()); let file_type = FileType::try_from_reader(&*bytes)?; let mime_type = file_type.media_types().get(0); let is_mus = match mime_type { - Some(&"audio/mpeg3") => true, - _ => false, + Some(&"audio/mpeg3") => Some(Default::default()), + _ => None, }; let is_img = match mime_type { - Some(&"image/png") => true, - _ => false, + Some(&"image/png") => Some(Default::default()), + _ => None, }; println!("{hash} {file_type:?} ({}b)\n{}\n", bytes.len(), path.display()); - (false, is_mus, is_img, Some(hash), Some(file_type)) + (None, is_mus, is_img, Some(hash), Some(file_type)) }; paths.push(Entry { - path: path.strip_prefix(&root)?.into(), - is_dir: path.is_dir(), - is_mus: false, - is_img: false, + path: path.strip_prefix(&root)?.into(), + is_dir, + is_mus, + is_img, depth, hash, file_type diff --git a/src/view.rs b/src/view.rs index 3feffe5..acdb128 100644 --- a/src/view.rs +++ b/src/view.rs @@ -49,13 +49,24 @@ impl<'a> Content for TreeTable<'a> { for (index, fragment) in entry.path.iter().enumerate() { if index == entry.depth - 1 { let cursor = if selected { ">" } else { " " }; - let icon = if entry.is_dir {"+"} else if entry.is_img {"I"} else if entry.is_mus {"M"} else {" "}; + let icon = if entry.is_dir.is_some() { + "" //"+" + } else if entry.is_img.is_some() { + "" + } else if entry.is_mus.is_some() { + "" + } else { + " " + }; + let style = if entry.is_dir.is_some() { + None + } else { + Some(Style::default().bold()) + }; let name = fragment.display(); let indent = "".pad_to_width((entry.depth - 1) * 2); let label = table_row(&format!("{cursor} {indent}{icon} {name}"), "", "", "", ""); - to.blit(&label, area.x(), y, if entry.is_dir { None } else { - Some(Style::default().bold()) - }); + to.blit(&label, area.x(), y, style); if selected { let fill = [area.x(), y, area.w(), 1]; to.fill_bg(fill, Color::Rgb(48, 48, 48));