wip: drawing table using Content::content

This commit is contained in:
🪞👃🪞 2025-03-17 02:33:43 +02:00
parent c3b9e0d9ec
commit 53132da551
5 changed files with 70 additions and 47 deletions

View file

@ -39,15 +39,17 @@ fn cli () -> clap::Command {
fn main () -> Usually<()> {
let args = cli().get_matches();
let path = if let Some(path) = args.get_one::<PathBuf>("path") {
path.into()
} else {
current_dir()?
};
let threads = args.get_one::<usize>("threads").map(|x|*x).unwrap_or_default().max(1);
set_current_dir(&path)?;
let threads = args.get_one::<usize>("threads").map(|x|*x).unwrap_or(4);
let results = collect(&path, threads)?;
if let Ok(results) = Arc::try_unwrap(results) {
let mut results = results.into_inner()?;
results.sort();

View file

@ -18,39 +18,58 @@ 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();
fn content (&self) -> impl Render<TuiOut> {
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;
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 { " " };
let label = self.0.columns.row_content(&entry);
Content::render(&label)
to.blit(&label, area.x(), y, entry.style());
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)
}
}
let mut dy = 0;
let offset = *offset;
let height = self.0.size.h();
Map::new(
move||offset..(offset + height),
move|row, y: usize|{
let mut dx = 0;
map_south(y as u16, 1, Map::new(
move||self.0.columns.0.iter(),
move|column: &Column<_>, x: usize|{
dx = dx + column.width;
map_east((dx - column.width) as u16, 1, "test")
}
}
} else {
break
}
}
))
})
}
//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;
////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 { " " };
////let label = self.0.columns.row_content(&entry);
//////Content::render(&label)
////to.blit(&label, area.x(), y, entry.style());
////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
////}
////}
//}
}
impl Entry {

View file

@ -51,10 +51,10 @@ impl<T> Columns<T> {
pub fn row_content (&self, entry: &T) -> impl Content<TuiOut> where T: Send + Sync {
Map::new(
||self.0.iter(),
|Column { width, value, .. }, index|map_east(
|&Column { width, ref value, .. }, index|map_east(
0u16,
*width as u16,
value(entry).map(|x|TrimString(*width as u16, x))
width as u16,
value(entry).map(|x|TrimString(width as u16, x))
)
)
}