add hash column; update tengri

This commit is contained in:
🪞👃🪞 2025-03-04 00:52:14 +02:00
parent c3f826a7d4
commit 72bd6148d6
4 changed files with 46 additions and 32 deletions

32
Cargo.lock generated
View file

@ -801,9 +801,9 @@ dependencies = [
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.93" version = "1.0.94"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99" checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
@ -825,9 +825,9 @@ dependencies = [
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.38" version = "1.0.39"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" checksum = "c1f1914ce909e1658d9907913b4b91947430c7d9be598b15a1912935b8c04801"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
] ]
@ -894,9 +894,9 @@ dependencies = [
[[package]] [[package]]
name = "redox_syscall" name = "redox_syscall"
version = "0.5.9" version = "0.5.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82b568323e98e49e2a0899dcee453dd679fae22d69adf9b11dd508d1549b7e2f" checksum = "0b8c0c260b63a8219631167be35e6a988e9554dbd323f8bd08439c8ed1302bd1"
dependencies = [ dependencies = [
"bitflags", "bitflags",
] ]
@ -1036,9 +1036,9 @@ dependencies = [
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.98" version = "2.0.99"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36147f1a48ae0ec2b5b3bc5b537d267457555a10dc06f3dbc8cb11ba3006d3b1" checksum = "e02e925281e18ffd9d640e234264753c43edc62d64b2d4cf898f1bc5e75f3fc2"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1065,7 +1065,7 @@ dependencies = [
[[package]] [[package]]
name = "tek_edn" name = "tek_edn"
version = "0.1.0" version = "0.1.0"
source = "git+https://codeberg.org/unspeaker/tengri#09ad6dc9f1e94fdf1f8314e5b54c245e878cb598" source = "git+https://codeberg.org/unspeaker/tengri#5352a9d5484198e35760d62a2cd6ef202990fb2c"
dependencies = [ dependencies = [
"itertools 0.14.0", "itertools 0.14.0",
"konst", "konst",
@ -1075,7 +1075,7 @@ dependencies = [
[[package]] [[package]]
name = "tek_input" name = "tek_input"
version = "0.2.0" version = "0.2.0"
source = "git+https://codeberg.org/unspeaker/tengri#09ad6dc9f1e94fdf1f8314e5b54c245e878cb598" source = "git+https://codeberg.org/unspeaker/tengri#5352a9d5484198e35760d62a2cd6ef202990fb2c"
dependencies = [ dependencies = [
"tek_edn", "tek_edn",
] ]
@ -1083,7 +1083,7 @@ dependencies = [
[[package]] [[package]]
name = "tek_output" name = "tek_output"
version = "0.2.0" version = "0.2.0"
source = "git+https://codeberg.org/unspeaker/tengri#09ad6dc9f1e94fdf1f8314e5b54c245e878cb598" source = "git+https://codeberg.org/unspeaker/tengri#5352a9d5484198e35760d62a2cd6ef202990fb2c"
dependencies = [ dependencies = [
"tek_edn", "tek_edn",
] ]
@ -1091,7 +1091,7 @@ dependencies = [
[[package]] [[package]]
name = "tek_tui" name = "tek_tui"
version = "0.2.0" version = "0.2.0"
source = "git+https://codeberg.org/unspeaker/tengri#09ad6dc9f1e94fdf1f8314e5b54c245e878cb598" source = "git+https://codeberg.org/unspeaker/tengri#5352a9d5484198e35760d62a2cd6ef202990fb2c"
dependencies = [ dependencies = [
"atomic_float", "atomic_float",
"better-panic", "better-panic",
@ -1108,18 +1108,18 @@ dependencies = [
[[package]] [[package]]
name = "thiserror" name = "thiserror"
version = "2.0.11" version = "2.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d452f284b73e6d76dd36758a0c8684b1d5be31f92b89d07fd5822175732206fc" checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708"
dependencies = [ dependencies = [
"thiserror-impl", "thiserror-impl",
] ]
[[package]] [[package]]
name = "thiserror-impl" name = "thiserror-impl"
version = "2.0.11" version = "2.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26afc1baea8a989337eeb52b6e72a039780ce45c3edfcc9c5b9d112feeb173c2" checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",

View file

@ -4,7 +4,8 @@ version = "0.1.0"
edition = "2024" edition = "2024"
[dependencies] [dependencies]
tek_tui = { git = "https://codeberg.org/unspeaker/tengri", ref = "47b3413" } tek_tui = { git = "https://codeberg.org/unspeaker/tengri", ref = "5352a9d" }
clap = { version = "4.5.4", features = [ "cargo" ] } clap = { version = "4.5.4", features = [ "cargo" ] }
walkdir = "2" walkdir = "2"
id3 = "1.16" id3 = "1.16"

View file

@ -24,8 +24,8 @@ pub(crate) type Usually<T> = std::result::Result<T, Box<dyn std::error::Error>>;
pub(crate) type Perhaps<T> = Usually<Option<T>>; pub(crate) type Perhaps<T> = Usually<Option<T>>;
pub(crate) const PAGE_SIZE: usize = 10; pub(crate) const PAGE_SIZE: usize = 10;
pub(crate) const COLUMN_COUNT: usize = 5; pub(crate) const COLUMN_COUNT: usize = 6;
pub(crate) const COLUMN_WIDTHS: [u16; COLUMN_COUNT] = [60, 20, 20, 5, 20]; pub(crate) const COLUMN_WIDTHS: [u16; COLUMN_COUNT] = [16, 60, 20, 20, 5, 20];
fn cli () -> clap::Command { fn cli () -> clap::Command {
command!() command!()
@ -111,6 +111,7 @@ impl Taggart {
} }
let depth = entry.depth(); let depth = entry.depth();
let path = entry.into_path(); let path = entry.into_path();
let short_path: PathBuf = path.strip_prefix(&root)?.into();
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() {
(Some(Default::default()), None, None, None, None) (Some(Default::default()), None, None, None, None)
} else { } else {
@ -126,11 +127,11 @@ impl Taggart {
Some(&"image/png") => Some(Default::default()), Some(&"image/png") => Some(Default::default()),
_ => None, _ => None,
}; };
println!("{hash} {file_type:?} ({}b)\n{}\n", bytes.len(), path.display()); println!("{hash} {:>10}b {}", bytes.len(), short_path.display());
(None, 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: short_path,
is_dir, is_dir,
is_mus, is_mus,
is_img, is_img,

View file

@ -2,13 +2,16 @@ use crate::*;
use tek_tui::ratatui::{style::{Color, Style}, prelude::Stylize}; use tek_tui::ratatui::{style::{Color, Style}, prelude::Stylize};
use pad::PadStr; use pad::PadStr;
fn table_row (label: &str, artist: &str, album: &str, track: &str, title: &str) -> String { fn table_row (
let label = label.pad_to_width(COLUMN_WIDTHS[0] as usize); hash: Option<&str>, label: &str, artist: &str, album: &str, track: &str, title: &str
let artist = artist.pad_to_width(COLUMN_WIDTHS[1] as usize); ) -> String {
let album = album.pad_to_width(COLUMN_WIDTHS[2] as usize); let hash = hash.unwrap_or("").pad_to_width(COLUMN_WIDTHS[0] as usize);
let track = track.pad_to_width(COLUMN_WIDTHS[3] as usize); let label = label.pad_to_width(COLUMN_WIDTHS[1] as usize);
let title = title.pad_to_width(COLUMN_WIDTHS[4] as usize); let artist = artist.pad_to_width(COLUMN_WIDTHS[2] as usize);
format!("{label}{artist}{album}{track}{title}") 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> { fn status_bar (content: impl Content<TuiOut>) -> impl Content<TuiOut> {
@ -20,7 +23,9 @@ impl Content<TuiOut> for Taggart {
let sizer = Fill::xy(&self.size); let sizer = Fill::xy(&self.size);
let size = format!("{}x{}", self.size.w(), self.size.h()); let size = format!("{}x{}", self.size.w(), self.size.h());
let size_bar = status_bar(Align::e(size)); let size_bar = status_bar(Align::e(size));
let titlebar = status_bar(Align::w(table_row("FILE", "ARTIST", "RELEASE", "TRACK", "TITLE"))); let titlebar = status_bar(Align::w(table_row(
Some("HASH"), "FILE", "ARTIST", "RELEASE", "TRACK", "TITLE"
)));
let table = Fill::xy(TreeTable(self)); let table = Fill::xy(TreeTable(self));
Bsp::n(size_bar, Bsp::s(titlebar, Bsp::b(sizer, table))) Bsp::n(size_bar, Bsp::s(titlebar, Bsp::b(sizer, table)))
} }
@ -65,12 +70,19 @@ impl<'a> Content<TuiOut> for TreeTable<'a> {
}; };
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(
entry.hash.as_deref(),
&format!("{indent}{icon} {name}"),
"",
"",
"",
""
);
to.blit(&label, area.x(), y, style); to.blit(&label, area.x(), y, style);
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_fg(fill, Color::Rgb(0, 0, 0));
to.fill_fg(fill, Color::Rgb(224, 192, 0)); to.fill_bg(fill, Color::Rgb(224, 192, 0));
} }
} }
} }