mirror of
https://codeberg.org/unspeaker/perch.git
synced 2025-12-07 10:06:44 +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)>,
|
editing: Option<(usize, usize)>,
|
||||||
show_hash: bool,
|
show_hash: bool,
|
||||||
}
|
}
|
||||||
#[derive(Ord, Eq, PartialEq, PartialOrd, Default)]
|
#[derive(Default, Ord, Eq, PartialEq, PartialOrd)]
|
||||||
struct Entry {
|
struct Entry {
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
is_dir: bool,
|
is_dir: Option<DirInfo>,
|
||||||
is_mus: bool,
|
is_mus: Option<MusInfo>,
|
||||||
is_img: bool,
|
is_img: Option<ImgInfo>,
|
||||||
depth: usize,
|
depth: usize,
|
||||||
hash: Option<String>,
|
hash: Option<String>,
|
||||||
file_type: Option<&'static FileType>,
|
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<()> {
|
fn main () -> Usually<()> {
|
||||||
let args = cli().get_matches();
|
let args = cli().get_matches();
|
||||||
|
|
@ -79,13 +102,8 @@ impl Taggart {
|
||||||
}
|
}
|
||||||
fn collect (root: &impl AsRef<Path>) -> Usually<Vec<Entry>> {
|
fn collect (root: &impl AsRef<Path>) -> Usually<Vec<Entry>> {
|
||||||
let mut paths = vec![];
|
let mut paths = vec![];
|
||||||
for entry in WalkDir::new(&root)
|
for entry in WalkDir::new(&root).into_iter()
|
||||||
.into_iter()
|
.filter_entry(|e|!e.file_name().to_str().map(|s|s.starts_with(".")).unwrap_or(false))
|
||||||
.filter_entry(|e|!e
|
|
||||||
.file_name()
|
|
||||||
.to_str()
|
|
||||||
.map(|s|s.starts_with("."))
|
|
||||||
.unwrap_or(false))
|
|
||||||
{
|
{
|
||||||
let entry = entry?;
|
let entry = entry?;
|
||||||
if entry.depth() == 0 {
|
if entry.depth() == 0 {
|
||||||
|
|
@ -94,28 +112,28 @@ impl Taggart {
|
||||||
let depth = entry.depth();
|
let depth = entry.depth();
|
||||||
let path = entry.into_path();
|
let path = entry.into_path();
|
||||||
let (is_dir, is_mus, is_img, hash, file_type) = if path.is_dir() {
|
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 {
|
} else {
|
||||||
let bytes = read(&path)?;
|
let bytes = read(&path)?;
|
||||||
let hash = hex::encode(xxh3_64(&bytes).to_be_bytes());
|
let hash = hex::encode(xxh3_64(&bytes).to_be_bytes());
|
||||||
let file_type = FileType::try_from_reader(&*bytes)?;
|
let file_type = FileType::try_from_reader(&*bytes)?;
|
||||||
let mime_type = file_type.media_types().get(0);
|
let mime_type = file_type.media_types().get(0);
|
||||||
let is_mus = match mime_type {
|
let is_mus = match mime_type {
|
||||||
Some(&"audio/mpeg3") => true,
|
Some(&"audio/mpeg3") => Some(Default::default()),
|
||||||
_ => false,
|
_ => None,
|
||||||
};
|
};
|
||||||
let is_img = match mime_type {
|
let is_img = match mime_type {
|
||||||
Some(&"image/png") => true,
|
Some(&"image/png") => Some(Default::default()),
|
||||||
_ => false,
|
_ => None,
|
||||||
};
|
};
|
||||||
println!("{hash} {file_type:?} ({}b)\n{}\n", bytes.len(), path.display());
|
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 {
|
paths.push(Entry {
|
||||||
path: path.strip_prefix(&root)?.into(),
|
path: path.strip_prefix(&root)?.into(),
|
||||||
is_dir: path.is_dir(),
|
is_dir,
|
||||||
is_mus: false,
|
is_mus,
|
||||||
is_img: false,
|
is_img,
|
||||||
depth,
|
depth,
|
||||||
hash,
|
hash,
|
||||||
file_type
|
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() {
|
for (index, fragment) in entry.path.iter().enumerate() {
|
||||||
if index == entry.depth - 1 {
|
if index == entry.depth - 1 {
|
||||||
let cursor = if selected { ">" } else { " " };
|
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 name = fragment.display();
|
||||||
let indent = "".pad_to_width((entry.depth - 1) * 2);
|
let indent = "".pad_to_width((entry.depth - 1) * 2);
|
||||||
let label = table_row(&format!("{cursor} {indent}{icon} {name}"), "", "", "", "");
|
let label = table_row(&format!("{cursor} {indent}{icon} {name}"), "", "", "", "");
|
||||||
to.blit(&label, area.x(), y, if entry.is_dir { None } else {
|
to.blit(&label, area.x(), y, style);
|
||||||
Some(Style::default().bold())
|
|
||||||
});
|
|
||||||
if selected {
|
if selected {
|
||||||
let fill = [area.x(), y, area.w(), 1];
|
let fill = [area.x(), y, area.w(), 1];
|
||||||
to.fill_bg(fill, Color::Rgb(48, 48, 48));
|
to.fill_bg(fill, Color::Rgb(48, 48, 48));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue