use libc::termios as Termios;
use std::{
io::Stdout,
sync::{OnceLock, RwLock},
};
pub mod buffer;
pub mod config;
pub mod dot;
pub mod editor;
pub mod exec;
pub mod fsys;
pub mod ftype;
pub mod key;
pub mod mode;
pub mod regex;
pub mod term;
pub mod trie;
pub mod util;
pub use buffer::GapBuffer;
pub use config::Config;
pub use editor::Editor;
pub use exec::{CachedStdin, Edit, Program};
use term::{disable_alternate_screen, disable_mouse_support, set_termios};
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub const UNNAMED_BUFFER: &str = "[No Name]";
pub const MAX_NAME_LEN: usize = 20;
pub(crate) static ORIGINAL_TERMIOS: OnceLock<Termios> = OnceLock::new();
pub(crate) static CONFIG: OnceLock<RwLock<Config>> = OnceLock::new();
pub(crate) fn set_config(cfg: Config) {
_ = CONFIG.set(RwLock::new(cfg));
}
pub(crate) fn replace_config(cfg: Config) {
*CONFIG
.get_or_init(|| RwLock::new(Config::default()))
.write()
.unwrap() = cfg;
}
pub(crate) fn update_config(input: &str) -> Result<(), String> {
let mut guard = CONFIG
.get_or_init(|| RwLock::new(Config::default()))
.write()
.unwrap();
guard.try_set_prop(input)
}
#[macro_export]
macro_rules! config {
() => {{
$crate::CONFIG
.get_or_init(|| std::sync::RwLock::new($crate::Config::default()))
.read()
.unwrap()
}};
}
#[macro_export]
macro_rules! die {
($template:expr $(, $arg:expr)*) => {{
$crate::restore_terminal_state(&mut ::std::io::stdout());
panic!($template $(, $arg)*)
}};
}
pub(crate) fn restore_terminal_state(so: &mut Stdout) {
disable_alternate_screen(so);
disable_mouse_support(so);
set_termios(*ORIGINAL_TERMIOS.get().unwrap());
}