From 72bd6148d61e6955f998d90eac704a857ed2fa27 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Tue, 4 Mar 2025 00:52:14 +0200 Subject: [PATCH] add hash column; update tengri --- Cargo.lock | 32 ++++++++++++++++---------------- Cargo.toml | 3 ++- src/main.rs | 9 +++++---- src/view.rs | 34 +++++++++++++++++++++++----------- 4 files changed, 46 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a33caaa..e617395 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -801,9 +801,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.93" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99" +checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84" dependencies = [ "unicode-ident", ] @@ -825,9 +825,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.38" +version = "1.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" +checksum = "c1f1914ce909e1658d9907913b4b91947430c7d9be598b15a1912935b8c04801" dependencies = [ "proc-macro2", ] @@ -894,9 +894,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.9" +version = "0.5.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82b568323e98e49e2a0899dcee453dd679fae22d69adf9b11dd508d1549b7e2f" +checksum = "0b8c0c260b63a8219631167be35e6a988e9554dbd323f8bd08439c8ed1302bd1" dependencies = [ "bitflags", ] @@ -1036,9 +1036,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.98" +version = "2.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36147f1a48ae0ec2b5b3bc5b537d267457555a10dc06f3dbc8cb11ba3006d3b1" +checksum = "e02e925281e18ffd9d640e234264753c43edc62d64b2d4cf898f1bc5e75f3fc2" dependencies = [ "proc-macro2", "quote", @@ -1065,7 +1065,7 @@ dependencies = [ [[package]] name = "tek_edn" version = "0.1.0" -source = "git+https://codeberg.org/unspeaker/tengri#09ad6dc9f1e94fdf1f8314e5b54c245e878cb598" +source = "git+https://codeberg.org/unspeaker/tengri#5352a9d5484198e35760d62a2cd6ef202990fb2c" dependencies = [ "itertools 0.14.0", "konst", @@ -1075,7 +1075,7 @@ dependencies = [ [[package]] name = "tek_input" version = "0.2.0" -source = "git+https://codeberg.org/unspeaker/tengri#09ad6dc9f1e94fdf1f8314e5b54c245e878cb598" +source = "git+https://codeberg.org/unspeaker/tengri#5352a9d5484198e35760d62a2cd6ef202990fb2c" dependencies = [ "tek_edn", ] @@ -1083,7 +1083,7 @@ dependencies = [ [[package]] name = "tek_output" version = "0.2.0" -source = "git+https://codeberg.org/unspeaker/tengri#09ad6dc9f1e94fdf1f8314e5b54c245e878cb598" +source = "git+https://codeberg.org/unspeaker/tengri#5352a9d5484198e35760d62a2cd6ef202990fb2c" dependencies = [ "tek_edn", ] @@ -1091,7 +1091,7 @@ dependencies = [ [[package]] name = "tek_tui" version = "0.2.0" -source = "git+https://codeberg.org/unspeaker/tengri#09ad6dc9f1e94fdf1f8314e5b54c245e878cb598" +source = "git+https://codeberg.org/unspeaker/tengri#5352a9d5484198e35760d62a2cd6ef202990fb2c" dependencies = [ "atomic_float", "better-panic", @@ -1108,18 +1108,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.11" +version = "2.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d452f284b73e6d76dd36758a0c8684b1d5be31f92b89d07fd5822175732206fc" +checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "2.0.11" +version = "2.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26afc1baea8a989337eeb52b6e72a039780ce45c3edfcc9c5b9d112feeb173c2" +checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 7281639..7592725 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,8 @@ version = "0.1.0" edition = "2024" [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" ] } walkdir = "2" id3 = "1.16" diff --git a/src/main.rs b/src/main.rs index 3ab9d61..986b905 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,8 +24,8 @@ pub(crate) type Usually = std::result::Result>; pub(crate) type Perhaps = Usually>; pub(crate) const PAGE_SIZE: usize = 10; -pub(crate) const COLUMN_COUNT: usize = 5; -pub(crate) const COLUMN_WIDTHS: [u16; COLUMN_COUNT] = [60, 20, 20, 5, 20]; +pub(crate) const COLUMN_COUNT: usize = 6; +pub(crate) const COLUMN_WIDTHS: [u16; COLUMN_COUNT] = [16, 60, 20, 20, 5, 20]; fn cli () -> clap::Command { command!() @@ -111,6 +111,7 @@ impl Taggart { } let depth = entry.depth(); 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() { (Some(Default::default()), None, None, None, None) } else { @@ -126,11 +127,11 @@ impl Taggart { Some(&"image/png") => Some(Default::default()), _ => 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)) }; paths.push(Entry { - path: path.strip_prefix(&root)?.into(), + path: short_path, is_dir, is_mus, is_img, diff --git a/src/view.rs b/src/view.rs index acdb128..c2f3e4a 100644 --- a/src/view.rs +++ b/src/view.rs @@ -2,13 +2,16 @@ use crate::*; use tek_tui::ratatui::{style::{Color, Style}, prelude::Stylize}; use pad::PadStr; -fn table_row (label: &str, artist: &str, album: &str, track: &str, title: &str) -> String { - let label = label.pad_to_width(COLUMN_WIDTHS[0] as usize); - let artist = artist.pad_to_width(COLUMN_WIDTHS[1] as usize); - let album = album.pad_to_width(COLUMN_WIDTHS[2] as usize); - let track = track.pad_to_width(COLUMN_WIDTHS[3] as usize); - let title = title.pad_to_width(COLUMN_WIDTHS[4] as usize); - format!("{label}│{artist}╎{album}╎{track}╎{title}") +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) -> impl Content { @@ -20,7 +23,9 @@ impl Content for Taggart { let sizer = Fill::xy(&self.size); 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("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)); Bsp::n(size_bar, Bsp::s(titlebar, Bsp::b(sizer, table))) } @@ -65,12 +70,19 @@ impl<'a> Content for TreeTable<'a> { }; let name = fragment.display(); 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); if selected { let fill = [area.x(), y, area.w(), 1]; - to.fill_bg(fill, Color::Rgb(48, 48, 48)); - to.fill_fg(fill, Color::Rgb(224, 192, 0)); + to.fill_fg(fill, Color::Rgb(0, 0, 0)); + to.fill_bg(fill, Color::Rgb(224, 192, 0)); } } }