-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b326e0b
commit 4292573
Showing
19 changed files
with
347 additions
and
84 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,10 @@ | ||
- separate event loop from tui | ||
- translate events into actions inside the event handler loop | ||
- have a dedicated rendering loop that can own the tui | ||
- | ||
|
||
|
||
|
||
|
||
## feature ideas | ||
- environment variables | ||
- aliases | ||
- shell history | ||
- grep (maybe also inside pdfs and other files (see rga)) | ||
- fd | ||
- recent directories | ||
- git | ||
- makefile commands | ||
- [x] environment variables | ||
- [ ] aliases | ||
- [ ] shell history | ||
- [ ] grep (maybe also inside pdfs and other files (see rga)) | ||
- [ ] fd | ||
- [ ] recent directories | ||
- [ ] git | ||
- [ ] makefile commands | ||
- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use color_eyre::Result; | ||
|
||
use crate::cli::UnitTvChannel; | ||
use crate::components::finders::Entry; | ||
use crate::components::pickers::{self, Picker}; | ||
use crate::components::previewers; | ||
|
||
pub enum TvChannel { | ||
Env(pickers::env::EnvVarPicker), | ||
Files(pickers::files::FilePicker), | ||
} | ||
|
||
impl TvChannel { | ||
pub fn load_entries(&mut self, pattern: &str) -> Result<()> { | ||
match self { | ||
TvChannel::Env(picker) => picker.load_entries(pattern), | ||
TvChannel::Files(picker) => picker.load_entries(pattern), | ||
} | ||
} | ||
|
||
pub fn entries(&self) -> &Vec<Entry> { | ||
match self { | ||
TvChannel::Env(picker) => picker.entries(), | ||
TvChannel::Files(picker) => picker.entries(), | ||
} | ||
} | ||
|
||
pub fn clear(&mut self) { | ||
match self { | ||
TvChannel::Env(picker) => picker.clear(), | ||
TvChannel::Files(picker) => picker.clear(), | ||
} | ||
} | ||
|
||
pub fn get_preview(&mut self, entry: &Entry) -> previewers::Preview { | ||
match self { | ||
TvChannel::Env(picker) => picker.get_preview(entry), | ||
TvChannel::Files(picker) => picker.get_preview(entry), | ||
} | ||
} | ||
} | ||
|
||
pub fn get_tv_channel(channel: UnitTvChannel) -> TvChannel { | ||
match channel { | ||
UnitTvChannel::ENV => TvChannel::Env(pickers::env::EnvVarPicker::new()), | ||
UnitTvChannel::FILES => TvChannel::Files(pickers::files::FilePicker::new()), | ||
_ => unimplemented!(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
use std::{ | ||
collections::HashMap, | ||
path::{Path, PathBuf}, | ||
}; | ||
|
||
use fuzzy_matcher::skim::SkimMatcherV2; | ||
use ignore::{types::TypesBuilder, WalkBuilder}; | ||
use tracing::info; | ||
|
||
use crate::{ | ||
components::finders::{Entry, Finder}, | ||
config::default_num_threads, | ||
}; | ||
|
||
pub struct FileFinder { | ||
current_directory: PathBuf, | ||
files: Vec<PathBuf>, | ||
matcher: SkimMatcherV2, | ||
cache: HashMap<String, Vec<Entry>>, | ||
} | ||
|
||
impl FileFinder { | ||
pub fn new() -> Self { | ||
let files = load_files(&std::env::current_dir().unwrap()); | ||
FileFinder { | ||
current_directory: std::env::current_dir().unwrap(), | ||
files, | ||
matcher: SkimMatcherV2::default(), | ||
cache: HashMap::new(), | ||
} | ||
} | ||
} | ||
|
||
impl Finder for FileFinder { | ||
fn find(&mut self, pattern: &str) -> impl Iterator<Item = Entry> { | ||
let mut results: Vec<Entry> = Vec::new(); | ||
// try to get from cache | ||
if let Some(entries) = self.cache.get(pattern) { | ||
results.extend(entries.iter().cloned()); | ||
} else { | ||
for file in &self.files { | ||
let file_name = file.file_name().unwrap().to_string_lossy().to_string(); | ||
if !pattern.is_empty() { | ||
if let Some((score, indices)) = self.matcher.fuzzy(&file_name, pattern, true) { | ||
results.push(Entry { | ||
name: file_name.clone(), | ||
display_name: None, | ||
preview: None, | ||
score, | ||
name_match_ranges: Some(indices.iter().map(|i| (*i, *i + 1)).collect()), | ||
preview_match_ranges: None, | ||
icon: None, | ||
line_number: None, | ||
}); | ||
} | ||
} | ||
} | ||
self.cache.insert(pattern.to_string(), results.clone()); | ||
} | ||
results.into_iter() | ||
} | ||
} | ||
|
||
const DEFAULT_RECV_TIMEOUT: std::time::Duration = std::time::Duration::from_millis(250); | ||
|
||
fn load_files(path: &Path) -> Vec<PathBuf> { | ||
let (tx, rx) = std::sync::mpsc::channel(); | ||
let walker = walk_builder(path, default_num_threads().into()).build_parallel(); | ||
walker.run(|| { | ||
let tx = tx.clone(); | ||
Box::new(move |result| { | ||
if let Ok(entry) = result { | ||
info!("found file: {:?}", entry.path()); | ||
if entry.file_type().unwrap().is_file() { | ||
tx.send(entry.path().to_path_buf()).unwrap(); | ||
} | ||
ignore::WalkState::Continue | ||
} else { | ||
ignore::WalkState::Continue | ||
} | ||
}) | ||
}); | ||
|
||
let mut files = Vec::new(); | ||
while let Ok(file) = rx.recv_timeout(DEFAULT_RECV_TIMEOUT) { | ||
files.push(file); | ||
} | ||
files | ||
} | ||
|
||
fn walk_builder(path: &Path, n_threads: usize) -> WalkBuilder { | ||
let mut builder = WalkBuilder::new(path); | ||
|
||
// ft-based filtering | ||
let mut types_builder = TypesBuilder::new(); | ||
types_builder.add_defaults(); | ||
builder.types(types_builder.build().unwrap()); | ||
|
||
builder.threads(n_threads); | ||
builder | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.