2020-06-02 03:57:01 +02:00
|
|
|
#![allow(unused)]
|
2020-09-19 16:16:00 +02:00
|
|
|
|
2020-10-16 05:29:22 +02:00
|
|
|
mod application;
|
2020-12-10 10:13:42 +01:00
|
|
|
mod commands;
|
2020-12-06 03:53:58 +01:00
|
|
|
mod compositor;
|
2020-12-10 10:13:42 +01:00
|
|
|
mod keymap;
|
2020-12-13 05:35:30 +01:00
|
|
|
mod ui;
|
2020-05-20 11:14:51 +02:00
|
|
|
|
2020-10-16 05:29:22 +02:00
|
|
|
use application::Application;
|
2020-05-20 11:14:51 +02:00
|
|
|
|
2020-06-02 03:57:01 +02:00
|
|
|
use std::path::PathBuf;
|
2020-05-20 11:14:51 +02:00
|
|
|
|
2020-05-25 06:02:21 +02:00
|
|
|
use anyhow::Error;
|
2020-05-20 11:14:51 +02:00
|
|
|
|
2020-10-23 07:33:09 +02:00
|
|
|
fn setup_logging(verbosity: u64) -> Result<(), fern::InitError> {
|
|
|
|
let mut base_config = fern::Dispatch::new();
|
|
|
|
|
|
|
|
// Let's say we depend on something which whose "info" level messages are too
|
|
|
|
// verbose to include in end-user output. If we don't need them,
|
|
|
|
// let's not include them.
|
|
|
|
// .level_for("overly-verbose-target", log::LevelFilter::Warn)
|
|
|
|
|
|
|
|
base_config = match verbosity {
|
|
|
|
0 => base_config.level(log::LevelFilter::Warn),
|
|
|
|
1 => base_config.level(log::LevelFilter::Info),
|
|
|
|
2 => base_config.level(log::LevelFilter::Debug),
|
|
|
|
_3_or_more => base_config.level(log::LevelFilter::Trace),
|
|
|
|
};
|
|
|
|
|
2021-02-19 08:48:51 +01:00
|
|
|
let home = dirs_next::home_dir().expect("can't find the home directory");
|
|
|
|
|
2020-10-23 07:33:09 +02:00
|
|
|
// Separate file config so we can include year, month and day in file logs
|
|
|
|
let file_config = fern::Dispatch::new()
|
|
|
|
.format(|out, message, record| {
|
|
|
|
out.finish(format_args!(
|
|
|
|
"{} {} [{}] {}",
|
|
|
|
chrono::Local::now().format("%Y-%m-%dT%H:%M:%S%.3f"),
|
|
|
|
record.target(),
|
|
|
|
record.level(),
|
|
|
|
message
|
|
|
|
))
|
|
|
|
})
|
2021-02-19 08:48:51 +01:00
|
|
|
.chain(fern::log_file(home.join("helix.log"))?);
|
2020-10-23 07:33:09 +02:00
|
|
|
|
|
|
|
base_config.chain(file_config).apply()?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2021-05-31 10:07:43 +02:00
|
|
|
pub struct Args {
|
|
|
|
files: Vec<PathBuf>,
|
|
|
|
}
|
|
|
|
|
2021-01-08 08:31:19 +01:00
|
|
|
fn main() {
|
2021-05-31 10:07:43 +02:00
|
|
|
let help = format!(
|
|
|
|
"\
|
|
|
|
{} {}
|
|
|
|
{}
|
|
|
|
{}
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
hx [FLAGS] [files]...
|
|
|
|
|
|
|
|
ARGS:
|
|
|
|
<files>... Sets the input file to use
|
|
|
|
|
|
|
|
FLAGS:
|
|
|
|
-h, --help Prints help information
|
|
|
|
-v Increases logging verbosity each use for up to 3 times
|
|
|
|
-V, --version Prints version information
|
|
|
|
",
|
|
|
|
env!("CARGO_PKG_NAME"),
|
|
|
|
env!("CARGO_PKG_VERSION"),
|
|
|
|
env!("CARGO_PKG_AUTHORS"),
|
|
|
|
env!("CARGO_PKG_DESCRIPTION"),
|
|
|
|
);
|
|
|
|
|
|
|
|
let mut pargs = pico_args::Arguments::from_env();
|
|
|
|
|
|
|
|
// Help has a higher priority and should be handled separately.
|
|
|
|
if pargs.contains(["-h", "--help"]) {
|
|
|
|
print!("{}", help);
|
|
|
|
std::process::exit(0);
|
|
|
|
}
|
|
|
|
|
2021-05-31 10:14:49 +02:00
|
|
|
let mut verbosity: u64 = 0;
|
2021-05-31 10:07:43 +02:00
|
|
|
|
2021-05-31 10:14:49 +02:00
|
|
|
if pargs.contains("-v") {
|
|
|
|
verbosity = 1;
|
|
|
|
}
|
2020-10-23 07:33:09 +02:00
|
|
|
|
|
|
|
setup_logging(verbosity).expect("failed to initialize logging.");
|
|
|
|
|
2021-05-31 10:14:49 +02:00
|
|
|
let args = Args {
|
|
|
|
files: pargs.finish().into_iter().map(|arg| arg.into()).collect(),
|
|
|
|
};
|
|
|
|
|
2021-03-25 07:26:25 +01:00
|
|
|
// initialize language registry
|
2021-04-07 16:56:20 +02:00
|
|
|
use helix_core::config_dir;
|
2021-03-25 07:26:25 +01:00
|
|
|
use helix_core::syntax::{Loader, LOADER};
|
2021-04-07 16:56:20 +02:00
|
|
|
|
|
|
|
// load $HOME/.config/helix/languages.toml, fallback to default config
|
|
|
|
let config = std::fs::read(config_dir().join("languages.toml"));
|
|
|
|
let toml = config
|
|
|
|
.as_deref()
|
|
|
|
.unwrap_or(include_bytes!("../../languages.toml"));
|
|
|
|
|
2021-03-25 07:26:25 +01:00
|
|
|
LOADER.get_or_init(|| {
|
2021-04-07 16:56:20 +02:00
|
|
|
let config = toml::from_slice(toml).expect("Could not parse languages.toml");
|
2021-03-25 07:26:25 +01:00
|
|
|
Loader::new(config)
|
|
|
|
});
|
|
|
|
|
2021-05-06 06:56:34 +02:00
|
|
|
let runtime = tokio::runtime::Runtime::new().unwrap();
|
2020-09-04 11:18:40 +02:00
|
|
|
|
2021-05-06 06:56:34 +02:00
|
|
|
// TODO: use the thread local executor to spawn the application task separately from the work pool
|
|
|
|
runtime.block_on(async move {
|
|
|
|
let mut app = Application::new(args).unwrap();
|
2020-10-18 11:01:06 +02:00
|
|
|
|
2021-05-06 06:56:34 +02:00
|
|
|
app.run().await;
|
|
|
|
});
|
2020-05-20 11:14:51 +02:00
|
|
|
}
|