summaryrefslogtreecommitdiff
path: root/helix-term/src/ui/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'helix-term/src/ui/mod.rs')
-rw-r--r--helix-term/src/ui/mod.rs28
1 files changed, 26 insertions, 2 deletions
diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs
index b778f531..f9480dd4 100644
--- a/helix-term/src/ui/mod.rs
+++ b/helix-term/src/ui/mod.rs
@@ -15,7 +15,7 @@ pub fn text_color() -> Style {
Style::default().fg(Color::Rgb(219, 191, 239)) // lilac
}
-use std::path::PathBuf;
+use std::path::{Path, PathBuf};
pub fn file_picker(root: &str) -> Picker<PathBuf> {
use ignore::Walk;
// TODO: determine root based on git root
@@ -38,7 +38,7 @@ pub fn file_picker(root: &str) -> Picker<PathBuf> {
files.take(MAX).collect(),
|path: &PathBuf| {
// format_fn
- path.strip_prefix("./").unwrap().to_str().unwrap() // TODO: render paths without ./
+ path.strip_prefix("./").unwrap().to_str().unwrap()
},
|editor: &mut Editor, path: &PathBuf| {
let size = editor.view().unwrap().size;
@@ -46,3 +46,27 @@ pub fn file_picker(root: &str) -> Picker<PathBuf> {
},
)
}
+
+use helix_view::View;
+pub fn buffer_picker(views: &[View], current: usize) -> Picker<(Option<PathBuf>, usize)> {
+ use helix_view::Editor;
+ Picker::new(
+ views
+ .iter()
+ .enumerate()
+ .map(|(i, view)| (view.doc.relative_path().map(Path::to_path_buf), i))
+ .collect(),
+ |(path, index): &(Option<PathBuf>, usize)| {
+ // format_fn
+ match path {
+ Some(path) => path.to_str().unwrap(),
+ None => "[NEW]",
+ }
+ },
+ |editor: &mut Editor, &(_, index): &(Option<PathBuf>, usize)| {
+ if index < editor.views.len() {
+ editor.focus = index;
+ }
+ },
+ )
+}