diff --git a/CHANGES.md b/CHANGES.md index 691daf4..bce4b33 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,7 +3,7 @@ CHANGES Next Release -- +- Add `omit_term_stderr` to the config to disable unnecessary backend terminal output to the stderr. 1.5.0 diff --git a/config.yml b/config.yml index 77d767f..daf4ec3 100644 --- a/config.yml +++ b/config.yml @@ -39,3 +39,6 @@ # when 'load_term_conf' is true. #term_config_path: /path/to/config.toml +# Set to true to redirect the backend terminal error output to null device. +# Avoid annoying harmless terminal error logs being printed all the time. +#omit_term_stderr: false diff --git a/src/backend/alacritty.rs b/src/backend/alacritty.rs index 76164b7..3cff9ef 100644 --- a/src/backend/alacritty.rs +++ b/src/backend/alacritty.rs @@ -193,15 +193,10 @@ mod tests { #[test] fn test_create_basic_alacritty_conf() { let conf = config::Config { - fork: false, backend: Some(config::Backend::Alacritty), - term_exe_path: None, - term_config_path: None, - exe_path: None, - nvim_exe_path: "nvim".to_owned(), font_size: 14, fonts: vec!["test_font".to_string()], - load_term_conf: false, + ..Default::default() }; let mut alacritty = Alacritty { exe_path: PathBuf::new(), @@ -232,15 +227,10 @@ bindings = [{ key = "Z", mods = "Control", action = "None" }] term_conf.insert("font", Item::Table(font_mapping)); let conf = config::Config { - fork: false, backend: Some(config::Backend::Alacritty), - term_exe_path: None, - term_config_path: None, - exe_path: None, - nvim_exe_path: "nvim".to_owned(), font_size: 14, fonts: vec!["test_font".to_string()], - load_term_conf: false, + ..Default::default() }; let mut alacritty = Alacritty { exe_path: PathBuf::new(), @@ -270,17 +260,8 @@ bindings = [{ key = "Z", mods = "Control", action = "None" }] font_mapping.insert("size", value(42)); term_conf.insert("font", Item::Table(font_mapping)); - let conf = config::Config { - fork: false, - backend: Some(config::Backend::Alacritty), - term_exe_path: None, - term_config_path: None, - exe_path: None, - nvim_exe_path: "nvim".to_owned(), - font_size: 0, - fonts: vec![], - load_term_conf: false, - }; + let mut conf = config::Config::default(); + conf.backend = Some(config::Backend::Alacritty); let mut alacritty = Alacritty { exe_path: PathBuf::new(), cfg_file: None, @@ -309,15 +290,8 @@ bindings = [{ key = "Z", mods = "Control", action = "None" }] term_conf.insert("colors", Item::Table(colors)); let conf = config::Config { - fork: false, backend: Some(config::Backend::Alacritty), - term_exe_path: None, - term_config_path: None, - exe_path: None, - nvim_exe_path: "nvim".to_owned(), - font_size: 0, - fonts: vec![], - load_term_conf: false, + ..Default::default() }; let mut alacritty = Alacritty { exe_path: PathBuf::new(), @@ -352,15 +326,11 @@ size = 16 w.write_all(term_conf.as_bytes()).ok(); w.flush().expect(""); let conf = config::Config { - fork: false, backend: Some(config::Backend::Alacritty), - term_exe_path: None, term_config_path: Some(term_conf_file.path().to_str().unwrap().to_string()), - exe_path: None, - nvim_exe_path: "nvim".to_owned(), font_size: 14, fonts: vec!["test_font".to_string()], - load_term_conf: false, + ..Default::default() }; let mut alacritty = Alacritty { exe_path: PathBuf::new(), diff --git a/src/config.rs b/src/config.rs index 9308c06..36fd1cd 100644 --- a/src/config.rs +++ b/src/config.rs @@ -33,6 +33,8 @@ pub struct Config { pub fonts: Vec, #[serde(default)] pub font_size: u8, + #[serde(default)] + pub omit_term_stderr: bool, } impl Default for Config { @@ -47,6 +49,7 @@ impl Default for Config { fonts: Vec::new(), font_size: 0, load_term_conf: false, + omit_term_stderr: false, } } } @@ -83,9 +86,13 @@ pub fn parse(path: PathBuf) -> Config { config } -pub fn complete(mut config: Config, fork: bool) -> Config { - config.fork = fork; - config +impl Config { + pub fn should_omit_stderr(&self) -> bool { + if log::log_enabled!(log::Level::Debug) { + return false; + } + self.omit_term_stderr + } } #[cfg(test)] diff --git a/src/main.rs b/src/main.rs index c2bac97..eaf96e4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,7 @@ mod error; use config::*; use std::env; -use std::process::Command; +use std::process::{Command, Stdio}; use sysinfo::Pid; const DEFAULT_FONT_SIZE: u8 = 12; @@ -75,7 +75,7 @@ fn parse_args() -> (Config, Vec) { } None => Config::default(), }; - config = config::complete(config, fork); + config.fork = fork; if !config.load_term_conf { // Set our default configs if user doesn't use the terminal's conf. if config.font_size == 0 { @@ -159,6 +159,9 @@ fn main() -> Result<(), Box> { prepare_env(); log::debug!("Start command: {:?}", command); + if config.should_omit_stderr() { + command.stderr(Stdio::null()); + } let mut child = command.spawn()?; backend_functions.post_start(&config, Pid::from_u32(child.id()));