Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
42 changes: 6 additions & 36 deletions src/backend/alacritty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
13 changes: 10 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pub struct Config {
pub fonts: Vec<String>,
#[serde(default)]
pub font_size: u8,
#[serde(default)]
pub omit_term_stderr: bool,
}

impl Default for Config {
Expand All @@ -47,6 +49,7 @@ impl Default for Config {
fonts: Vec::new(),
font_size: 0,
load_term_conf: false,
omit_term_stderr: false,
}
}
}
Expand Down Expand Up @@ -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)]
Expand Down
7 changes: 5 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -75,7 +75,7 @@ fn parse_args() -> (Config, Vec<String>) {
}
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 {
Expand Down Expand Up @@ -159,6 +159,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

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()));
Expand Down