read id3 tags

This commit is contained in:
🪞👃🪞 2025-03-07 23:49:08 +02:00
parent 72bd6148d6
commit b29511c23e
6 changed files with 251 additions and 272 deletions

View file

@ -1,22 +1,7 @@
use crate::*;
use tek_tui::ratatui::{style::{Color, Style}, prelude::Stylize};
use pad::PadStr;
fn table_row (
hash: Option<&str>, label: &str, artist: &str, album: &str, track: &str, title: &str
) -> String {
let hash = hash.unwrap_or("").pad_to_width(COLUMN_WIDTHS[0] as usize);
let label = label.pad_to_width(COLUMN_WIDTHS[1] as usize);
let artist = artist.pad_to_width(COLUMN_WIDTHS[2] as usize);
let album = album.pad_to_width(COLUMN_WIDTHS[3] as usize);
let track = track.pad_to_width(COLUMN_WIDTHS[4] as usize);
let title = title.pad_to_width(COLUMN_WIDTHS[5] as usize);
format!("{hash}{label}{artist}{album}{track}{title}")
}
fn status_bar (content: impl Content<TuiOut>) -> impl Content<TuiOut> {
Fixed::y(1, Fill::x(Tui::bold(true, Tui::fg_bg(Color::Rgb(0,0,0), Color::Rgb(255,255,255), content))))
}
use std::fmt::Display;
impl Content<TuiOut> for Taggart {
fn content (&self) -> impl Render<TuiOut> {
@ -24,7 +9,12 @@ impl Content<TuiOut> for Taggart {
let size = format!("{}x{}", self.size.w(), self.size.h());
let size_bar = status_bar(Align::e(size));
let titlebar = status_bar(Align::w(table_row(
Some("HASH"), "FILE", "ARTIST", "RELEASE", "TRACK", "TITLE"
Some("HASH".into()),
"FILE",
Some("ARTIST".into()),
Some("RELEASE".into()),
"TRACK",
Some("TITLE".into())
)));
let table = Fill::xy(TreeTable(self));
Bsp::n(size_bar, Bsp::s(titlebar, Bsp::b(sizer, table)))
@ -38,7 +28,7 @@ impl<'a> Content<TuiOut> for TreeTable<'a> {
let area = to.area();
let Taggart { offset, paths, cursor, column, .. } = self.0;
let mut x = 0;
for (index, width) in COLUMN_WIDTHS.iter().enumerate() {
for (index, _width) in COLUMN_WIDTHS.iter().enumerate() {
let w = COLUMN_WIDTHS[index] + 1;
if index == *column {
to.fill_bg([area.x() + x, area.y(), w, area.h()], Color::Rgb(0, 0, 0));
@ -54,30 +44,9 @@ 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.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(
entry.hash.as_deref(),
&format!("{indent}{icon} {name}"),
"",
"",
"",
""
);
let icon = entry.icon();
let style = entry.style();
let label = entry.label(icon, &fragment.display());
to.blit(&label, area.x(), y, style);
if selected {
let fill = [area.x(), y, area.w(), 1];
@ -92,3 +61,56 @@ impl<'a> Content<TuiOut> for TreeTable<'a> {
}
}
}
impl Entry {
fn icon (&self) -> &'static str {
if self.is_dir() {
"" //"+"
} else if self.is_img() {
""
} else if self.is_mus() {
""
} else {
" "
}
}
fn style (&self) -> Option<Style> {
if self.is_dir() {
None
} else {
Some(Style::default().bold())
}
}
fn label (&self, icon: &str, name: &impl Display) -> String {
let indent = "".pad_to_width((self.depth - 1) * 2);
table_row(
self.hash(),
&format!("{indent}{icon} {name}"),
self.artist(),
self.album(),
"",
self.title()
)
}
}
fn table_row (
hash: Option<Arc<str>>,
label: &str,
artist: Option<Arc<str>>,
album: Option<Arc<str>>,
track: &str,
title: Option<Arc<str>>,
) -> String {
let hash = hash.unwrap_or_default().pad_to_width(COLUMN_WIDTHS[0] as usize);
let label = label.pad_to_width(COLUMN_WIDTHS[1] as usize);
let artist = artist.unwrap_or_default().pad_to_width(COLUMN_WIDTHS[2] as usize);
let album = album.unwrap_or_default().pad_to_width(COLUMN_WIDTHS[3] as usize);
let track = track.pad_to_width(COLUMN_WIDTHS[4] as usize);
let title = title.unwrap_or_default().pad_to_width(COLUMN_WIDTHS[5] as usize);
format!("{hash}{label}{artist}{album}{track}{title}")
}
fn status_bar (content: impl Content<TuiOut>) -> impl Content<TuiOut> {
Fixed::y(1, Fill::x(Tui::bold(true, Tui::fg_bg(Color::Rgb(0,0,0), Color::Rgb(255,255,255), content))))
}