Skip to content

Commit 1f72b1a

Browse files
authored
Add omit_term_stderr config (#79)
To disable unnecessary backend terminal output to the stderr. There are some annoying but harmless logs from kitty like: """ [0.201] The output buffer does not support sRGB color encoding, colors will be incorrect. [0.321] [PARSE ERROR] Escape codes to resize text area are not supported """ which are printed all the time. See: kovidgoyal/kitty#7409 kovidgoyal/kitty#8545 Just give user an option to disable the stderr output. The error log will be disabled if the option is true and the log level is above DEBUG. (Have thought about adding a log filter to specific backend, but it seems to be over-designed.)
1 parent 55d8d2e commit 1f72b1a

File tree

5 files changed

+25
-42
lines changed

5 files changed

+25
-42
lines changed

CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ CHANGES
33

44
Next Release
55

6-
-
6+
- Add `omit_term_stderr` to the config to disable unnecessary backend terminal output to the stderr.
77

88
1.5.0
99

config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,6 @@
3939
# when 'load_term_conf' is true.
4040
#term_config_path: /path/to/config.toml
4141

42+
# Set to true to redirect the backend terminal error output to null device.
43+
# Avoid annoying harmless terminal error logs being printed all the time.
44+
#omit_term_stderr: false

src/backend/alacritty.rs

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,10 @@ mod tests {
193193
#[test]
194194
fn test_create_basic_alacritty_conf() {
195195
let conf = config::Config {
196-
fork: false,
197196
backend: Some(config::Backend::Alacritty),
198-
term_exe_path: None,
199-
term_config_path: None,
200-
exe_path: None,
201-
nvim_exe_path: "nvim".to_owned(),
202197
font_size: 14,
203198
fonts: vec!["test_font".to_string()],
204-
load_term_conf: false,
199+
..Default::default()
205200
};
206201
let mut alacritty = Alacritty {
207202
exe_path: PathBuf::new(),
@@ -232,15 +227,10 @@ bindings = [{ key = "Z", mods = "Control", action = "None" }]
232227
term_conf.insert("font", Item::Table(font_mapping));
233228

234229
let conf = config::Config {
235-
fork: false,
236230
backend: Some(config::Backend::Alacritty),
237-
term_exe_path: None,
238-
term_config_path: None,
239-
exe_path: None,
240-
nvim_exe_path: "nvim".to_owned(),
241231
font_size: 14,
242232
fonts: vec!["test_font".to_string()],
243-
load_term_conf: false,
233+
..Default::default()
244234
};
245235
let mut alacritty = Alacritty {
246236
exe_path: PathBuf::new(),
@@ -270,17 +260,8 @@ bindings = [{ key = "Z", mods = "Control", action = "None" }]
270260
font_mapping.insert("size", value(42));
271261
term_conf.insert("font", Item::Table(font_mapping));
272262

273-
let conf = config::Config {
274-
fork: false,
275-
backend: Some(config::Backend::Alacritty),
276-
term_exe_path: None,
277-
term_config_path: None,
278-
exe_path: None,
279-
nvim_exe_path: "nvim".to_owned(),
280-
font_size: 0,
281-
fonts: vec![],
282-
load_term_conf: false,
283-
};
263+
let mut conf = config::Config::default();
264+
conf.backend = Some(config::Backend::Alacritty);
284265
let mut alacritty = Alacritty {
285266
exe_path: PathBuf::new(),
286267
cfg_file: None,
@@ -309,15 +290,8 @@ bindings = [{ key = "Z", mods = "Control", action = "None" }]
309290
term_conf.insert("colors", Item::Table(colors));
310291

311292
let conf = config::Config {
312-
fork: false,
313293
backend: Some(config::Backend::Alacritty),
314-
term_exe_path: None,
315-
term_config_path: None,
316-
exe_path: None,
317-
nvim_exe_path: "nvim".to_owned(),
318-
font_size: 0,
319-
fonts: vec![],
320-
load_term_conf: false,
294+
..Default::default()
321295
};
322296
let mut alacritty = Alacritty {
323297
exe_path: PathBuf::new(),
@@ -352,15 +326,11 @@ size = 16
352326
w.write_all(term_conf.as_bytes()).ok();
353327
w.flush().expect("");
354328
let conf = config::Config {
355-
fork: false,
356329
backend: Some(config::Backend::Alacritty),
357-
term_exe_path: None,
358330
term_config_path: Some(term_conf_file.path().to_str().unwrap().to_string()),
359-
exe_path: None,
360-
nvim_exe_path: "nvim".to_owned(),
361331
font_size: 14,
362332
fonts: vec!["test_font".to_string()],
363-
load_term_conf: false,
333+
..Default::default()
364334
};
365335
let mut alacritty = Alacritty {
366336
exe_path: PathBuf::new(),

src/config.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ pub struct Config {
3333
pub fonts: Vec<String>,
3434
#[serde(default)]
3535
pub font_size: u8,
36+
#[serde(default)]
37+
pub omit_term_stderr: bool,
3638
}
3739

3840
impl Default for Config {
@@ -47,6 +49,7 @@ impl Default for Config {
4749
fonts: Vec::new(),
4850
font_size: 0,
4951
load_term_conf: false,
52+
omit_term_stderr: false,
5053
}
5154
}
5255
}
@@ -83,9 +86,13 @@ pub fn parse(path: PathBuf) -> Config {
8386
config
8487
}
8588

86-
pub fn complete(mut config: Config, fork: bool) -> Config {
87-
config.fork = fork;
88-
config
89+
impl Config {
90+
pub fn should_omit_stderr(&self) -> bool {
91+
if log::log_enabled!(log::Level::Debug) {
92+
return false;
93+
}
94+
self.omit_term_stderr
95+
}
8996
}
9097

9198
#[cfg(test)]

src/main.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ mod error;
88

99
use config::*;
1010
use std::env;
11-
use std::process::Command;
11+
use std::process::{Command, Stdio};
1212
use sysinfo::Pid;
1313

1414
const DEFAULT_FONT_SIZE: u8 = 12;
@@ -75,7 +75,7 @@ fn parse_args() -> (Config, Vec<String>) {
7575
}
7676
None => Config::default(),
7777
};
78-
config = config::complete(config, fork);
78+
config.fork = fork;
7979
if !config.load_term_conf {
8080
// Set our default configs if user doesn't use the terminal's conf.
8181
if config.font_size == 0 {
@@ -159,6 +159,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
159159

160160
prepare_env();
161161
log::debug!("Start command: {:?}", command);
162+
if config.should_omit_stderr() {
163+
command.stderr(Stdio::null());
164+
}
162165
let mut child = command.spawn()?;
163166

164167
backend_functions.post_start(&config, Pid::from_u32(child.id()));

0 commit comments

Comments
 (0)