|
|
@ -25,7 +25,7 @@ use std::{
|
|
|
|
time::{Duration, Instant},
|
|
|
|
time::{Duration, Instant},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
use anyhow::Error;
|
|
|
|
use anyhow::{Context, Error};
|
|
|
|
|
|
|
|
|
|
|
|
use crossterm::{
|
|
|
|
use crossterm::{
|
|
|
|
event::{DisableMouseCapture, EnableMouseCapture, Event},
|
|
|
|
event::{DisableMouseCapture, EnableMouseCapture, Event},
|
|
|
@ -122,7 +122,7 @@ impl Application {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
let syn_loader = std::sync::Arc::new(syntax::Loader::new(syn_loader_conf));
|
|
|
|
let syn_loader = std::sync::Arc::new(syntax::Loader::new(syn_loader_conf));
|
|
|
|
|
|
|
|
|
|
|
|
let mut compositor = Compositor::new()?;
|
|
|
|
let mut compositor = Compositor::new().context("build compositor")?;
|
|
|
|
let config = Arc::new(ArcSwap::from_pointee(config));
|
|
|
|
let config = Arc::new(ArcSwap::from_pointee(config));
|
|
|
|
let mut editor = Editor::new(
|
|
|
|
let mut editor = Editor::new(
|
|
|
|
compositor.size(),
|
|
|
|
compositor.size(),
|
|
|
@ -141,26 +141,28 @@ impl Application {
|
|
|
|
|
|
|
|
|
|
|
|
if args.load_tutor {
|
|
|
|
if args.load_tutor {
|
|
|
|
let path = helix_loader::runtime_dir().join("tutor.txt");
|
|
|
|
let path = helix_loader::runtime_dir().join("tutor.txt");
|
|
|
|
editor.open(path, Action::VerticalSplit)?;
|
|
|
|
editor.open(&path, Action::VerticalSplit)?;
|
|
|
|
// Unset path to prevent accidentally saving to the original tutor file.
|
|
|
|
// Unset path to prevent accidentally saving to the original tutor file.
|
|
|
|
doc_mut!(editor).set_path(None)?;
|
|
|
|
doc_mut!(editor).set_path(None)?;
|
|
|
|
} else if !args.files.is_empty() {
|
|
|
|
} else if !args.files.is_empty() {
|
|
|
|
let first = &args.files[0].0; // we know it's not empty
|
|
|
|
let first = &args.files[0].0; // we know it's not empty
|
|
|
|
if first.is_dir() {
|
|
|
|
if first.is_dir() {
|
|
|
|
std::env::set_current_dir(&first)?;
|
|
|
|
std::env::set_current_dir(&first).context("set current dir")?;
|
|
|
|
editor.new_file(Action::VerticalSplit);
|
|
|
|
editor.new_file(Action::VerticalSplit);
|
|
|
|
let picker = ui::file_picker(".".into(), &config.load().editor);
|
|
|
|
let picker = ui::file_picker(".".into(), &config.load().editor);
|
|
|
|
compositor.push(Box::new(overlayed(picker)));
|
|
|
|
compositor.push(Box::new(overlayed(picker)));
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
let nr_of_files = args.files.len();
|
|
|
|
let nr_of_files = args.files.len();
|
|
|
|
editor.open(first.to_path_buf(), Action::VerticalSplit)?;
|
|
|
|
editor.open(first, Action::VerticalSplit)?;
|
|
|
|
for (file, pos) in args.files {
|
|
|
|
for (file, pos) in args.files {
|
|
|
|
if file.is_dir() {
|
|
|
|
if file.is_dir() {
|
|
|
|
return Err(anyhow::anyhow!(
|
|
|
|
return Err(anyhow::anyhow!(
|
|
|
|
"expected a path to file, found a directory. (to open a directory pass it as first argument)"
|
|
|
|
"expected a path to file, found a directory. (to open a directory pass it as first argument)"
|
|
|
|
));
|
|
|
|
));
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
let doc_id = editor.open(file, Action::Load)?;
|
|
|
|
let doc_id = editor
|
|
|
|
|
|
|
|
.open(&file, Action::Load)
|
|
|
|
|
|
|
|
.context(format!("open '{}'", file.to_string_lossy()))?;
|
|
|
|
// with Action::Load all documents have the same view
|
|
|
|
// with Action::Load all documents have the same view
|
|
|
|
let view_id = editor.tree.focus;
|
|
|
|
let view_id = editor.tree.focus;
|
|
|
|
let doc = editor.document_mut(doc_id).unwrap();
|
|
|
|
let doc = editor.document_mut(doc_id).unwrap();
|
|
|
@ -192,7 +194,8 @@ impl Application {
|
|
|
|
#[cfg(windows)]
|
|
|
|
#[cfg(windows)]
|
|
|
|
let signals = futures_util::stream::empty();
|
|
|
|
let signals = futures_util::stream::empty();
|
|
|
|
#[cfg(not(windows))]
|
|
|
|
#[cfg(not(windows))]
|
|
|
|
let signals = Signals::new(&[signal::SIGTSTP, signal::SIGCONT])?;
|
|
|
|
let signals =
|
|
|
|
|
|
|
|
Signals::new(&[signal::SIGTSTP, signal::SIGCONT]).context("build signal handler")?;
|
|
|
|
|
|
|
|
|
|
|
|
let app = Self {
|
|
|
|
let app = Self {
|
|
|
|
compositor,
|
|
|
|
compositor,
|
|
|
|