move trimmed strings to tengri

This commit is contained in:
🪞👃🪞 2025-03-18 01:19:10 +02:00
parent c67d3c8803
commit 6e0bf1e4b6
7 changed files with 135 additions and 200 deletions

View file

@ -1,10 +1,9 @@
use crate::*;
use tengri::tui::ratatui::{style::{Color, Style}, prelude::Stylize};
use std::sync::atomic::{AtomicU16, Ordering::Relaxed};
pub(crate) use tengri::tui::ratatui::style::Color;//, Style}, prelude::Stylize};
pub(crate) use pad::PadStr;
mod column; pub use self::column::*;
mod string; pub use self::string::*;
mod status; pub use self::status::*;
mod table; pub use self::table::*;
impl Content<TuiOut> for Taggart {
fn content (&self) -> impl Render<TuiOut> {
@ -16,51 +15,6 @@ impl Content<TuiOut> for Taggart {
}
}
struct TreeTable<'a>(&'a Taggart);
impl<'a> Content<TuiOut> for TreeTable<'a> {
fn render (&self, to: &mut TuiOut) {
let area = to.area();
let Taggart { offset, paths, cursor, column, .. } = self.0;
let (x, w) = self.0.columns.xw(*column);
to.fill_bg([area.x() + x, area.y(), w, area.h()], Color::Rgb(0, 0, 0));
for (i, y) in area.iter_y().enumerate() {
let i_offset = i + offset;
let selected = *cursor == i_offset;
let mut x = area.x();
if let Some(entry) = paths.get(i_offset) {
for (index, _fragment) in entry.path.iter().enumerate() {
if index == entry.depth - 1 {
let _cursor = if selected { ">" } else { " " };
to.area[1] = y;
for Column { width, value, .. } in self.0.columns.0.iter() {
to.area[0] = x;
if let Some(value) = value(entry) {
Content::render(&TrimStringRef(*width as u16, &value), to);
}
x += *width as u16;
}
if selected {
let fill = [area.x(), y, area.w(), 1];
to.fill_fg(fill, Color::Rgb(0, 0, 0));
to.fill_bg(fill, Color::Rgb(192, 128, 0));
let fill = [area.x() + x as u16, y, w, 1];
to.fill_bg(fill, Color::Rgb(224, 192, 0));
if let Some((_index, value)) = &self.0.editing {
let x = area.x() + if x > 0 { x + 1 } else { x } as u16;
to.blit(&value, x, y, None)
}
}
}
}
} else {
break
}
}
to.area = area;
}
}
impl Entry {
pub fn name (&self) -> Option<Arc<str>> {
let indent = "".pad_to_width((self.depth - 1) * 2);
@ -79,15 +33,11 @@ impl Entry {
""
}
}
fn style (&self) -> Option<Style> {
if self.is_dir() {
None
} else {
Some(Style::default().bold())
}
}
}
fn status_bar (content: impl Content<TuiOut>) -> impl Content<TuiOut> {
Fixed::y(1, Fill::x(Tui::bold(true, Tui::fg_bg(Color::Rgb(0,0,0), Color::Rgb(255,255,255), content))))
//fn style (&self) -> Option<Style> {
//if self.is_dir() {
//None
//} else {
//Some(Style::default().bold())
//}
//}
}