summaryrefslogtreecommitdiff
path: root/helix-term/src/ui/mod.rs
diff options
context:
space:
mode:
authorBlaž Hrastnik2020-12-18 10:24:50 +0000
committerGitHub2020-12-18 10:24:50 +0000
commit3f0dbfcac878131167953b6f57c923a5bc889e80 (patch)
tree41b876f9bb067e5f199fe53ecb78eeb57d09719b /helix-term/src/ui/mod.rs
parentb12a6dc8303bbc1b4b08a9abb4668741d154adbd (diff)
parent25aa45e76c9bec62f36a59768298e1f2ea2678bf (diff)
Merge pull request #7 from helix-editor/interactive-split-select
File picker/interactive split prompt
Diffstat (limited to 'helix-term/src/ui/mod.rs')
-rw-r--r--helix-term/src/ui/mod.rs36
1 files changed, 35 insertions, 1 deletions
diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs
index bc79e09c..b778f531 100644
--- a/helix-term/src/ui/mod.rs
+++ b/helix-term/src/ui/mod.rs
@@ -1,8 +1,10 @@
mod editor;
+mod picker;
mod prompt;
pub use editor::EditorView;
-pub use prompt::Prompt;
+pub use picker::Picker;
+pub use prompt::{Prompt, PromptEvent};
pub use tui::layout::Rect;
pub use tui::style::{Color, Modifier, Style};
@@ -12,3 +14,35 @@ pub use tui::style::{Color, Modifier, Style};
pub fn text_color() -> Style {
Style::default().fg(Color::Rgb(219, 191, 239)) // lilac
}
+
+use std::path::PathBuf;
+pub fn file_picker(root: &str) -> Picker<PathBuf> {
+ use ignore::Walk;
+ // TODO: determine root based on git root
+ let files = Walk::new(root).filter_map(|entry| match entry {
+ Ok(entry) => {
+ // filter dirs, but we might need special handling for symlinks!
+ if !entry.file_type().unwrap().is_dir() {
+ Some(entry.into_path())
+ } else {
+ None
+ }
+ }
+ Err(_err) => None,
+ });
+
+ const MAX: usize = 1024;
+
+ use helix_view::Editor;
+ Picker::new(
+ files.take(MAX).collect(),
+ |path: &PathBuf| {
+ // format_fn
+ path.strip_prefix("./").unwrap().to_str().unwrap() // TODO: render paths without ./
+ },
+ |editor: &mut Editor, path: &PathBuf| {
+ let size = editor.view().unwrap().size;
+ editor.open(path.into(), size);
+ },
+ )
+}