mirror of
https://codeberg.org/unspeaker/perch.git
synced 2025-12-06 17:46:42 +01:00
open files with space
This commit is contained in:
parent
8cc9418272
commit
41c5686d67
5 changed files with 137 additions and 33 deletions
101
Cargo.lock
generated
101
Cargo.lock
generated
|
|
@ -125,6 +125,17 @@ version = "2.9.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd"
|
||||
|
||||
[[package]]
|
||||
name = "bstr"
|
||||
version = "1.11.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "531a9155a481e2ee699d4f98f43c0ca4ff8ee1bfd55c31e9e98fb29d2b176fe0"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.17.0"
|
||||
|
|
@ -158,6 +169,15 @@ dependencies = [
|
|||
"rustversion",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.2.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "be714c154be609ec7f5dad223a33bf1482fff90472de28f7362806e6d4832b8c"
|
||||
dependencies = [
|
||||
"shlex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
|
|
@ -313,6 +333,17 @@ dependencies = [
|
|||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dbus"
|
||||
version = "0.9.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1bb21987b9fb1613058ba3843121dd18b163b254d8a6e797e144cbac14d96d1b"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"libdbus-sys",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.14.0"
|
||||
|
|
@ -527,6 +558,16 @@ version = "0.2.170"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "875b3680cb2f8f71bdcf9a30f38d48282f5d3c95cbf9b3fa57269bb5d5c06828"
|
||||
|
||||
[[package]]
|
||||
name = "libdbus-sys"
|
||||
version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06085512b750d640299b79be4bad3d2fa90a9c00b1fd9e1b46364f66f0485c72"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.4.15"
|
||||
|
|
@ -607,6 +648,15 @@ dependencies = [
|
|||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "normpath"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c8911957c4b1549ac0dc74e30db9c8b0e66ddcd6d7acc33098f4c63a64a6d7ed"
|
||||
dependencies = [
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.19"
|
||||
|
|
@ -631,6 +681,18 @@ version = "1.20.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "945462a4b81e43c4e3ba96bd7b49d834c6f61198356aa858733bc4acf3cbe62e"
|
||||
|
||||
[[package]]
|
||||
name = "opener"
|
||||
version = "0.7.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d0812e5e4df08da354c851a3376fead46db31c2214f849d3de356d774d057681"
|
||||
dependencies = [
|
||||
"bstr",
|
||||
"dbus",
|
||||
"normpath",
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pad"
|
||||
version = "0.1.6"
|
||||
|
|
@ -736,6 +798,12 @@ dependencies = [
|
|||
"siphasher",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pkg-config"
|
||||
version = "0.3.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.20"
|
||||
|
|
@ -847,6 +915,12 @@ dependencies = [
|
|||
"bitflags",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
|
||||
|
||||
[[package]]
|
||||
name = "rustc-demangle"
|
||||
version = "0.1.24"
|
||||
|
|
@ -893,6 +967,32 @@ version = "1.2.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.218"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e8dfc9d19bdbf6d17e22319da49161d5d0108e4188e8b680aef6299eed22df60"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.218"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f09503e191f4e797cb8aac08e9a4a4695c5edf6a2e70e376d961ddd5c969f82b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||
|
||||
[[package]]
|
||||
name = "signal-hook"
|
||||
version = "0.3.17"
|
||||
|
|
@ -989,6 +1089,7 @@ dependencies = [
|
|||
"hex",
|
||||
"id3",
|
||||
"moku",
|
||||
"opener",
|
||||
"pad",
|
||||
"tek_tui",
|
||||
"unicode-width 0.2.0",
|
||||
|
|
|
|||
|
|
@ -17,3 +17,4 @@ hex = "0.4"
|
|||
xxhash-rust = { version = "0.8.5", features = ["xxh3"] }
|
||||
#base64 = "0.22"
|
||||
unicode-width = "0.2"
|
||||
opener = "0.7"
|
||||
|
|
|
|||
22
src/keys.rs
22
src/keys.rs
|
|
@ -1,9 +1,10 @@
|
|||
use crate::*;
|
||||
use opener::open;
|
||||
|
||||
macro_rules! press {
|
||||
($key:tt) => {
|
||||
($($key:tt)+) => {
|
||||
Event::Key(KeyEvent {
|
||||
code: KeyCode::$key,
|
||||
code: KeyCode::$($key)+,
|
||||
kind: KeyEventKind::Press,
|
||||
modifiers: KeyModifiers::NONE,
|
||||
state: KeyEventState::NONE
|
||||
|
|
@ -16,14 +17,15 @@ impl Handle<TuiIn> for Taggart {
|
|||
let x_min = self.offset;
|
||||
let x_max = self.offset + self.size.h().saturating_sub(1);
|
||||
match &*input.event() {
|
||||
press!(Up) => { self.cursor = self.cursor.saturating_sub(1); },
|
||||
press!(Down) => { self.cursor = self.cursor + 1; },
|
||||
press!(PageUp) => { self.cursor = self.cursor.saturating_sub(PAGE_SIZE); },
|
||||
press!(PageDown) => { self.cursor += PAGE_SIZE; },
|
||||
press!(Left) => { self.column = self.column.saturating_sub(1); },
|
||||
press!(Right) => { self.column = self.column + 1; },
|
||||
press!(Enter) => { self.editing = Some((self.cursor, self.column)); },
|
||||
press!(Esc) => { self.editing = None; },
|
||||
press!(Up) => { self.cursor = self.cursor.saturating_sub(1); },
|
||||
press!(Down) => { self.cursor = self.cursor + 1; },
|
||||
press!(PageUp) => { self.cursor = self.cursor.saturating_sub(PAGE_SIZE); },
|
||||
press!(PageDown) => { self.cursor += PAGE_SIZE; },
|
||||
press!(Left) => { self.column = self.column.saturating_sub(1); },
|
||||
press!(Right) => { self.column = self.column + 1; },
|
||||
press!(Enter) => { self.editing = Some((self.cursor, self.column)); },
|
||||
press!(Esc) => { self.editing = None; },
|
||||
press!(Char(' ')) => { open(&self.paths[self.cursor].path)?; }
|
||||
_ => {}
|
||||
}
|
||||
if self.cursor < x_min {
|
||||
|
|
|
|||
35
src/main.rs
35
src/main.rs
|
|
@ -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,
|
||||
|
|
|
|||
11
src/model.rs
11
src/model.rs
|
|
@ -3,6 +3,17 @@ use walkdir::DirEntry;
|
|||
use id3::{Tag, TagLike};
|
||||
use std::io::Read;
|
||||
|
||||
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)>,
|
||||
}
|
||||
|
||||
#[derive(Ord, Eq, PartialEq, PartialOrd)]
|
||||
pub struct Entry {
|
||||
pub path: PathBuf,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue