mirror of
https://codeberg.org/unspeaker/perch.git
synced 2025-12-06 17:46:42 +01:00
dynamic columns; macro keydefs
This commit is contained in:
parent
b29511c23e
commit
8cc9418272
6 changed files with 113 additions and 147 deletions
28
src/main.rs
28
src/main.rs
|
|
@ -16,15 +16,13 @@ use xxhash_rust::xxh3::xxh3_64;
|
|||
use file_type::FileType;
|
||||
|
||||
mod keys;
|
||||
mod view;
|
||||
mod view; use self::view::*;
|
||||
mod model; pub(crate) use self::model::*;
|
||||
|
||||
pub(crate) type Usually<T> = std::result::Result<T, Box<dyn std::error::Error>>;
|
||||
pub(crate) type Perhaps<T> = Usually<Option<T>>;
|
||||
|
||||
pub(crate) const PAGE_SIZE: usize = 10;
|
||||
pub(crate) const COLUMN_COUNT: usize = 6;
|
||||
pub(crate) const COLUMN_WIDTHS: [u16; COLUMN_COUNT] = [16, 60, 20, 20, 5, 20];
|
||||
|
||||
fn cli () -> clap::Command {
|
||||
command!()
|
||||
|
|
@ -38,7 +36,19 @@ fn main () -> Usually<()> {
|
|||
Tui::new()?.run(&state)
|
||||
}
|
||||
|
||||
pub struct Taggart {
|
||||
pub root: PathBuf,
|
||||
pub paths: Vec<Entry>,
|
||||
pub cursor: usize,
|
||||
pub offset: usize,
|
||||
pub column: usize,
|
||||
pub columns: Columns<Entry>,
|
||||
pub size: Measure<TuiOut>,
|
||||
pub editing: Option<(usize, usize)>,
|
||||
}
|
||||
|
||||
impl Taggart {
|
||||
|
||||
fn new (root: Option<&impl AsRef<Path>>) -> Usually<Self> {
|
||||
let root = if let Some(root) = root {
|
||||
root.as_ref().into()
|
||||
|
|
@ -48,14 +58,15 @@ impl Taggart {
|
|||
Ok(Self {
|
||||
paths: Self::collect(&root)?,
|
||||
root,
|
||||
cursor: 0,
|
||||
offset: 0,
|
||||
column: 0,
|
||||
size: Measure::new(),
|
||||
cursor: 0,
|
||||
offset: 0,
|
||||
column: 0,
|
||||
size: Measure::new(),
|
||||
editing: None,
|
||||
show_hash: false,
|
||||
columns: Columns::default(),
|
||||
})
|
||||
}
|
||||
|
||||
fn collect (root: &impl AsRef<Path>) -> Usually<Vec<Entry>> {
|
||||
let mut paths = vec![];
|
||||
for entry in WalkDir::new(&root).into_iter()
|
||||
|
|
@ -72,4 +83,5 @@ impl Taggart {
|
|||
paths.sort();
|
||||
Ok(paths)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue