perch/src/view.rs

96 lines
3.1 KiB
Rust

use crate::*;
pub(crate) use tengri::tui::ratatui::style::Color;//, Style}, prelude::Stylize};
pub(crate) use pad::PadStr;
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 size = format!("{}x{}", self.display.w(), self.display.h());
let sizer = Fill::xy(&self.display);
let titlebar = status_bar(
Color::Rgb(0, 0, 0),
Color::Rgb(192, 192, 192),
Align::w(self.columns.header())
);
let value_bar = status_bar(
Color::Rgb(192, 192, 192),
Color::Rgb(0, 0, 0),
Fill::x(Align::w(format!(
" {}/{} {}:",
self.cursor + 1,
self.entries.len(),
self.columns.0[self.column].title
)))
);
let mode_bar = status_bar(
Color::Rgb(0, 0, 0),
Color::Rgb(192, 192, 192),
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, Space: open, Enter: edit"
)
}))),
Fill::x(Align::e(size)),
))
);
Bsp::n(
value_bar,
Bsp::n(
mode_bar,
Bsp::s(
titlebar,
Bsp::b(
sizer,
Fill::xy(TreeTable(self))
)
)
)
)
}
}
pub fn status_bar (
fg: Color, bg: Color, content: impl Content<TuiOut>
) -> impl Content<TuiOut> {
Fixed::y(1, Fill::x(Tui::bold(true, Tui::fg_bg(fg, bg, content))))
}
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
}
}
}