2022-01-18 09:48:28 +01:00
|
|
|
mod config_files;
|
|
|
|
mod eval_file;
|
|
|
|
mod logger;
|
|
|
|
mod prompt_update;
|
|
|
|
mod reedline_config;
|
|
|
|
mod repl;
|
|
|
|
mod utils;
|
|
|
|
|
2021-08-10 20:57:08 +02:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests;
|
|
|
|
|
2022-01-18 09:48:28 +01:00
|
|
|
use miette::Result;
|
|
|
|
use nu_command::create_default_context;
|
|
|
|
use std::sync::{
|
|
|
|
atomic::{AtomicBool, Ordering},
|
|
|
|
Arc,
|
|
|
|
};
|
2021-10-02 15:10:28 +02:00
|
|
|
|
2021-09-20 23:37:26 +02:00
|
|
|
fn main() -> Result<()> {
|
2021-11-14 20:25:57 +01:00
|
|
|
// miette::set_panic_hook();
|
2021-10-01 18:39:50 +02:00
|
|
|
let miette_hook = std::panic::take_hook();
|
|
|
|
std::panic::set_hook(Box::new(move |x| {
|
2021-12-04 13:38:21 +01:00
|
|
|
crossterm::terminal::disable_raw_mode().expect("unable to disable raw mode");
|
2021-10-01 18:39:50 +02:00
|
|
|
miette_hook(x);
|
|
|
|
}));
|
2021-09-21 21:37:16 +02:00
|
|
|
|
2022-01-04 23:30:34 +01:00
|
|
|
// Get initial current working directory.
|
2022-01-18 09:48:28 +01:00
|
|
|
let init_cwd = utils::get_init_cwd();
|
2022-01-04 23:30:34 +01:00
|
|
|
let mut engine_state = create_default_context(&init_cwd);
|
2021-07-17 08:31:34 +02:00
|
|
|
|
2022-01-24 16:05:19 +01:00
|
|
|
// Custom additions
|
|
|
|
let delta = {
|
|
|
|
let mut working_set = nu_protocol::engine::StateWorkingSet::new(&engine_state);
|
|
|
|
working_set.add_decl(Box::new(nu_cli::NuHighlight));
|
|
|
|
|
|
|
|
working_set.render()
|
|
|
|
};
|
|
|
|
let _ = engine_state.merge_delta(delta, None, &init_cwd);
|
|
|
|
|
2021-10-28 06:13:10 +02:00
|
|
|
// TODO: make this conditional in the future
|
|
|
|
// Ctrl-c protection section
|
|
|
|
let ctrlc = Arc::new(AtomicBool::new(false));
|
|
|
|
let handler_ctrlc = ctrlc.clone();
|
|
|
|
let engine_state_ctrlc = ctrlc.clone();
|
|
|
|
|
|
|
|
ctrlc::set_handler(move || {
|
|
|
|
handler_ctrlc.store(true, Ordering::SeqCst);
|
|
|
|
})
|
|
|
|
.expect("Error setting Ctrl-C handler");
|
|
|
|
|
|
|
|
engine_state.ctrlc = Some(engine_state_ctrlc);
|
|
|
|
// End ctrl-c protection section
|
|
|
|
|
2021-07-22 08:04:50 +02:00
|
|
|
if let Some(path) = std::env::args().nth(1) {
|
2022-01-18 09:48:28 +01:00
|
|
|
eval_file::evaluate(path, init_cwd, &mut engine_state)
|
2021-06-30 03:42:56 +02:00
|
|
|
} else {
|
2022-01-18 09:48:28 +01:00
|
|
|
repl::evaluate(ctrlc, &mut engine_state)
|
2022-01-04 23:30:34 +01:00
|
|
|
}
|
|
|
|
}
|