mirror of
https://codeberg.org/unspeaker/perch.git
synced 2025-12-06 09:36:42 +01:00
add nerdicons and define metadata fields
This commit is contained in:
parent
747abab922
commit
c3f826a7d4
2 changed files with 54 additions and 25 deletions
60
src/main.rs
60
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<DirInfo>,
|
||||
is_mus: Option<MusInfo>,
|
||||
is_img: Option<ImgInfo>,
|
||||
depth: usize,
|
||||
hash: Option<String>,
|
||||
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<String>,
|
||||
release: Option<String>,
|
||||
track: Option<usize>,
|
||||
title: Option<String>,
|
||||
date: Option<String>,
|
||||
year: Option<String>,
|
||||
people: Option<Vec<String>>,
|
||||
publisher: Option<String>,
|
||||
key: Option<String>,
|
||||
}
|
||||
#[derive(Default, Ord, Eq, PartialEq, PartialOrd)]
|
||||
struct ImgInfo {
|
||||
author: Option<String>,
|
||||
}
|
||||
|
||||
fn main () -> Usually<()> {
|
||||
let args = cli().get_matches();
|
||||
|
|
@ -79,13 +102,8 @@ impl Taggart {
|
|||
}
|
||||
fn collect (root: &impl AsRef<Path>) -> Usually<Vec<Entry>> {
|
||||
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
|
||||
|
|
|
|||
19
src/view.rs
19
src/view.rs
|
|
@ -49,13 +49,24 @@ impl<'a> Content<TuiOut> 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));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue