open files with space

This commit is contained in:
🪞👃🪞 2025-03-09 04:47:44 +02:00
parent 8cc9418272
commit 41c5686d67
5 changed files with 137 additions and 33 deletions

View file

@ -2,7 +2,7 @@
use std::sync::{Arc, RwLock};
use std::path::{Path, PathBuf};
use std::env::current_dir;
use std::env::{current_dir, set_current_dir};
use std::fs::read;
use tek_tui::*;
@ -30,34 +30,23 @@ fn cli () -> clap::Command {
}
fn main () -> Usually<()> {
let args = cli().get_matches();
let path = args.get_one::<PathBuf>("path");
let state = Arc::new(RwLock::new(Taggart::new(path)?));
let args = cli().get_matches();
let path = if let Some(path) = args.get_one::<PathBuf>("path") {
path.into()
} else {
current_dir()?
};
set_current_dir(&path);
let state = Arc::new(RwLock::new(Taggart::new(&path)?));
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()
} else {
current_dir()?
};
fn new (root: &impl AsRef<Path>) -> Usually<Self> {
Ok(Self {
paths: Self::collect(&root)?,
root,
root: root.as_ref().into(),
paths: Self::collect(root)?,
cursor: 0,
offset: 0,
column: 0,