mod app;
mod clipboard;
mod config;
mod editor;
mod filesystem;
mod input;
mod renderer;
mod search;
mod syntax;
mod theme;
mod ui;
mod undo;
use std::path::PathBuf;
use std::process::ExitCode;
use anyhow::Result;
const USAGE: &str = "\
termi — a terminal code editor
USAGE:
termi [OPTIONS] [FILE]...
OPTIONS:
-h, --help Print this message
-V, --version Print the version
Configuration lives in <config-dir>/termi/config.toml, and themes in
<config-dir>/termi/themes/<name>.toml.";
fn main() -> ExitCode {
match parse_arguments() {
Arguments::Help => {
println!("{USAGE}");
ExitCode::SUCCESS
}
Arguments::Version => {
println!("termi {}", env!("CARGO_PKG_VERSION"));
ExitCode::SUCCESS
}
Arguments::Open(files) => match edit(files) {
Ok(()) => ExitCode::SUCCESS,
Err(error) => {
eprintln!("termi: {error:#}");
ExitCode::FAILURE
}
},
}
}
enum Arguments {
Help,
Version,
Open(Vec<PathBuf>),
}
fn parse_arguments() -> Arguments {
let mut files = Vec::new();
for argument in std::env::args_os().skip(1) {
match argument.to_str() {
Some("-h" | "--help") => return Arguments::Help,
Some("-V" | "--version") => return Arguments::Version,
_ => files.push(PathBuf::from(argument)),
}
}
Arguments::Open(files)
}
fn edit(files: Vec<PathBuf>) -> Result<()> {
renderer::install_panic_hook();
let mut editor = app::App::new();
for file in files {
if let Err(error) = editor.open(file) {
editor.error(error.to_string());
}
}
let mut tui = renderer::Tui::new()?;
let result = app::run(&mut editor, &mut tui);
drop(tui);
result
}