perch/src/view.rs

61 lines
2.2 KiB
Rust

use crate::*;
pub(crate) use tengri::tui::ratatui::style::Color;//, Style}, prelude::Stylize};
pub(crate) use pad::PadStr;
mod status; pub use self::status::*;
mod table; pub use self::table::*;
impl Taggart {
pub(crate) const FG_BROWSE: Color = Color::Rgb(255, 192, 0);
pub(crate) const BG_BROWSE: Color = Color::Rgb(0, 0, 0);
pub(crate) const BG_EDIT: Color = Color::Rgb(48, 128, 0);
pub(crate) const FG_EDIT: Color = Color::Rgb(255, 255, 255);
}
impl Content<TuiOut> for Taggart {
fn content (&self) -> impl Render<TuiOut> {
let sizer = Fill::xy(&self.display);
let size = format!("{}x{}", self.display.w(), self.display.h());
let titlebar = status_bar(Align::w(self.columns.header()));
let size_bar = status_bar(Fill::x(Bsp::a(
Fill::x(Align::w(Tui::bold(true, if self.editing.is_some() {
Bsp::e(
Tui::bg(Self::BG_EDIT, Tui::fg(Self::FG_EDIT, " EDIT ")),
" Esc: cancel, Enter: set value"
)
} else {
Bsp::e(
Tui::bg(Self::BG_BROWSE, Tui::fg(Self::FG_BROWSE, " BROWSE ")),
" Q: exit, Arrows: select, Enter: edit"
)
}))),
Fill::x(Align::e(size)),
)));
Bsp::n(size_bar, Bsp::s(titlebar, Bsp::b(sizer, Fill::xy(TreeTable(self)))))
}
}
impl Entry {
pub const ICON_DIRECTORY: &'static str = "";
pub const ICON_IMAGE: &'static str = "󰋩";
pub const ICON_MUSIC: &'static str = "";
pub const ICON_MUSIC_NO_META: &'static str = "󰎇";
pub const ICON_UNKNOWN: &'static str = "";
pub fn name (&self) -> Option<Arc<str>> {
let indent = "".pad_to_width((self.depth - 1) * 2);
let icon = self.icon();
let name = self.path.iter().last().expect("empty path").display();
Some(format!("{indent}{icon} {name}").into())
}
fn icon (&self) -> &'static str {
if self.is_dir() {
Self::ICON_DIRECTORY
} else if self.is_img() {
Self::ICON_IMAGE
} else if self.is_mus() {
Self::ICON_MUSIC
} else {
Self::ICON_UNKNOWN
}
}
}