mirror of
https://codeberg.org/unspeaker/perch.git
synced 2025-12-06 09:36:42 +01:00
wip: drawing table using Content::content
This commit is contained in:
parent
c3b9e0d9ec
commit
53132da551
5 changed files with 70 additions and 47 deletions
20
Cargo.lock
generated
20
Cargo.lock
generated
|
|
@ -479,9 +479,9 @@ checksum = "dd2e7510819d6fbf51a5545c8f922716ecfb14df168a3242f7d33e0239efe6a1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "file_type"
|
name = "file_type"
|
||||||
version = "0.7.6"
|
version = "0.8.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e29dcb4c86cc8aff2e79a382de1e7ee6c61e075a732ceb1ec43e81131d12175c"
|
checksum = "a2f41d9c0ff84ee5335227a501bfa01284d5fec029f504dc48bea8238a16ca04"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"phf",
|
"phf",
|
||||||
]
|
]
|
||||||
|
|
@ -1446,8 +1446,8 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tengri"
|
name = "tengri"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
source = "git+https://codeberg.org/unspeaker/tengri?rev=877b344765#877b3447653f69f951f3bc0dad57de82350d866b"
|
source = "git+https://codeberg.org/unspeaker/tengri?rev=10a2d17#10a2d17b487fb6a8690d807d7698f04da4267129"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"tengri_input",
|
"tengri_input",
|
||||||
"tengri_output",
|
"tengri_output",
|
||||||
|
|
@ -1456,18 +1456,18 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tengri_input"
|
name = "tengri_input"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
source = "git+https://codeberg.org/unspeaker/tengri?rev=877b344765#877b3447653f69f951f3bc0dad57de82350d866b"
|
source = "git+https://codeberg.org/unspeaker/tengri?rev=10a2d17#10a2d17b487fb6a8690d807d7698f04da4267129"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tengri_output"
|
name = "tengri_output"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
source = "git+https://codeberg.org/unspeaker/tengri?rev=877b344765#877b3447653f69f951f3bc0dad57de82350d866b"
|
source = "git+https://codeberg.org/unspeaker/tengri?rev=10a2d17#10a2d17b487fb6a8690d807d7698f04da4267129"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tengri_tui"
|
name = "tengri_tui"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
source = "git+https://codeberg.org/unspeaker/tengri?rev=877b344765#877b3447653f69f951f3bc0dad57de82350d866b"
|
source = "git+https://codeberg.org/unspeaker/tengri?rev=10a2d17#10a2d17b487fb6a8690d807d7698f04da4267129"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"atomic_float",
|
"atomic_float",
|
||||||
"better-panic",
|
"better-panic",
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,15 @@ name = "taggart"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies.tengri]
|
||||||
tengri = { git = "https://codeberg.org/unspeaker/tengri", rev = "877b344765" }
|
git = "https://codeberg.org/unspeaker/tengri"
|
||||||
|
rev = "10a2d17"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
clap = { version = "4.5.4", features = [ "cargo" ] }
|
clap = { version = "4.5.4", features = [ "cargo" ] }
|
||||||
enolib = { git = "https://codeberg.org/simonrepp/enolib-rs", tag = "0.5.0" }
|
enolib = { git = "https://codeberg.org/simonrepp/enolib-rs", tag = "0.5.0" }
|
||||||
byte-unit = "5.1.6"
|
byte-unit = "5.1.6"
|
||||||
file_type = "0.7"
|
file_type = "0.8"
|
||||||
hex = "0.4"
|
hex = "0.4"
|
||||||
id3 = "1.16"
|
id3 = "1.16"
|
||||||
lofty = "0.22.2"
|
lofty = "0.22.2"
|
||||||
|
|
|
||||||
|
|
@ -39,15 +39,17 @@ fn cli () -> clap::Command {
|
||||||
|
|
||||||
fn main () -> Usually<()> {
|
fn main () -> Usually<()> {
|
||||||
let args = cli().get_matches();
|
let args = cli().get_matches();
|
||||||
|
|
||||||
let path = if let Some(path) = args.get_one::<PathBuf>("path") {
|
let path = if let Some(path) = args.get_one::<PathBuf>("path") {
|
||||||
path.into()
|
path.into()
|
||||||
} else {
|
} else {
|
||||||
current_dir()?
|
current_dir()?
|
||||||
};
|
};
|
||||||
let threads = args.get_one::<usize>("threads").map(|x|*x).unwrap_or_default().max(1);
|
|
||||||
set_current_dir(&path)?;
|
set_current_dir(&path)?;
|
||||||
|
|
||||||
|
let threads = args.get_one::<usize>("threads").map(|x|*x).unwrap_or(4);
|
||||||
let results = collect(&path, threads)?;
|
let results = collect(&path, threads)?;
|
||||||
|
|
||||||
if let Ok(results) = Arc::try_unwrap(results) {
|
if let Ok(results) = Arc::try_unwrap(results) {
|
||||||
let mut results = results.into_inner()?;
|
let mut results = results.into_inner()?;
|
||||||
results.sort();
|
results.sort();
|
||||||
|
|
|
||||||
79
src/view.rs
79
src/view.rs
|
|
@ -18,39 +18,58 @@ impl Content<TuiOut> for Taggart {
|
||||||
struct TreeTable<'a>(&'a Taggart);
|
struct TreeTable<'a>(&'a Taggart);
|
||||||
|
|
||||||
impl<'a> Content<TuiOut> for TreeTable<'a> {
|
impl<'a> Content<TuiOut> for TreeTable<'a> {
|
||||||
fn render (&self, to: &mut TuiOut) {
|
fn content (&self) -> impl Render<TuiOut> {
|
||||||
let area = to.area();
|
|
||||||
let Taggart { offset, paths, cursor, column, .. } = self.0;
|
let Taggart { offset, paths, cursor, column, .. } = self.0;
|
||||||
let (x, w) = self.0.columns.xw(*column);
|
let mut dy = 0;
|
||||||
to.fill_bg([area.x() + x, area.y(), w, area.h()], Color::Rgb(0, 0, 0));
|
let offset = *offset;
|
||||||
for (i, y) in area.iter_y().enumerate() {
|
let height = self.0.size.h();
|
||||||
let i_offset = i + offset;
|
Map::new(
|
||||||
let selected = *cursor == i_offset;
|
move||offset..(offset + height),
|
||||||
if let Some(entry) = paths.get(i_offset) {
|
move|row, y: usize|{
|
||||||
for (index, _fragment) in entry.path.iter().enumerate() {
|
let mut dx = 0;
|
||||||
if index == entry.depth - 1 {
|
map_south(y as u16, 1, Map::new(
|
||||||
let _cursor = if selected { ">" } else { " " };
|
move||self.0.columns.0.iter(),
|
||||||
let label = self.0.columns.row_content(&entry);
|
move|column: &Column<_>, x: usize|{
|
||||||
Content::render(&label)
|
dx = dx + column.width;
|
||||||
to.blit(&label, area.x(), y, entry.style());
|
map_east((dx - column.width) as u16, 1, "test")
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//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 {
|
impl Entry {
|
||||||
|
|
|
||||||
|
|
@ -51,10 +51,10 @@ impl<T> Columns<T> {
|
||||||
pub fn row_content (&self, entry: &T) -> impl Content<TuiOut> where T: Send + Sync {
|
pub fn row_content (&self, entry: &T) -> impl Content<TuiOut> where T: Send + Sync {
|
||||||
Map::new(
|
Map::new(
|
||||||
||self.0.iter(),
|
||self.0.iter(),
|
||||||
|Column { width, value, .. }, index|map_east(
|
|&Column { width, ref value, .. }, index|map_east(
|
||||||
0u16,
|
0u16,
|
||||||
*width as u16,
|
width as u16,
|
||||||
value(entry).map(|x|TrimString(*width as u16, x))
|
value(entry).map(|x|TrimString(width as u16, x))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue