diff --git a/alacritty/src/logging.rs b/alacritty/src/logging.rs index f3405e58..113e96ff 100644 --- a/alacritty/src/logging.rs +++ b/alacritty/src/logging.rs @@ -15,15 +15,27 @@ use std::{env, process}; use glutin::event_loop::EventLoopProxy; use log::{self, Level, LevelFilter}; +use alacritty_terminal::config::LOG_TARGET_CONFIG; + use crate::cli::Options; use crate::event::{Event, EventType}; use crate::message_bar::{Message, MessageType}; +/// Logging target for IPC config error messages. +pub const LOG_TARGET_IPC_CONFIG: &str = "alacritty_log_ipc_config"; + /// Name for the environment variable containing the log file's path. const ALACRITTY_LOG_ENV: &str = "ALACRITTY_LOG"; + /// List of targets which will be logged by Alacritty. -const ALLOWED_TARGETS: [&str; 4] = - ["alacritty_terminal", "alacritty_config_derive", "alacritty", "crossfont"]; +const ALLOWED_TARGETS: &[&str] = &[ + LOG_TARGET_IPC_CONFIG, + LOG_TARGET_CONFIG, + "alacritty_config_derive", + "alacritty_terminal", + "alacritty", + "crossfont", +]; pub fn initialize( options: &Options, diff --git a/alacritty/src/window_context.rs b/alacritty/src/window_context.rs index 9a2a8730..45adf8b8 100644 --- a/alacritty/src/window_context.rs +++ b/alacritty/src/window_context.rs @@ -38,6 +38,7 @@ use crate::config::UiConfig; use crate::display::Display; use crate::event::{ActionContext, Event, EventProxy, EventType, Mouse, SearchState}; use crate::input; +use crate::logging::LOG_TARGET_IPC_CONFIG; use crate::message_bar::MessageBuffer; use crate::scheduler::Scheduler; @@ -184,10 +185,20 @@ impl WindowContext { if !self.ipc_config.is_empty() { let mut config = (*self.config).clone(); - // Apply each option. - for (key, value) in &self.ipc_config { - if let Err(err) = config.replace(key, value.clone()) { - error!("Unable to override option '{}': {}", key, err); + // Apply each option, removing broken ones. + let mut i = 0; + while i < self.ipc_config.len() { + let (key, value) = &self.ipc_config[i]; + + match config.replace(key, value.clone()) { + Err(err) => { + error!( + target: LOG_TARGET_IPC_CONFIG, + "Unable to override option '{}': {}", key, err + ); + self.ipc_config.swap_remove(i); + }, + Ok(_) => i += 1, } } @@ -255,15 +266,21 @@ impl WindowContext { /// Update the IPC config overrides. #[cfg(unix)] pub fn update_ipc_config(&mut self, config: Rc, ipc_config: IpcConfig) { - self.ipc_config.clear(); + // Clear previous IPC errors. + self.message_buffer.remove_target(LOG_TARGET_IPC_CONFIG); - if !ipc_config.reset { + if ipc_config.reset { + self.ipc_config.clear(); + } else { for option in &ipc_config.options { // Separate config key/value. let (key, value) = match option.split_once('=') { Some(split) => split, None => { - error!("'{}': IPC config option missing value", option); + error!( + target: LOG_TARGET_IPC_CONFIG, + "'{}': IPC config option missing value", option + ); continue; }, }; @@ -271,7 +288,10 @@ impl WindowContext { // Try and parse value as yaml. match serde_yaml::from_str(value) { Ok(value) => self.ipc_config.push((key.to_owned(), value)), - Err(err) => error!("'{}': Invalid IPC config value: {:?}", option, err), + Err(err) => error!( + target: LOG_TARGET_IPC_CONFIG, + "'{}': Invalid IPC config value: {:?}", option, err + ), } } } diff --git a/alacritty_terminal/src/config/mod.rs b/alacritty_terminal/src/config/mod.rs index 53a0eb77..f63f6ebb 100644 --- a/alacritty_terminal/src/config/mod.rs +++ b/alacritty_terminal/src/config/mod.rs @@ -12,6 +12,7 @@ use crate::ansi::{CursorShape, CursorStyle}; pub use crate::config::scrolling::{Scrolling, MAX_SCROLLBACK_LINES}; +/// Logging target for config error messages. pub const LOG_TARGET_CONFIG: &str = "alacritty_config_derive"; const MIN_BLINK_INTERVAL: u64 = 10;