mirror of https://github.com/bobwen-dev/hunter
find files
This commit is contained in:
parent
7fc77f8605
commit
184f4916d3
|
@ -59,13 +59,6 @@ impl FileBrowser {
|
|||
miller.set_coordinates(&coords);
|
||||
|
||||
|
||||
// let lists: Result<Vec<ListView<Files>>, Box<Error>> = cwd
|
||||
// .ancestors()
|
||||
// .map(|path| Ok(ListView::new(Files::new_from_path(path)?)))
|
||||
// .take(2)
|
||||
// .collect();
|
||||
// let mut lists = lists?;
|
||||
// lists.reverse();
|
||||
let (left_coords, main_coords, _) = miller.calculate_coordinates();
|
||||
|
||||
let main_path: std::path::PathBuf = cwd.ancestors().take(1).map(|path| std::path::PathBuf::from(path)).collect();
|
||||
|
@ -90,9 +83,6 @@ impl FileBrowser {
|
|||
miller.push_widget(left_widget);
|
||||
miller.push_widget(main_widget);
|
||||
|
||||
// for widget in lists {
|
||||
// miller.push_widget(widget);
|
||||
// }
|
||||
|
||||
let cwd = File::new_from_path(&cwd).unwrap();
|
||||
|
||||
|
@ -100,11 +90,6 @@ impl FileBrowser {
|
|||
cwd: cwd };
|
||||
|
||||
|
||||
|
||||
//file_browser.fix_selection();
|
||||
//file_browser.animate_columns();
|
||||
//file_browser.update_preview();
|
||||
|
||||
Ok(file_browser)
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ use std::io::Write;
|
|||
|
||||
use crate::coordinates::{Coordinates, Position, Size};
|
||||
use crate::files::{File, Files};
|
||||
use crate::fail::HResult;
|
||||
use crate::term;
|
||||
use crate::widget::{Widget};
|
||||
|
||||
|
@ -41,7 +42,8 @@ impl Listable for ListView<Files> {
|
|||
Key::Down | Key::Char('n') => {
|
||||
self.move_down();
|
||||
self.refresh();
|
||||
}
|
||||
},
|
||||
Key::Ctrl('s') => { self.find_file().ok(); }
|
||||
Key::Left => self.goto_grand_parent(),
|
||||
Key::Right => self.goto_selected(),
|
||||
Key::Char(' ') => self.multi_select_file(),
|
||||
|
@ -381,6 +383,20 @@ impl ListView<Files>
|
|||
}
|
||||
}
|
||||
|
||||
fn find_file(&mut self) -> HResult<()> {
|
||||
let name = self.minibuffer("find")?;
|
||||
let file = self.content.files.iter().find(|file| {
|
||||
if file.name.to_lowercase().contains(&name) {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
})?.clone();
|
||||
|
||||
self.select_file(&file);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn render(&self) -> Vec<String> {
|
||||
let ysize = self.get_coordinates().ysize() as usize;
|
||||
let offset = self.offset;
|
||||
|
|
Loading…
Reference in New Issue