2020-12-13 05:35:30 +01:00
|
|
|
mod editor;
|
2021-02-09 07:40:30 +01:00
|
|
|
mod menu;
|
2020-12-17 10:08:16 +01:00
|
|
|
mod picker;
|
2021-02-25 10:07:47 +01:00
|
|
|
mod popup;
|
2020-12-13 05:35:30 +01:00
|
|
|
mod prompt;
|
|
|
|
|
|
|
|
pub use editor::EditorView;
|
2021-02-09 07:40:30 +01:00
|
|
|
pub use menu::Menu;
|
2020-12-17 10:08:16 +01:00
|
|
|
pub use picker::Picker;
|
2021-02-25 10:07:47 +01:00
|
|
|
pub use popup::Popup;
|
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};
|
|
|
|
|
2021-01-22 09:13:14 +01:00
|
|
|
use helix_core::regex::Regex;
|
|
|
|
use helix_view::{Document, Editor};
|
|
|
|
|
2020-12-13 05:35:30 +01:00
|
|
|
// 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
|
|
|
|
2021-01-22 09:13:14 +01:00
|
|
|
pub fn regex_prompt(
|
|
|
|
cx: &mut crate::commands::Context,
|
|
|
|
prompt: String,
|
|
|
|
fun: impl Fn(&mut Document, Regex) + 'static,
|
|
|
|
) -> Prompt {
|
|
|
|
let snapshot = cx.doc().state.clone();
|
|
|
|
|
|
|
|
Prompt::new(
|
|
|
|
prompt,
|
|
|
|
|input: &str| Vec::new(), // this is fine because Vec::new() doesn't allocate
|
|
|
|
move |editor: &mut Editor, input: &str, event: PromptEvent| {
|
|
|
|
match event {
|
|
|
|
PromptEvent::Abort => {
|
|
|
|
// revert state
|
|
|
|
let doc = &mut editor.view_mut().doc;
|
|
|
|
doc.state = snapshot.clone();
|
|
|
|
}
|
|
|
|
PromptEvent::Validate => {
|
|
|
|
//
|
|
|
|
}
|
|
|
|
PromptEvent::Update => {
|
|
|
|
match Regex::new(input) {
|
|
|
|
Ok(regex) => {
|
2021-02-12 10:10:05 +01:00
|
|
|
let view = &mut editor.view_mut();
|
|
|
|
let doc = &mut view.doc;
|
2021-01-22 09:13:14 +01:00
|
|
|
|
|
|
|
// revert state to what it was before the last update
|
|
|
|
doc.state = snapshot.clone();
|
|
|
|
|
|
|
|
fun(doc, regex);
|
2021-02-12 10:10:05 +01:00
|
|
|
|
|
|
|
view.ensure_cursor_in_view();
|
2021-01-22 09:13:14 +01:00
|
|
|
}
|
|
|
|
Err(_err) => (), // TODO: mark command line as error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-12-21 08:23:05 +01:00
|
|
|
use std::path::{Path, PathBuf};
|
2021-01-21 08:55:46 +01:00
|
|
|
pub fn file_picker(root: &str, ex: &'static smol::Executor) -> Picker<PathBuf> {
|
2020-12-18 11:19:50 +01:00
|
|
|
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
|
2020-12-21 09:58:54 +01:00
|
|
|
path.strip_prefix("./").unwrap().to_str().unwrap().into()
|
2020-12-18 11:19:50 +01:00
|
|
|
},
|
2021-01-21 08:55:46 +01:00
|
|
|
move |editor: &mut Editor, path: &PathBuf| {
|
2021-02-03 11:36:54 +01:00
|
|
|
editor.open(path.into(), ex);
|
2020-12-18 11:19:50 +01:00
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
2020-12-21 08:23:05 +01:00
|
|
|
|
|
|
|
use helix_view::View;
|
|
|
|
pub fn buffer_picker(views: &[View], current: usize) -> Picker<(Option<PathBuf>, usize)> {
|
2021-02-03 11:36:54 +01:00
|
|
|
unimplemented!();
|
|
|
|
// use helix_view::Editor;
|
|
|
|
// Picker::new(
|
|
|
|
// views
|
|
|
|
// .iter()
|
|
|
|
// .enumerate()
|
|
|
|
// .map(|(i, view)| (view.doc.relative_path().map(Path::to_path_buf), i))
|
|
|
|
// .collect(),
|
|
|
|
// move |(path, index): &(Option<PathBuf>, usize)| {
|
|
|
|
// // format_fn
|
|
|
|
// match path {
|
|
|
|
// Some(path) => {
|
|
|
|
// if *index == current {
|
|
|
|
// format!("{} (*)", path.to_str().unwrap()).into()
|
|
|
|
// } else {
|
|
|
|
// path.to_str().unwrap().into()
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// None => "[NEW]".into(),
|
|
|
|
// }
|
|
|
|
// },
|
|
|
|
// |editor: &mut Editor, &(_, index): &(Option<PathBuf>, usize)| {
|
|
|
|
// if index < editor.views.len() {
|
|
|
|
// editor.focus = index;
|
|
|
|
// }
|
|
|
|
// },
|
|
|
|
// )
|
2020-12-21 08:23:05 +01:00
|
|
|
}
|