mirror of
https://codeberg.org/unspeaker/perch.git
synced 2025-12-07 01:56:45 +01:00
add stylers; dim column separators; shrink columns; refactor handlers
This commit is contained in:
parent
38f97558a7
commit
004cf96c2e
5 changed files with 70 additions and 43 deletions
|
|
@ -1,18 +1,20 @@
|
|||
use crate::*;
|
||||
use crate::ratatui::style::Style;
|
||||
|
||||
pub struct Column<G, S> {
|
||||
pub struct Column<G, S, U> {
|
||||
pub title: Arc<str>,
|
||||
pub width: usize,
|
||||
pub collapsed: bool,
|
||||
pub getter: G,
|
||||
pub setter: Option<S>,
|
||||
//pub styler: Option<U>,
|
||||
pub styler: Option<U>,
|
||||
}
|
||||
|
||||
type Getter<T> = fn(&T)->Option<Arc<str>>;
|
||||
type Setter<T> = fn(&mut T, usize, &str);
|
||||
type Styler<T> = fn(&T)->Option<Style>;
|
||||
|
||||
impl<G, S> Column<Getter<G>, Setter<S>> {
|
||||
impl<G, S, U> Column<Getter<G>, Setter<S>, Styler<U>> {
|
||||
pub fn new (
|
||||
title: &impl AsRef<str>,
|
||||
width: usize,
|
||||
|
|
@ -23,6 +25,7 @@ impl<G, S> Column<Getter<G>, Setter<S>> {
|
|||
title: title.as_ref().into(),
|
||||
getter,
|
||||
setter: None,
|
||||
styler: None,
|
||||
collapsed: false,
|
||||
}
|
||||
}
|
||||
|
|
@ -30,6 +33,10 @@ impl<G, S> Column<Getter<G>, Setter<S>> {
|
|||
self.setter = Some(setter);
|
||||
self
|
||||
}
|
||||
fn styler (mut self, styler: Styler<U>) -> Self {
|
||||
self.styler = Some(styler);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn entries_under (
|
||||
|
|
@ -56,7 +63,7 @@ pub(crate) fn entries_under (
|
|||
}
|
||||
}
|
||||
|
||||
pub struct Columns<G, S>(pub Vec<Column<G, S>>);
|
||||
pub struct Columns<G, S, U>(pub Vec<Column<G, S, U>>);
|
||||
|
||||
macro_rules! setter {
|
||||
($set:ident) => {{
|
||||
|
|
@ -82,7 +89,11 @@ macro_rules! setter {
|
|||
}}
|
||||
}
|
||||
|
||||
impl Default for Columns<fn(&Entry)->Option<Arc<str>>, fn(&mut Taggart, usize, &str)> {
|
||||
impl Default for Columns<
|
||||
fn(&Entry)->Option<Arc<str>>,
|
||||
fn(&mut Taggart, usize, &str),
|
||||
fn(&Entry)->Option<Style>,
|
||||
> {
|
||||
fn default () -> Self {
|
||||
Self(vec![
|
||||
// Computed file hash
|
||||
|
|
@ -92,18 +103,18 @@ impl Default for Columns<fn(&Entry)->Option<Arc<str>>, fn(&mut Taggart, usize, &
|
|||
// Selected?
|
||||
Column::new(&"∗", 1, |entry: &Entry|Some(" ".into())),
|
||||
// File name
|
||||
Column::new(&"File", 80, |entry: &Entry|entry.name()),
|
||||
Column::new(&"File", 40, |entry: &Entry|entry.name()),
|
||||
// Modified tags?
|
||||
Column::new(&"~", 1, |entry: &Entry|if entry.is_modified() {
|
||||
Some("~".into())
|
||||
} else {
|
||||
None
|
||||
}),
|
||||
Column::new(&"Artist", 30, |entry: &Entry|entry.artist()).setter(setter!(set_artist)),
|
||||
Column::new(&"Year", 5, |entry: &Entry|entry.year()).setter(setter!(set_year)),
|
||||
Column::new(&"Release", 30, |entry: &Entry|entry.album()).setter(setter!(set_album)),
|
||||
Column::new(&"Artist", 15, |entry: &Entry|entry.artist()).setter(setter!(set_artist)),
|
||||
Column::new(&"Year", 4, |entry: &Entry|entry.year()).setter(setter!(set_year)),
|
||||
Column::new(&"Release", 15, |entry: &Entry|entry.album()).setter(setter!(set_album)),
|
||||
Column::new(&"Track", 5, |entry: &Entry|entry.track()).setter(setter!(set_track)),
|
||||
Column::new(&"Title", 80, |entry: &Entry|entry.title()).setter(setter!(set_title)),
|
||||
Column::new(&"Title", 40, |entry: &Entry|entry.title()).setter(setter!(set_title)),
|
||||
])
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue