2020-12-13 05:35:30 +01:00
|
|
|
mod editor;
|
2020-12-17 10:08:16 +01:00
|
|
|
mod picker;
|
2020-12-13 05:35:30 +01:00
|
|
|
mod prompt;
|
|
|
|
|
|
|
|
pub use editor::EditorView;
|
2020-12-17 10:08:16 +01:00
|
|
|
pub use picker::Picker;
|
2020-12-15 11:29:56 +01:00
|
|
|
pub use prompt::{Prompt, PromptEvent};
|
2020-12-13 05:35:30 +01:00
|
|
|
|
|
|
|
pub use tui::layout::Rect;
|
|
|
|
pub use tui::style::{Color, Modifier, Style};
|
|
|
|
|
|
|
|
// TODO: temp
|
|
|
|
#[inline(always)]
|
|
|
|
pub fn text_color() -> Style {
|
|
|
|
Style::default().fg(Color::Rgb(219, 191, 239)) // lilac
|
|
|
|
}
|
2020-12-18 11:19:50 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|