mirror of
https://codeberg.org/unspeaker/perch.git
synced 2025-12-06 17:46:42 +01:00
add hash column; update tengri
This commit is contained in:
parent
c3f826a7d4
commit
72bd6148d6
4 changed files with 46 additions and 32 deletions
|
|
@ -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) 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,
|
||||
|
|
|
|||
34
src/view.rs
34
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<TuiOut>) -> impl Content<TuiOut> {
|
||||
|
|
@ -20,7 +23,9 @@ impl Content<TuiOut> 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<TuiOut> 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue